web-logs: Initial version of role

This commit is contained in:
Timo Makinen 2021-09-18 18:46:12 +00:00
parent 8a2471f932
commit 8f54421d17
4 changed files with 108 additions and 0 deletions

View file

@ -0,0 +1,28 @@
#!/bin/sh
set -u
umask 022
TARGET="/var/cache/sync-http-logs"
CONFIG="/etc/rclone/rclone.conf"
LOGDIR="/var/log/rclone"
timestamp="$(date +%Y%m%d%H%M%S)"
if [ ! -d "$TARGET" ]; then
echo "ERR: Destination directory '${TARGET}' does not exist" 1>&2
exit 1
fi
for host in $(rclone --config "$CONFIG" listremotes | tr -d ":") ; do
fqdn="$(rclone --config "$CONFIG" config show "$host" | \
awk '{ if ($1 == "host") print $3 }')"
if [ ! -d "${TARGET}/${fqdn}" ]; then
mkdir "${TARGET}/${fqdn}"
fi
log="${LOGDIR}/${fqdn}.${timestamp}.log"
if ! rclone --config "$CONFIG" --log-file "$log" --log-level INFO \
sync "${host}:/" "${TARGET}/${fqdn}/"; then
cat "$log"
fi
done