summaryrefslogtreecommitdiff
path: root/roles/storage/zfs/syncoid
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2022-01-11 00:19:35 +0100
committerChristian Pointner <equinox@spreadspace.org>2022-01-11 00:19:35 +0100
commit9dd9c2ec2e0e0f34db95d9650ea253c147f8c7d3 (patch)
tree99c7953dea546113ba85bcb6da56d7d6b688a6eb /roles/storage/zfs/syncoid
parentzfs/syncoid: add error handling to pull (diff)
zfs/syncoid: add duration of job to prometheus metrics
Diffstat (limited to 'roles/storage/zfs/syncoid')
-rw-r--r--roles/storage/zfs/syncoid/templates/syncoid_finalize.j215
-rw-r--r--roles/storage/zfs/syncoid/templates/syncoid_pull.j26
2 files changed, 19 insertions, 2 deletions
diff --git a/roles/storage/zfs/syncoid/templates/syncoid_finalize.j2 b/roles/storage/zfs/syncoid/templates/syncoid_finalize.j2
index 5ddc691b..3869e975 100644
--- a/roles/storage/zfs/syncoid/templates/syncoid_finalize.j2
+++ b/roles/storage/zfs/syncoid/templates/syncoid_finalize.j2
@@ -3,7 +3,7 @@
echo "running sanoid --prune to cleanup old snapshots"
sleep 5
-echo systemctl start --wait sanoid-prune.service
+systemctl start --wait sanoid-prune.service
echo "wait 30s (autosuspend cooldown period)"
sleep 30
@@ -27,8 +27,19 @@ for line in $(cat "$RUNTIME_DIRECTORY/exit_codes"); do
fi
done
+now=$(date +"%s")
+starttime=$(cat "$RUNTIME_DIRECTORY/start")
+duration=0
+if [[ $starttime =~ [^[:digit:]] ]]; then
+ ret=-1
+ echo "invalid starttime from pull script: $starttime"
+else
+ duration=$(( now - starttime ))
+fi
+
cat <<EOF >> "$RUNTIME_DIRECTORY/metrics"
-syncoid_pull_last_run{backup_server="{{ inventory_hostname }}"} $(date +"%s")
+syncoid_pull_run{backup_server="{{ inventory_hostname }}"} $now
+syncoid_pull_duration_seconds{backup_server="{{ inventory_hostname }}"} $duration
EOF
diff --git a/roles/storage/zfs/syncoid/templates/syncoid_pull.j2 b/roles/storage/zfs/syncoid/templates/syncoid_pull.j2
index ab6c3116..d54683c5 100644
--- a/roles/storage/zfs/syncoid/templates/syncoid_pull.j2
+++ b/roles/storage/zfs/syncoid/templates/syncoid_pull.j2
@@ -16,6 +16,12 @@ if [ -n "$1" ]; then
shift
fi
+if [ -n "$RUNTIME_DIRECTORY" ]; then
+ if [ ! -e "$RUNTIME_DIRECTORY/start" ]; then
+ date +"%s" > "$RUNTIME_DIRECTORY/start"
+ fi
+fi
+
/usr/sbin/syncoid --sshoption "UserKnownHostsFile=/var/lib/syncoid/ssh.knownhosts" --sshoption "HashKnownHosts=no" --sshkey "/var/lib/syncoid/id_ssh_ed25519" --no-sync-snap --compress zstd-fast "$@" "$src_host:$src_path" "$dest_path"
ret=$?