diff --git a/NEWS b/NEWS index dea3f300..e44c2dd1 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,7 @@ * #1086: Fix for the "spot" check breaking when the "--progress" flag is used. * #1091: Fix for the "config generate" action generating invalid configuration when upgrading deprecated command hooks. + * #1093: Fix for the LVM hook erroring when the "--dry-run" flag is used. * Add support for Borg 2's "s3:" and "b2:" repository URLs, so you can backup to S3 or B2 cloud storage services even without using Rclone. diff --git a/borgmatic/hooks/data_source/lvm.py b/borgmatic/hooks/data_source/lvm.py index a2ed1c3a..65a2b6bf 100644 --- a/borgmatic/hooks/data_source/lvm.py +++ b/borgmatic/hooks/data_source/lvm.py @@ -230,12 +230,13 @@ def dump_data_sources( ) # Get the device path for the snapshot we just created. - try: - snapshot = get_snapshots( - hook_config.get('lvs_command', 'lvs'), snapshot_name=snapshot_name - )[0] - except IndexError: - raise ValueError(f'Cannot find LVM snapshot {snapshot_name}') + if not dry_run: + try: + snapshot = get_snapshots( + hook_config.get('lvs_command', 'lvs'), snapshot_name=snapshot_name + )[0] + except IndexError: + raise ValueError(f'Cannot find LVM snapshot {snapshot_name}') # Mount the snapshot into a particular named temporary directory so that the snapshot ends # up in the Borg archive at the "original" logical volume mount point path. diff --git a/tests/unit/hooks/data_source/test_lvm.py b/tests/unit/hooks/data_source/test_lvm.py index 837b4a3c..430dfa68 100644 --- a/tests/unit/hooks/data_source/test_lvm.py +++ b/tests/unit/hooks/data_source/test_lvm.py @@ -556,16 +556,7 @@ def test_dump_data_sources_with_dry_run_skips_snapshots_and_does_not_touch_patte ) flexmock(module.os).should_receive('getpid').and_return(1234) flexmock(module).should_receive('snapshot_logical_volume').never() - flexmock(module).should_receive('get_snapshots').with_args( - 'lvs', snapshot_name='lvolume1_borgmatic-1234' - ).and_return( - (module.Snapshot(name='lvolume1_borgmatic-1234', device_path='/dev/lvolume1_snap'),) - ) - flexmock(module).should_receive('get_snapshots').with_args( - 'lvs', snapshot_name='lvolume2_borgmatic-1234' - ).and_return( - (module.Snapshot(name='lvolume2_borgmatic-1234', device_path='/dev/lvolume2_snap'),) - ) + flexmock(module).should_receive('get_snapshots').never() flexmock(module).should_receive('mount_snapshot').never() assert (