zfs snapshot hook: unmounting fails with nested dataset #950
Labels
No labels
blocked
breaking
bug
data loss
design finalized
good first issue
new feature area
question / support
security
waiting for response
No milestone
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
borgmatic-collective/borgmatic#950
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What I'm trying to do and why
I am trying to setup the zfs hook to automatically snapshot a dataset before backing it up to avoid any headaches with files being changed during the backup (awesome feature btw :D) The dataset I am trying to backup is contained within another dataset.
Steps to reproduce
This is the output of
zfs listwith the 2 relevant datasets. Withinstorage, there is another dataset,storage/nextcloud(the one I am attempting to back up)relevant extracts of my borgmatic configuration:
Actual behavior
The creation of the snapshot works as expected:
The problem later comes when unmounting once the backup is complete:
borgmatic looks for filesystems and their mountpoints and tries to unmount
mnt/storage, when it should instead unmountmnt/storage/nextcloudThis leaves the snapshot afterwards, which needs manual unmounting and removal:
Expected behavior
borgmatic should either:
returnafter theumountcommand failure, allowing the loop to continue and succeed on the next iteration in the loopOther notes / implementation ideas
relevant section in the borgmatic source:
for snapshots_directory in glob.glob(snapshots_glob):if not os.path.isdir(snapshots_directory):continue# This might fail if the directory is already mounted, but we swallow errors here since# we'll try again below. The point of doing it here is that we don't want to try to unmount# a non-mounted directory (which *will* fail), and probing for whether a directory is# mounted is tough to do in a cross-platform way.if not dry_run:shutil.rmtree(snapshots_directory, ignore_errors=True)for _, mount_point in datasets:snapshot_mount_path = os.path.join(snapshots_directory, mount_point.lstrip(os.path.sep))if not os.path.isdir(snapshot_mount_path):continuelogger.debug(f'{log_prefix}: Unmounting ZFS snapshot at {snapshot_mount_path}{dry_run_label}')if not dry_run:try:unmount_snapshot(umount_command, snapshot_mount_path)except FileNotFoundError:logger.debug(f'{log_prefix}: Could not find "{umount_command}" command')returnexcept subprocess.CalledProcessError as error:logger.debug(f'{log_prefix}: {error}')returnborgmatic version
1.9.3
borgmatic installation method
pipx
Borg version
borg 1.4.0
Python version
Python 3.11.2
Database version (if applicable)
No response
Operating system and version
Debian GNU/Linux 12 (bookworm)
Thanks so much for trying out the ZFS hook and reporting this issue. I believe the problem has been already fixed in
maina branch, which will become the next release. But I'll confirm that it's fixed before closing this ticket.In terms of the specific solution, it's basically doing your option 2 (more or less).
Okay, I've confirmed this is fixed in the branch after one tweak. Here's the setup for my repro:
borgmatic config:
And then running borgmatic:
Thanks again for the issue report!
Thank you! ❤️ tried on
51a7f50e3aand can confirm it works for me as well :)Awesome, thanks for testing it out!
Released in borgmatic 1.9.4!