bundlewrap/bundles/zfs/files/backup-pre-hook
Franzi 0ba3df7385
Some checks failed
kunsi/bundlewrap/pipeline/head There was a failure building this commit
bundles/zfs: unmount backup-snapshots recursively
2022-03-01 06:32:23 +01:00

37 lines
947 B
Bash

#!/bin/bash
errors=0
run-parts --exit-on-error -- /etc/zfs-snapshot-backup-pre.d || errors=1
% for dataset in sorted(node.metadata.get('zfs/filesystems_with_backup_snapshots')):
mountpoint="/mnt/backup-snapshot${node.metadata['zfs']['datasets'][dataset]['mountpoint']}"
if findmnt "$mountpoint" >/dev/null
then
umount -R "$mountpoint" || errors=1
fi
if zfs get type "${dataset}@snapshot-backup" >/dev/null 2>&1
then
zfs destroy "${dataset}@snapshot-backup" || errors=1
fi
zfs snapshot "${dataset}@snapshot-backup" || errors=1
mkdir -p "$mountpoint" || errors=1
mount -t zfs "${dataset}@snapshot-backup" "$mountpoint" || errors=1
% endfor
run-parts --exit-on-error -- /etc/zfs-snapshot-backup-post.d || errors=1
if (( errors ))
then
# We can't use 'set -e' in here, because this could result in services
# not getting started, if they need to get stopped before creating a
# consistent backup snapshot.
exit 1
fi