rclone: Move more generic stuff away from web-logs role

This commit is contained in:
Timo Makinen 2021-09-19 19:16:24 +00:00
parent 06f173cba2
commit 06f4645127
3 changed files with 18 additions and 22 deletions

View file

@ -1,34 +0,0 @@
#!/bin/sh
set -u
umask 027
TARGET="/var/cache/sync-http-logs"
CONFIG="/etc/rclone/rclone.conf"
LOGDIR="/var/log/rclone"
RCLONE="/usr/local/bin/rclone"
timestamp="$(date +%Y%m%d%H%M%S)"
if [ "$(whoami)" != "logsync" ]; then
echo "ERR: Script needs to be run as logsync user" 1>&2
exit 1
fi
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

View file

@ -19,6 +19,7 @@
vars:
remote_user: logsync
hostgroup: webservers
destination: /var/cache/sync-http-logs
- name: create data directories
file:
@ -30,22 +31,6 @@
with_items:
- /var/cache/sync-http-logs
- name: create log directory
file:
path: /var/log/rclone
state: directory
mode: 0750
owner: logsync
group: "{{ ansible_wheel }}"
- name: copy logsync script
copy:
dest: /usr/local/bin/sync-http-logs
src: sync-http-logs.sh
mode: 0755
owner: root
group: "{{ ansible_wheel }}"
- name: add log sync cron job
cron:
name: sync-http-logs