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

@ -19,3 +19,19 @@
mode: 0644
owner: root
group: "{{ ansible_wheel }}"
- name: create log directory
file:
path: /var/log/rclone
state: directory
mode: 0750
owner: "{{ local_user | default('root') }}"
group: "{{ local_user | default(ansible_wheel) }}"
- name: copy logsync script
template:
dest: /usr/local/bin/rclone-sync
src: rclone-sync.sh.j2
mode: 0755
owner: root
group: "{{ ansible_wheel }}"

View file

@ -0,0 +1,29 @@
#!/bin/sh
set -u
umask 027
TARGET="{{ destination }}"
CONFIG="/etc/rclone/rclone.conf"
LOGDIR="/var/log/rclone"
RCLONE="/usr/local/bin/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