web-logs: Initial version of role
This commit is contained in:
parent
8a2471f932
commit
8f54421d17
4 changed files with 108 additions and 0 deletions
28
roles/web-logs/files/sync-http-logs.sh
Executable file
28
roles/web-logs/files/sync-http-logs.sh
Executable 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
|
Loading…
Add table
Add a link
Reference in a new issue