bundlewrap/bundles/zfs/files/backup-pre-hook

29 lines
651 B
Text
Raw Normal View History

#!/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')):
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
then
zfs destroy "${dataset}@snapshot-backup"
fi
zfs snapshot "${dataset}@snapshot-backup"
mkdir -p "$mountpoint"
mount -t zfs "${dataset}@snapshot-backup" "$mountpoint"
% endfor
run-parts --exit-on-error -- /etc/zfs-snapshot-backup-post.d