diff --git a/roles/mgrote_zfs_sanoid/tasks/destination.yml b/roles/mgrote_zfs_sanoid/tasks/destination.yml index 9cb40daf..1e0fcd19 100644 --- a/roles/mgrote_zfs_sanoid/tasks/destination.yml +++ b/roles/mgrote_zfs_sanoid/tasks/destination.yml @@ -38,6 +38,17 @@ when: - sanoid_syncoid_destination_host +- name: template syncoid.sh + become: true + ansible.builtin.template: + src: "syncoid.sh.j2" + dest: /usr/bin/syncoid.sh + owner: root + group: root + mode: "0755" + when: + - sanoid_syncoid_destination_host + - name: template syncoid_mail.service become: true ansible.builtin.template: diff --git a/roles/mgrote_zfs_sanoid/templates/syncoid.service.j2 b/roles/mgrote_zfs_sanoid/templates/syncoid.service.j2 index ef25ec94..af61c7f5 100644 --- a/roles/mgrote_zfs_sanoid/templates/syncoid.service.j2 +++ b/roles/mgrote_zfs_sanoid/templates/syncoid.service.j2 @@ -6,14 +6,5 @@ OnFailure=syncoid_mail.service OnSuccess=syncoid_mail.service [Service] -Type=oneshot -# check if dest-dataset is mounted (sed: entferne 1. Zeile; awk: zeige nur yes/no; grep: RC1 when != yes) -{% for item in sanoid_syncoid_datasets_sync %} -# check if target dataset is mounted -ExecStart=/bin/sh -c '/usr/sbin/zfs get mounted -H {{ item.destination_mount_check }} | awk "{print $3}" | grep yes > /dev/null' -# check if source host is reachable -ExecStart=/bin/sh -c 'ping -c1 -W1 {{ item.source_host }} > /dev/null || {{ item.source_host }} not reachable!' -# syncoid -ExecStart=/bin/sh -c 'echo "sending {{ item.source_dataset }}..."' -ExecStart=/bin/sh -c 'export HOME=/root ; /usr/bin/syncoid --compress=zstd-fast --quiet --sshoption=StrictHostKeyChecking=no --delete-target-snapshots --use-hold --preserve-recordsize --sshkey "/etc/sanoid/.ssh/id_sanoid" --source-bwlimit {{ sanoid_syncoid_bwlimit }} {{ sanoid_user }}@{{ item.source_host }}:{{ item.source_dataset }} {{ item.destination_dataset }}' -{% endfor %} +Type=simple +ExecStart=/usr/bin/syncoid.sh diff --git a/roles/mgrote_zfs_sanoid/templates/syncoid.sh.j2 b/roles/mgrote_zfs_sanoid/templates/syncoid.sh.j2 new file mode 100644 index 00000000..81acfe38 --- /dev/null +++ b/roles/mgrote_zfs_sanoid/templates/syncoid.sh.j2 @@ -0,0 +1,12 @@ +#!/bin/bash +{{ file_header | default () }} + +# check if dest-dataset is mounted (sed: entferne 1. Zeile; awk: zeige nur yes/no; grep: RC1 when != yes) +{% for item in sanoid_syncoid_datasets_sync %} +# check if target dataset is mounted +/usr/sbin/zfs get mounted -H {{ item.destination_mount_check }} | awk "{print $3}" | grep yes > /dev/null +# check if source host is reachable +ping -c1 -W1 {{ item.source_host }} > /dev/null || {{ item.source_host }} not reachable! +# syncoid +export HOME=/root ; /usr/bin/syncoid --compress=zstd-fast --sshoption=StrictHostKeyChecking=no --delete-target-snapshots --use-hold --preserve-recordsize --sshkey "/etc/sanoid/.ssh/id_sanoid" --source-bwlimit {{ sanoid_syncoid_bwlimit }} {{ sanoid_user }}@{{ item.source_host }}:{{ item.source_dataset }} {{ item.destination_dataset }} +{% endfor %}