bundlewrap/bundles/zfs/files/backup-pre-hook
Franziska Kunsmann 976aa251d1
All checks were successful
bundlewrap/pipeline/head This commit looks good
bundles/zfs: actually unmount snapshots before trying to destroy them
2021-05-16 07:43:31 +02:00

28 lines
651 B
Bash

#!/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