From 9afdaca98512ceed02bea05a7b1987c9246f53d9 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Tue, 3 Dec 2024 19:19:22 -0800 Subject: [PATCH] Before unmounting, remove the snapshot mount path instead of the parent snapshot directory (#80). --- borgmatic/hooks/data_source/lvm.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/borgmatic/hooks/data_source/lvm.py b/borgmatic/hooks/data_source/lvm.py index 0319f3a2..ce9aa5a0 100644 --- a/borgmatic/hooks/data_source/lvm.py +++ b/borgmatic/hooks/data_source/lvm.py @@ -169,7 +169,7 @@ def dump_data_sources( hook_config.get('snapshot_size', DEFAULT_SNAPSHOT_SIZE), ) - # Get the device path for the device path for the snapshot we just created. + # Get the device path for the snapshot we just created. try: snapshot = get_snapshots( hook_config.get('lvs_command', 'lvs'), snapshot_name=snapshot_name @@ -316,12 +316,6 @@ def remove_data_source_dumps(hook_config, config, log_prefix, borgmatic_runtime_ 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). - if not dry_run: - shutil.rmtree(snapshots_directory, ignore_errors=True) - for logical_volume in logical_volumes: snapshot_mount_path = os.path.join( snapshots_directory, logical_volume.mount_point.lstrip(os.path.sep) @@ -329,6 +323,12 @@ def remove_data_source_dumps(hook_config, config, log_prefix, borgmatic_runtime_ if not os.path.isdir(snapshot_mount_path): continue + # This might fail if the directory is already mounted, but we swallow errors here since + # we'll do another recursive delete below. The point of doing it here is that we don't + # want to try to unmount a non-mounted directory (which *will* fail). + if not dry_run: + shutil.rmtree(snapshot_mount_path, ignore_errors=True) + logger.debug( f'{log_prefix}: Unmounting LVM snapshot at {snapshot_mount_path}{dry_run_label}' )