From 976aa251d12774a9b7012eb9727cdf7829a3c871 Mon Sep 17 00:00:00 2001 From: Franziska Kunsmann Date: Sun, 16 May 2021 07:43:31 +0200 Subject: [PATCH] bundles/zfs: actually unmount snapshots before trying to destroy them --- bundles/zfs/files/backup-pre-hook | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/bundles/zfs/files/backup-pre-hook b/bundles/zfs/files/backup-pre-hook index a5041b0..8ee996d 100644 --- a/bundles/zfs/files/backup-pre-hook +++ b/bundles/zfs/files/backup-pre-hook @@ -6,15 +6,22 @@ run-parts --exit-on-error -- /etc/zfs-snapshot-backup-pre.d % for dataset in sorted(node.metadata.get('zfs/filesystems_with_backup_snapshots')): -if zfs get type ${dataset}@snapshot-backup >/dev/null 2>&1 +mountpoint="/mnt/backup-snapshot${node.metadata['zfs']['datasets'][dataset]['mountpoint']}" + +if findmnt "$mountpoint" >/dev/null then - zfs destroy -f ${dataset}@snapshot-backup + umount "$mountpoint" fi -zfs snapshot ${dataset}@snapshot-backup +if zfs get type "${dataset}@snapshot-backup" >/dev/null 2>&1 +then + zfs destroy "${dataset}@snapshot-backup" +fi -mkdir -p /mnt/backup-snapshot${node.metadata['zfs']['datasets'][dataset]['mountpoint']} -mount -t zfs ${dataset}@snapshot-backup /mnt/backup-snapshot${node.metadata['zfs']['datasets'][dataset]['mountpoint']} +zfs snapshot "${dataset}@snapshot-backup" + +mkdir -p "$mountpoint" +mount -t zfs "${dataset}@snapshot-backup" "$mountpoint" % endfor