homeserver/roles/mgrote_rsync/templates/rsync_mirror.sh.j2
Michael Grote 7a2ccbabb6
All checks were successful
ansible-lint / gitleaks (push) Successful in 2s
ansible-lint / Ansible Lint (push) Successful in 23s
remove syncoid, switch to rsync (#221)
no more zfs send
mirroring with rsync
snaps an both sides

Reviewed-on: #221
Co-authored-by: Michael Grote <michael.grote@posteo.de>
Co-committed-by: Michael Grote <michael.grote@posteo.de>
2024-10-31 12:01:46 +01:00

24 lines
1.2 KiB
Django/Jinja

#!/bin/bash
{{ file_header | default () }}
{% for item in rsync_mirror_dirs %}
{# Header #}
echo "-----------------------"
echo "Source: {{ item.src }}"
echo "Destination: {{ item.dest.split(':') | last }}"
{# Mount check source #}
{# der führende / muss beim Dataset entfernt werden, sonst melden das Kommando immer "mounted" zurück #}
if [[ "$(/usr/sbin/zfs get mounted -H {{ item.src | regex_replace('^/', '') }} | cut -f3)" = "yes" ]] ; then
{# Mount check destination #}
if [[ "$(ssh -i /etc/rsync_mirror/.ssh/id_rsync_mirror -o StrictHostKeyChecking=no {{ item.dest.split(':') | first }} /usr/sbin/zfs get mounted -H {{ item.dest.split(':') | last | regex_replace('^/', '') }} | cut -f3)" = "yes" ]] ; then
rsync -e "ssh -i /etc/rsync_mirror/.ssh/id_rsync_mirror -o StrictHostKeyChecking=no" --bwlimit={{ rsync_mirror_bw_limit }} --archive --verbose --inplace --itemize-changes --omit-dir-times --human-readable --stats --compress --fuzzy --force --partial --delete-after --recursive {{ item.src }}/ {{ item.dest }}/
{# "/" am Ende von Src+Dest ist Wichtig und notwendig, sonst wird in Unterordner kopiert #}
else
echo "Destination-Dataset not mounted!"
exit 1
fi
else
echo "Source-Dataset not mounted!"
exit 1
fi
{% endfor %}