rclone: Don't use template for backup script
This commit is contained in:
parent
cd8e979ded
commit
f3293d4b05
3 changed files with 7 additions and 4 deletions
29
roles/rclone/files/rclone-sync.sh
Executable file
29
roles/rclone/files/rclone-sync.sh
Executable file
|
@ -0,0 +1,29 @@
|
|||
#!/bin/sh
|
||||
|
||||
set -eu
|
||||
umask 027
|
||||
|
||||
TARGET="/srv/backup"
|
||||
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
|
Loading…
Add table
Add a link
Reference in a new issue