#!/bin/bash set -euo pipefail now=$(date +"%Y%m%d%H%M") if ! mountpoint -q {{ hetzner_raid_mount }} then echo "[${now}] {{ hetzner_raid_mount }} not mounted, refusing to sync" exit 1 fi sync_path() { local src=$1 local dest=$2 if [ -z "$(ls -A ${src} 2>/dev/null)" ] then echo "[${now}] ${src} empty, refusing to sync" exit 1 fi echo "[${now}] syncing ${src} to ${dest}" sudo -u {{ user }} rsync -a --delete --partial \ -e "ssh -p {{ hetzner_port }} -i {{ user_home }}/.ssh/id_ed25519 -o UserKnownHostsFile={{ user_home }}/.ssh/known_hosts -o StrictHostKeyChecking=yes" \ ${src}/ \ {{ hetzner_user }}@{{ hetzner_host }}:${dest}/ } echo "[${now}] offsite sync start" {% for path in hetzner_paths %} sync_path {{ path.src }} {{ path.dest }} {% endfor %} echo "[${now}] offsite sync done"