diff options
author | Christian Pointner <equinox@spreadspace.org> | 2022-01-11 00:04:35 +0100 |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2022-01-11 00:04:35 +0100 |
commit | 5f3230aad459d06cfd257616564bddc4cd9ad7cc (patch) | |
tree | 62987e7d565077a7a8aee4f7460bb1b4789d9158 /roles/storage/zfs/syncoid/templates/syncoid_finalize.j2 | |
parent | disable syncoid for some testvms (diff) |
zfs/syncoid: add error handling to pull
Diffstat (limited to 'roles/storage/zfs/syncoid/templates/syncoid_finalize.j2')
-rw-r--r-- | roles/storage/zfs/syncoid/templates/syncoid_finalize.j2 | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/roles/storage/zfs/syncoid/templates/syncoid_finalize.j2 b/roles/storage/zfs/syncoid/templates/syncoid_finalize.j2 new file mode 100644 index 00000000..5ddc691b --- /dev/null +++ b/roles/storage/zfs/syncoid/templates/syncoid_finalize.j2 @@ -0,0 +1,53 @@ +#!/bin/bash +{% if zfs_syncoid_autosuspend %} + +echo "running sanoid --prune to cleanup old snapshots" +sleep 5 +echo systemctl start --wait sanoid-prune.service + +echo "wait 30s (autosuspend cooldown period)" +sleep 30 +echo "done." +{% endif %} + +if [ -z "$RUNTIME_DIRECTORY" ]; then + exit 0 +fi + +ret=0 +for line in $(cat "$RUNTIME_DIRECTORY/exit_codes"); do + if [[ $line =~ [^[:digit:]] ]]; then + ret=-1 + echo "invalid exit_code from pull script: $line" + else + ret=$line + fi + if [ $ret -ne 0 ]; then + break + fi +done + +cat <<EOF >> "$RUNTIME_DIRECTORY/metrics" +syncoid_pull_last_run{backup_server="{{ inventory_hostname }}"} $(date +"%s") +EOF + + +if [ -z "$1" ] || [ -z "$2" ] || [ "$1" == "--" ] || [ "$2" == "--" ]; then + echo "$0 <host> <textfile-collector-path> [ -- <additional ssh arguments .. > ]" + exit -2 +fi +report_to=$1 +textfile_collector_path=$2 +shift 2 +if [ -n "$1" ]; then + if [ "$1" != "--" ]; then + echo "additional arguments must be separated using '--'" + exit -2 + fi + shift +fi + +echo "transfering prometheus metrics to: $report_to:$textfile_collector_path" +cat "$RUNTIME_DIRECTORY/metrics" | ssh -o "UserKnownHostsFile=/var/lib/syncoid/ssh.knownhosts" -o "HashKnownHosts=no" -i "/var/lib/syncoid/id_ssh_ed25519" "$@" "$report_to" "cat > '$textfile_collector_path/syncoid-pull-{{ inventory_hostname }}.prom'" + +exit $ret |