2021-05-15 18:32:23 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
run-parts --exit-on-error -- /etc/zfs-snapshot-backup-pre.d
|
|
|
|
|
|
|
|
|
|
|
|
% for dataset in sorted(node.metadata.get('zfs/filesystems_with_backup_snapshots')):
|
2021-05-16 05:43:31 +00:00
|
|
|
mountpoint="/mnt/backup-snapshot${node.metadata['zfs']['datasets'][dataset]['mountpoint']}"
|
|
|
|
|
|
|
|
if findmnt "$mountpoint" >/dev/null
|
|
|
|
then
|
|
|
|
umount "$mountpoint"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if zfs get type "${dataset}@snapshot-backup" >/dev/null 2>&1
|
2021-05-15 18:32:23 +00:00
|
|
|
then
|
2021-05-16 05:43:31 +00:00
|
|
|
zfs destroy "${dataset}@snapshot-backup"
|
2021-05-15 18:32:23 +00:00
|
|
|
fi
|
|
|
|
|
2021-05-16 05:43:31 +00:00
|
|
|
zfs snapshot "${dataset}@snapshot-backup"
|
2021-05-15 18:32:23 +00:00
|
|
|
|
2021-05-16 05:43:31 +00:00
|
|
|
mkdir -p "$mountpoint"
|
|
|
|
mount -t zfs "${dataset}@snapshot-backup" "$mountpoint"
|
2021-05-15 18:32:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
% endfor
|
|
|
|
run-parts --exit-on-error -- /etc/zfs-snapshot-backup-post.d
|