From 7dc7b77f6c3bd18aceffe166c5759ed33718a96b Mon Sep 17 00:00:00 2001 From: Jackson Date: Thu, 20 Nov 2025 16:29:20 +0100 Subject: [PATCH 1/5] static btrfs snapshot paths i don't know the implications of this change, except for maybe concurrent borgmatic processes --- borgmatic/hooks/data_source/btrfs.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/borgmatic/hooks/data_source/btrfs.py b/borgmatic/hooks/data_source/btrfs.py index 0fd758ae..d98fbdd4 100644 --- a/borgmatic/hooks/data_source/btrfs.py +++ b/borgmatic/hooks/data_source/btrfs.py @@ -180,7 +180,7 @@ def get_subvolumes(btrfs_command, patterns): return tuple(sorted(subvolumes, key=lambda subvolume: subvolume.path)) -BORGMATIC_SNAPSHOT_PREFIX = '.borgmatic-snapshot-' +BORGMATIC_SNAPSHOT_PREFIX = '.borgmatic-snapshot' def make_snapshot_path(subvolume_path): @@ -189,7 +189,7 @@ def make_snapshot_path(subvolume_path): ''' return os.path.join( subvolume_path, - f'{BORGMATIC_SNAPSHOT_PREFIX}{os.getpid()}', + f'{BORGMATIC_SNAPSHOT_PREFIX}', # Included so that the snapshot ends up in the Borg archive at the "original" subvolume path. ) + subvolume_path.rstrip(os.path.sep) @@ -244,7 +244,7 @@ def make_borg_snapshot_pattern(subvolume_path, pattern): rewritten_path = initial_caret + os.path.join( subvolume_path, - f'{BORGMATIC_SNAPSHOT_PREFIX}{os.getpid()}', + f'{BORGMATIC_SNAPSHOT_PREFIX}', # Use the Borg 1.4+ "slashdot" hack to prevent the snapshot path prefix from getting # included in the archive—but only if there's not already a slashdot hack present in the # pattern. From f95fbaa6aadb32fc311a475212be04c8642b22bc Mon Sep 17 00:00:00 2001 From: Jackson Date: Fri, 21 Nov 2025 09:22:14 +0100 Subject: [PATCH 2/5] fix at least some tests (with changed snapshot path) this really is just a blanket find and replace though --- .../hooks/data_source/test_btrfs.py | 18 +- tests/unit/hooks/data_source/test_btrfs.py | 210 +++++++++--------- 2 files changed, 114 insertions(+), 114 deletions(-) diff --git a/tests/integration/hooks/data_source/test_btrfs.py b/tests/integration/hooks/data_source/test_btrfs.py index 1c6bc4e5..f12928b8 100644 --- a/tests/integration/hooks/data_source/test_btrfs.py +++ b/tests/integration/hooks/data_source/test_btrfs.py @@ -28,12 +28,12 @@ def test_dump_data_sources_snapshots_each_subvolume_and_updates_patterns(): flexmock(module).should_receive('snapshot_subvolume').with_args( 'btrfs', '/mnt/subvol1', - '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1', + '/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1', ).once() flexmock(module).should_receive('snapshot_subvolume').with_args( 'btrfs', '/mnt/subvol2', - '/mnt/subvol2/.borgmatic-snapshot-1234/mnt/subvol2', + '/mnt/subvol2/.borgmatic-snapshot/mnt/subvol2', ).once() assert ( @@ -50,21 +50,21 @@ def test_dump_data_sources_snapshots_each_subvolume_and_updates_patterns(): assert patterns == [ Pattern( - '/mnt/subvol2/.borgmatic-snapshot-1234/mnt/subvol2/.borgmatic-snapshot-1234', + '/mnt/subvol2/.borgmatic-snapshot/mnt/subvol2/.borgmatic-snapshot', Pattern_type.NO_RECURSE, Pattern_style.FNMATCH, ), Pattern( - '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1/.borgmatic-snapshot-1234', + '/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1/.borgmatic-snapshot', Pattern_type.NO_RECURSE, Pattern_style.FNMATCH, ), Pattern('/foo'), - Pattern('/mnt/subvol1/.borgmatic-snapshot-1234/./mnt/subvol1'), - Pattern('/mnt/subvol1/.borgmatic-snapshot-1234/./mnt/subvol1/.cache', Pattern_type.EXCLUDE), - Pattern('/mnt/subvol1/.borgmatic-snapshot-1234/./mnt/subvol1', Pattern_type.INCLUDE), - Pattern('/mnt/subvol2/.borgmatic-snapshot-1234/./mnt/subvol2'), - Pattern('/mnt/subvol2/.borgmatic-snapshot-1234/./mnt/subvol2', Pattern_type.INCLUDE), + Pattern('/mnt/subvol1/.borgmatic-snapshot/./mnt/subvol1'), + Pattern('/mnt/subvol1/.borgmatic-snapshot/./mnt/subvol1/.cache', Pattern_type.EXCLUDE), + Pattern('/mnt/subvol1/.borgmatic-snapshot/./mnt/subvol1', Pattern_type.INCLUDE), + Pattern('/mnt/subvol2/.borgmatic-snapshot/./mnt/subvol2'), + Pattern('/mnt/subvol2/.borgmatic-snapshot/./mnt/subvol2', Pattern_type.INCLUDE), ] assert config == { 'btrfs': {}, diff --git a/tests/unit/hooks/data_source/test_btrfs.py b/tests/unit/hooks/data_source/test_btrfs.py index 25a1b1e4..58e0e1fc 100644 --- a/tests/unit/hooks/data_source/test_btrfs.py +++ b/tests/unit/hooks/data_source/test_btrfs.py @@ -340,8 +340,8 @@ def test_get_subvolumes_skips_non_config_patterns(): @pytest.mark.parametrize( 'subvolume_path,expected_snapshot_path', ( - ('/foo/bar', '/foo/bar/.borgmatic-snapshot-1234/foo/bar'), - ('/', '/.borgmatic-snapshot-1234'), + ('/foo/bar', '/foo/bar/.borgmatic-snapshot/foo/bar'), + ('/', '/.borgmatic-snapshot'), ), ) def test_make_snapshot_path_includes_stripped_subvolume_path( @@ -359,14 +359,14 @@ def test_make_snapshot_path_includes_stripped_subvolume_path( ( '/foo/bar', Pattern('/foo/bar/baz'), - Pattern('/foo/bar/.borgmatic-snapshot-1234/./foo/bar/baz'), + Pattern('/foo/bar/.borgmatic-snapshot/./foo/bar/baz'), ), - ('/foo/bar', Pattern('/foo/bar'), Pattern('/foo/bar/.borgmatic-snapshot-1234/./foo/bar')), + ('/foo/bar', Pattern('/foo/bar'), Pattern('/foo/bar/.borgmatic-snapshot/./foo/bar')), ( '/foo/bar', Pattern('^/foo/bar', Pattern_type.INCLUDE, Pattern_style.REGULAR_EXPRESSION), Pattern( - '^/foo/bar/.borgmatic-snapshot-1234/./foo/bar', + '^/foo/bar/.borgmatic-snapshot/./foo/bar', Pattern_type.INCLUDE, Pattern_style.REGULAR_EXPRESSION, ), @@ -375,17 +375,17 @@ def test_make_snapshot_path_includes_stripped_subvolume_path( '/foo/bar', Pattern('/foo/bar', Pattern_type.INCLUDE, Pattern_style.REGULAR_EXPRESSION), Pattern( - '/foo/bar/.borgmatic-snapshot-1234/./foo/bar', + '/foo/bar/.borgmatic-snapshot/./foo/bar', Pattern_type.INCLUDE, Pattern_style.REGULAR_EXPRESSION, ), ), - ('/', Pattern('/foo'), Pattern('/.borgmatic-snapshot-1234/./foo')), - ('/', Pattern('/'), Pattern('/.borgmatic-snapshot-1234/./')), + ('/', Pattern('/foo'), Pattern('/.borgmatic-snapshot/./foo')), + ('/', Pattern('/'), Pattern('/.borgmatic-snapshot/./')), ( '/foo/bar', Pattern('/foo/bar/./baz'), - Pattern('/foo/bar/.borgmatic-snapshot-1234/foo/bar/./baz'), + Pattern('/foo/bar/.borgmatic-snapshot/foo/bar/./baz'), ), ), ) @@ -409,26 +409,26 @@ def test_dump_data_sources_snapshots_each_subvolume_and_replaces_patterns(): ), ) flexmock(module).should_receive('make_snapshot_path').with_args('/mnt/subvol1').and_return( - '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1', + '/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1', ) flexmock(module).should_receive('make_snapshot_path').with_args('/mnt/subvol2').and_return( - '/mnt/subvol2/.borgmatic-snapshot-1234/mnt/subvol2', + '/mnt/subvol2/.borgmatic-snapshot/mnt/subvol2', ) flexmock(module).should_receive('snapshot_subvolume').with_args( 'btrfs', '/mnt/subvol1', - '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1', + '/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1', ).once() flexmock(module).should_receive('snapshot_subvolume').with_args( 'btrfs', '/mnt/subvol2', - '/mnt/subvol2/.borgmatic-snapshot-1234/mnt/subvol2', + '/mnt/subvol2/.borgmatic-snapshot/mnt/subvol2', ).once() flexmock(module).should_receive('make_snapshot_exclude_pattern').with_args( '/mnt/subvol1', ).and_return( Pattern( - '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1/.borgmatic-snapshot-1234', + '/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1/.borgmatic-snapshot', Pattern_type.NO_RECURSE, Pattern_style.FNMATCH, ), @@ -437,7 +437,7 @@ def test_dump_data_sources_snapshots_each_subvolume_and_replaces_patterns(): '/mnt/subvol2', ).and_return( Pattern( - '/mnt/subvol2/.borgmatic-snapshot-1234/mnt/subvol2/.borgmatic-snapshot-1234', + '/mnt/subvol2/.borgmatic-snapshot/mnt/subvol2/.borgmatic-snapshot', Pattern_type.NO_RECURSE, Pattern_style.FNMATCH, ), @@ -445,11 +445,11 @@ def test_dump_data_sources_snapshots_each_subvolume_and_replaces_patterns(): flexmock(module).should_receive('make_borg_snapshot_pattern').with_args( '/mnt/subvol1', object, - ).and_return(Pattern('/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1')) + ).and_return(Pattern('/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1')) flexmock(module).should_receive('make_borg_snapshot_pattern').with_args( '/mnt/subvol2', object, - ).and_return(Pattern('/mnt/subvol2/.borgmatic-snapshot-1234/mnt/subvol2')) + ).and_return(Pattern('/mnt/subvol2/.borgmatic-snapshot/mnt/subvol2')) flexmock(module.borgmatic.hooks.data_source.config).should_receive( 'get_last_pattern_index' ).and_return(0) @@ -457,7 +457,7 @@ def test_dump_data_sources_snapshots_each_subvolume_and_replaces_patterns(): object, Pattern('/mnt/subvol1'), module.borgmatic.borg.pattern.Pattern( - '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1', + '/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1', source=module.borgmatic.borg.pattern.Pattern_source.HOOK, ), 0, @@ -466,7 +466,7 @@ def test_dump_data_sources_snapshots_each_subvolume_and_replaces_patterns(): object, Pattern('/mnt/subvol2'), module.borgmatic.borg.pattern.Pattern( - '/mnt/subvol2/.borgmatic-snapshot-1234/mnt/subvol2', + '/mnt/subvol2/.borgmatic-snapshot/mnt/subvol2', source=module.borgmatic.borg.pattern.Pattern_source.HOOK, ), 0, @@ -474,7 +474,7 @@ def test_dump_data_sources_snapshots_each_subvolume_and_replaces_patterns(): flexmock(module.borgmatic.hooks.data_source.config).should_receive('inject_pattern').with_args( object, module.borgmatic.borg.pattern.Pattern( - '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1/.borgmatic-snapshot-1234', + '/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1/.borgmatic-snapshot', Pattern_type.NO_RECURSE, Pattern_style.FNMATCH, ), @@ -482,7 +482,7 @@ def test_dump_data_sources_snapshots_each_subvolume_and_replaces_patterns(): flexmock(module.borgmatic.hooks.data_source.config).should_receive('inject_pattern').with_args( object, module.borgmatic.borg.pattern.Pattern( - '/mnt/subvol2/.borgmatic-snapshot-1234/mnt/subvol2/.borgmatic-snapshot-1234', + '/mnt/subvol2/.borgmatic-snapshot/mnt/subvol2/.borgmatic-snapshot', Pattern_type.NO_RECURSE, Pattern_style.FNMATCH, ), @@ -512,18 +512,18 @@ def test_dump_data_sources_uses_custom_btrfs_command_in_commands(): (module.Subvolume('/mnt/subvol1', contained_patterns=(Pattern('/mnt/subvol1'),)),), ) flexmock(module).should_receive('make_snapshot_path').with_args('/mnt/subvol1').and_return( - '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1', + '/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1', ) flexmock(module).should_receive('snapshot_subvolume').with_args( '/usr/local/bin/btrfs', '/mnt/subvol1', - '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1', + '/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1', ).once() flexmock(module).should_receive('make_snapshot_exclude_pattern').with_args( '/mnt/subvol1', ).and_return( Pattern( - '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1/.borgmatic-snapshot-1234', + '/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1/.borgmatic-snapshot', Pattern_type.NO_RECURSE, Pattern_style.FNMATCH, ), @@ -531,7 +531,7 @@ def test_dump_data_sources_uses_custom_btrfs_command_in_commands(): flexmock(module).should_receive('make_borg_snapshot_pattern').with_args( '/mnt/subvol1', object, - ).and_return(Pattern('/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1')) + ).and_return(Pattern('/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1')) flexmock(module.borgmatic.hooks.data_source.config).should_receive( 'get_last_pattern_index' ).and_return(0) @@ -539,7 +539,7 @@ def test_dump_data_sources_uses_custom_btrfs_command_in_commands(): object, Pattern('/mnt/subvol1'), module.borgmatic.borg.pattern.Pattern( - '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1', + '/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1', source=module.borgmatic.borg.pattern.Pattern_source.HOOK, ), 0, @@ -547,7 +547,7 @@ def test_dump_data_sources_uses_custom_btrfs_command_in_commands(): flexmock(module.borgmatic.hooks.data_source.config).should_receive('inject_pattern').with_args( object, module.borgmatic.borg.pattern.Pattern( - '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1/.borgmatic-snapshot-1234', + '/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1/.borgmatic-snapshot', Pattern_type.NO_RECURSE, Pattern_style.FNMATCH, ), @@ -583,18 +583,18 @@ def test_dump_data_sources_with_findmnt_command_warns(): (module.Subvolume('/mnt/subvol1', contained_patterns=(Pattern('/mnt/subvol1'),)),), ).once() flexmock(module).should_receive('make_snapshot_path').with_args('/mnt/subvol1').and_return( - '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1', + '/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1', ) flexmock(module).should_receive('snapshot_subvolume').with_args( 'btrfs', '/mnt/subvol1', - '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1', + '/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1', ).once() flexmock(module).should_receive('make_snapshot_exclude_pattern').with_args( '/mnt/subvol1', ).and_return( Pattern( - '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1/.borgmatic-snapshot-1234', + '/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1/.borgmatic-snapshot', Pattern_type.NO_RECURSE, Pattern_style.FNMATCH, ), @@ -602,7 +602,7 @@ def test_dump_data_sources_with_findmnt_command_warns(): flexmock(module).should_receive('make_borg_snapshot_pattern').with_args( '/mnt/subvol1', object, - ).and_return(Pattern('/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1')) + ).and_return(Pattern('/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1')) flexmock(module.borgmatic.hooks.data_source.config).should_receive( 'get_last_pattern_index' ).and_return(0) @@ -610,7 +610,7 @@ def test_dump_data_sources_with_findmnt_command_warns(): object, Pattern('/mnt/subvol1'), module.borgmatic.borg.pattern.Pattern( - '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1', + '/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1', source=module.borgmatic.borg.pattern.Pattern_source.HOOK, ), 0, @@ -618,7 +618,7 @@ def test_dump_data_sources_with_findmnt_command_warns(): flexmock(module.borgmatic.hooks.data_source.config).should_receive('inject_pattern').with_args( object, module.borgmatic.borg.pattern.Pattern( - '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1/.borgmatic-snapshot-1234', + '/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1/.borgmatic-snapshot', Pattern_type.NO_RECURSE, Pattern_style.FNMATCH, ), @@ -650,7 +650,7 @@ def test_dump_data_sources_with_dry_run_skips_snapshot_and_patterns_update(): (module.Subvolume('/mnt/subvol1', contained_patterns=(Pattern('/mnt/subvol1'),)),), ) flexmock(module).should_receive('make_snapshot_path').with_args('/mnt/subvol1').and_return( - '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1', + '/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1', ) flexmock(module).should_receive('snapshot_subvolume').never() flexmock(module).should_receive('make_snapshot_exclude_pattern').never() @@ -712,90 +712,90 @@ def test_remove_data_source_dumps_deletes_snapshots(): ), ) flexmock(module).should_receive('make_snapshot_path').with_args('/mnt/subvol1').and_return( - '/mnt/subvol1/.borgmatic-snapshot-1234/./mnt/subvol1', + '/mnt/subvol1/.borgmatic-snapshot/./mnt/subvol1', ) flexmock(module).should_receive('make_snapshot_path').with_args('/mnt/subvol2').and_return( - '/mnt/subvol2/.borgmatic-snapshot-1234/./mnt/subvol2', + '/mnt/subvol2/.borgmatic-snapshot/./mnt/subvol2', ) flexmock(module.borgmatic.config.paths).should_receive( 'replace_temporary_subdirectory_with_glob', ).with_args( - '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1', + '/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1', temporary_directory_prefix=module.BORGMATIC_SNAPSHOT_PREFIX, ).and_return('/mnt/subvol1/.borgmatic-*/mnt/subvol1') flexmock(module.borgmatic.config.paths).should_receive( 'replace_temporary_subdirectory_with_glob', ).with_args( - '/mnt/subvol2/.borgmatic-snapshot-1234/mnt/subvol2', + '/mnt/subvol2/.borgmatic-snapshot/mnt/subvol2', temporary_directory_prefix=module.BORGMATIC_SNAPSHOT_PREFIX, ).and_return('/mnt/subvol2/.borgmatic-*/mnt/subvol2') flexmock(module.glob).should_receive('glob').with_args( '/mnt/subvol1/.borgmatic-*/mnt/subvol1', ).and_return( ( - '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1', - '/mnt/subvol1/.borgmatic-snapshot-5678/mnt/subvol1', + '/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1', + '/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1', ), ) flexmock(module.glob).should_receive('glob').with_args( '/mnt/subvol2/.borgmatic-*/mnt/subvol2', ).and_return( ( - '/mnt/subvol2/.borgmatic-snapshot-1234/mnt/subvol2', - '/mnt/subvol2/.borgmatic-snapshot-5678/mnt/subvol2', + '/mnt/subvol2/.borgmatic-snapshot/mnt/subvol2', + '/mnt/subvol2/.borgmatic-snapshot/mnt/subvol2', ), ) flexmock(module.os.path).should_receive('isdir').with_args( - '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1', + '/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1', ).and_return(True) flexmock(module.os.path).should_receive('isdir').with_args( - '/mnt/subvol1/.borgmatic-snapshot-5678/mnt/subvol1', + '/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1', ).and_return(True) flexmock(module.os.path).should_receive('isdir').with_args( - '/mnt/subvol2/.borgmatic-snapshot-1234/mnt/subvol2', + '/mnt/subvol2/.borgmatic-snapshot/mnt/subvol2', ).and_return(True) flexmock(module.os.path).should_receive('isdir').with_args( - '/mnt/subvol2/.borgmatic-snapshot-5678/mnt/subvol2', + '/mnt/subvol2/.borgmatic-snapshot/mnt/subvol2', ).and_return(False) flexmock(module).should_receive('delete_snapshot').with_args( 'btrfs', - '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1', + '/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1', ).once() flexmock(module).should_receive('delete_snapshot').with_args( 'btrfs', - '/mnt/subvol1/.borgmatic-snapshot-5678/mnt/subvol1', + '/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1', ).once() flexmock(module).should_receive('delete_snapshot').with_args( 'btrfs', - '/mnt/subvol2/.borgmatic-snapshot-1234/mnt/subvol2', + '/mnt/subvol2/.borgmatic-snapshot/mnt/subvol2', ).once() flexmock(module).should_receive('delete_snapshot').with_args( 'btrfs', - '/mnt/subvol2/.borgmatic-snapshot-5678/mnt/subvol2', + '/mnt/subvol2/.borgmatic-snapshot/mnt/subvol2', ).never() flexmock(module.os.path).should_receive('isdir').with_args( - '/mnt/subvol1/.borgmatic-snapshot-1234', + '/mnt/subvol1/.borgmatic-snapshot', ).and_return(True) flexmock(module.os.path).should_receive('isdir').with_args( - '/mnt/subvol1/.borgmatic-snapshot-5678', + '/mnt/subvol1/.borgmatic-snapshot', ).and_return(True) flexmock(module.os.path).should_receive('isdir').with_args( - '/mnt/subvol2/.borgmatic-snapshot-1234', + '/mnt/subvol2/.borgmatic-snapshot', ).and_return(True) flexmock(module.os.path).should_receive('isdir').with_args( - '/mnt/subvol2/.borgmatic-snapshot-5678', + '/mnt/subvol2/.borgmatic-snapshot', ).and_return(True) flexmock(module.shutil).should_receive('rmtree').with_args( - '/mnt/subvol1/.borgmatic-snapshot-1234', + '/mnt/subvol1/.borgmatic-snapshot', ).once() flexmock(module.shutil).should_receive('rmtree').with_args( - '/mnt/subvol1/.borgmatic-snapshot-5678', + '/mnt/subvol1/.borgmatic-snapshot', ).once() flexmock(module.shutil).should_receive('rmtree').with_args( - '/mnt/subvol2/.borgmatic-snapshot-1234', + '/mnt/subvol2/.borgmatic-snapshot', ).once() flexmock(module.shutil).should_receive('rmtree').with_args( - '/mnt/subvol2/.borgmatic-snapshot-5678', + '/mnt/subvol2/.borgmatic-snapshot', ).never() module.remove_data_source_dumps( @@ -874,50 +874,50 @@ def test_remove_data_source_dumps_with_dry_run_skips_deletes(): ), ) flexmock(module).should_receive('make_snapshot_path').with_args('/mnt/subvol1').and_return( - '/mnt/subvol1/.borgmatic-snapshot-1234/./mnt/subvol1', + '/mnt/subvol1/.borgmatic-snapshot/./mnt/subvol1', ) flexmock(module).should_receive('make_snapshot_path').with_args('/mnt/subvol2').and_return( - '/mnt/subvol2/.borgmatic-snapshot-1234/./mnt/subvol2', + '/mnt/subvol2/.borgmatic-snapshot/./mnt/subvol2', ) flexmock(module.borgmatic.config.paths).should_receive( 'replace_temporary_subdirectory_with_glob', ).with_args( - '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1', + '/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1', temporary_directory_prefix=module.BORGMATIC_SNAPSHOT_PREFIX, ).and_return('/mnt/subvol1/.borgmatic-*/mnt/subvol1') flexmock(module.borgmatic.config.paths).should_receive( 'replace_temporary_subdirectory_with_glob', ).with_args( - '/mnt/subvol2/.borgmatic-snapshot-1234/mnt/subvol2', + '/mnt/subvol2/.borgmatic-snapshot/mnt/subvol2', temporary_directory_prefix=module.BORGMATIC_SNAPSHOT_PREFIX, ).and_return('/mnt/subvol2/.borgmatic-*/mnt/subvol2') flexmock(module.glob).should_receive('glob').with_args( '/mnt/subvol1/.borgmatic-*/mnt/subvol1', ).and_return( ( - '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1', - '/mnt/subvol1/.borgmatic-snapshot-5678/mnt/subvol1', + '/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1', + '/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1', ), ) flexmock(module.glob).should_receive('glob').with_args( '/mnt/subvol2/.borgmatic-*/mnt/subvol2', ).and_return( ( - '/mnt/subvol2/.borgmatic-snapshot-1234/mnt/subvol2', - '/mnt/subvol2/.borgmatic-snapshot-5678/mnt/subvol2', + '/mnt/subvol2/.borgmatic-snapshot/mnt/subvol2', + '/mnt/subvol2/.borgmatic-snapshot/mnt/subvol2', ), ) flexmock(module.os.path).should_receive('isdir').with_args( - '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1', + '/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1', ).and_return(True) flexmock(module.os.path).should_receive('isdir').with_args( - '/mnt/subvol1/.borgmatic-snapshot-5678/mnt/subvol1', + '/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1', ).and_return(True) flexmock(module.os.path).should_receive('isdir').with_args( - '/mnt/subvol2/.borgmatic-snapshot-1234/mnt/subvol2', + '/mnt/subvol2/.borgmatic-snapshot/mnt/subvol2', ).and_return(True) flexmock(module.os.path).should_receive('isdir').with_args( - '/mnt/subvol2/.borgmatic-snapshot-5678/mnt/subvol2', + '/mnt/subvol2/.borgmatic-snapshot/mnt/subvol2', ).and_return(False) flexmock(module).should_receive('delete_snapshot').never() flexmock(module.shutil).should_receive('rmtree').never() @@ -959,21 +959,21 @@ def test_remove_data_source_without_snapshots_skips_deletes(): ), ) flexmock(module).should_receive('make_snapshot_path').with_args('/mnt/subvol1').and_return( - '/mnt/subvol1/.borgmatic-snapshot-1234/./mnt/subvol1', + '/mnt/subvol1/.borgmatic-snapshot/./mnt/subvol1', ) flexmock(module).should_receive('make_snapshot_path').with_args('/mnt/subvol2').and_return( - '/mnt/subvol2/.borgmatic-snapshot-1234/./mnt/subvol2', + '/mnt/subvol2/.borgmatic-snapshot/./mnt/subvol2', ) flexmock(module.borgmatic.config.paths).should_receive( 'replace_temporary_subdirectory_with_glob', ).with_args( - '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1', + '/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1', temporary_directory_prefix=module.BORGMATIC_SNAPSHOT_PREFIX, ).and_return('/mnt/subvol1/.borgmatic-*/mnt/subvol1') flexmock(module.borgmatic.config.paths).should_receive( 'replace_temporary_subdirectory_with_glob', ).with_args( - '/mnt/subvol2/.borgmatic-snapshot-1234/mnt/subvol2', + '/mnt/subvol2/.borgmatic-snapshot/mnt/subvol2', temporary_directory_prefix=module.BORGMATIC_SNAPSHOT_PREFIX, ).and_return('/mnt/subvol2/.borgmatic-*/mnt/subvol2') flexmock(module.glob).should_receive('glob').and_return(()) @@ -999,50 +999,50 @@ def test_remove_data_source_dumps_with_delete_snapshot_file_not_found_error_bail ), ) flexmock(module).should_receive('make_snapshot_path').with_args('/mnt/subvol1').and_return( - '/mnt/subvol1/.borgmatic-snapshot-1234/./mnt/subvol1', + '/mnt/subvol1/.borgmatic-snapshot/./mnt/subvol1', ) flexmock(module).should_receive('make_snapshot_path').with_args('/mnt/subvol2').and_return( - '/mnt/subvol2/.borgmatic-snapshot-1234/./mnt/subvol2', + '/mnt/subvol2/.borgmatic-snapshot/./mnt/subvol2', ) flexmock(module.borgmatic.config.paths).should_receive( 'replace_temporary_subdirectory_with_glob', ).with_args( - '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1', + '/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1', temporary_directory_prefix=module.BORGMATIC_SNAPSHOT_PREFIX, ).and_return('/mnt/subvol1/.borgmatic-*/mnt/subvol1') flexmock(module.borgmatic.config.paths).should_receive( 'replace_temporary_subdirectory_with_glob', ).with_args( - '/mnt/subvol2/.borgmatic-snapshot-1234/mnt/subvol2', + '/mnt/subvol2/.borgmatic-snapshot/mnt/subvol2', temporary_directory_prefix=module.BORGMATIC_SNAPSHOT_PREFIX, ).and_return('/mnt/subvol2/.borgmatic-*/mnt/subvol2') flexmock(module.glob).should_receive('glob').with_args( '/mnt/subvol1/.borgmatic-*/mnt/subvol1', ).and_return( ( - '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1', - '/mnt/subvol1/.borgmatic-snapshot-5678/mnt/subvol1', + '/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1', + '/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1', ), ) flexmock(module.glob).should_receive('glob').with_args( '/mnt/subvol2/.borgmatic-*/mnt/subvol2', ).and_return( ( - '/mnt/subvol2/.borgmatic-snapshot-1234/mnt/subvol2', - '/mnt/subvol2/.borgmatic-snapshot-5678/mnt/subvol2', + '/mnt/subvol2/.borgmatic-snapshot/mnt/subvol2', + '/mnt/subvol2/.borgmatic-snapshot/mnt/subvol2', ), ) flexmock(module.os.path).should_receive('isdir').with_args( - '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1', + '/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1', ).and_return(True) flexmock(module.os.path).should_receive('isdir').with_args( - '/mnt/subvol1/.borgmatic-snapshot-5678/mnt/subvol1', + '/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1', ).and_return(True) flexmock(module.os.path).should_receive('isdir').with_args( - '/mnt/subvol2/.borgmatic-snapshot-1234/mnt/subvol2', + '/mnt/subvol2/.borgmatic-snapshot/mnt/subvol2', ).and_return(True) flexmock(module.os.path).should_receive('isdir').with_args( - '/mnt/subvol2/.borgmatic-snapshot-5678/mnt/subvol2', + '/mnt/subvol2/.borgmatic-snapshot/mnt/subvol2', ).and_return(False) flexmock(module).should_receive('delete_snapshot').and_raise(FileNotFoundError) flexmock(module.shutil).should_receive('rmtree').never() @@ -1065,50 +1065,50 @@ def test_remove_data_source_dumps_with_delete_snapshot_called_process_error_bail ), ) flexmock(module).should_receive('make_snapshot_path').with_args('/mnt/subvol1').and_return( - '/mnt/subvol1/.borgmatic-snapshot-1234/./mnt/subvol1', + '/mnt/subvol1/.borgmatic-snapshot/./mnt/subvol1', ) flexmock(module).should_receive('make_snapshot_path').with_args('/mnt/subvol2').and_return( - '/mnt/subvol2/.borgmatic-snapshot-1234/./mnt/subvol2', + '/mnt/subvol2/.borgmatic-snapshot/./mnt/subvol2', ) flexmock(module.borgmatic.config.paths).should_receive( 'replace_temporary_subdirectory_with_glob', ).with_args( - '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1', + '/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1', temporary_directory_prefix=module.BORGMATIC_SNAPSHOT_PREFIX, ).and_return('/mnt/subvol1/.borgmatic-*/mnt/subvol1') flexmock(module.borgmatic.config.paths).should_receive( 'replace_temporary_subdirectory_with_glob', ).with_args( - '/mnt/subvol2/.borgmatic-snapshot-1234/mnt/subvol2', + '/mnt/subvol2/.borgmatic-snapshot/mnt/subvol2', temporary_directory_prefix=module.BORGMATIC_SNAPSHOT_PREFIX, ).and_return('/mnt/subvol2/.borgmatic-*/mnt/subvol2') flexmock(module.glob).should_receive('glob').with_args( '/mnt/subvol1/.borgmatic-*/mnt/subvol1', ).and_return( ( - '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1', - '/mnt/subvol1/.borgmatic-snapshot-5678/mnt/subvol1', + '/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1', + '/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1', ), ) flexmock(module.glob).should_receive('glob').with_args( '/mnt/subvol2/.borgmatic-*/mnt/subvol2', ).and_return( ( - '/mnt/subvol2/.borgmatic-snapshot-1234/mnt/subvol2', - '/mnt/subvol2/.borgmatic-snapshot-5678/mnt/subvol2', + '/mnt/subvol2/.borgmatic-snapshot/mnt/subvol2', + '/mnt/subvol2/.borgmatic-snapshot/mnt/subvol2', ), ) flexmock(module.os.path).should_receive('isdir').with_args( - '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1', + '/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1', ).and_return(True) flexmock(module.os.path).should_receive('isdir').with_args( - '/mnt/subvol1/.borgmatic-snapshot-5678/mnt/subvol1', + '/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1', ).and_return(True) flexmock(module.os.path).should_receive('isdir').with_args( - '/mnt/subvol2/.borgmatic-snapshot-1234/mnt/subvol2', + '/mnt/subvol2/.borgmatic-snapshot/mnt/subvol2', ).and_return(True) flexmock(module.os.path).should_receive('isdir').with_args( - '/mnt/subvol2/.borgmatic-snapshot-5678/mnt/subvol2', + '/mnt/subvol2/.borgmatic-snapshot/mnt/subvol2', ).and_return(False) flexmock(module).should_receive('delete_snapshot').and_raise( module.subprocess.CalledProcessError(1, 'command', 'error'), @@ -1131,36 +1131,36 @@ def test_remove_data_source_dumps_with_root_subvolume_skips_duplicate_removal(): ) flexmock(module).should_receive('make_snapshot_path').with_args('/').and_return( - '/.borgmatic-snapshot-1234', + '/.borgmatic-snapshot', ) flexmock(module.borgmatic.config.paths).should_receive( 'replace_temporary_subdirectory_with_glob', ).with_args( - '/.borgmatic-snapshot-1234', + '/.borgmatic-snapshot', temporary_directory_prefix=module.BORGMATIC_SNAPSHOT_PREFIX, ).and_return('/.borgmatic-*') flexmock(module.glob).should_receive('glob').with_args('/.borgmatic-*').and_return( - ('/.borgmatic-snapshot-1234', '/.borgmatic-snapshot-5678'), + ('/.borgmatic-snapshot', '/.borgmatic-snapshot'), ) flexmock(module.os.path).should_receive('isdir').with_args( - '/.borgmatic-snapshot-1234' + '/.borgmatic-snapshot' ).and_return( True, ).and_return(False) flexmock(module.os.path).should_receive('isdir').with_args( - '/.borgmatic-snapshot-5678' + '/.borgmatic-snapshot' ).and_return( True, ).and_return(False) flexmock(module).should_receive('delete_snapshot').with_args( - 'btrfs', '/.borgmatic-snapshot-1234' + 'btrfs', '/.borgmatic-snapshot' ).once() flexmock(module).should_receive('delete_snapshot').with_args( - 'btrfs', '/.borgmatic-snapshot-5678' + 'btrfs', '/.borgmatic-snapshot' ).once() flexmock(module.os.path).should_receive('isdir').with_args('').and_return(False) From 4976352fd3b65c25698d4e01960fd6aed4ab3900 Mon Sep 17 00:00:00 2001 From: Jackson Date: Sat, 22 Nov 2025 05:49:15 +0100 Subject: [PATCH 3/5] add to btrfs docs that caching works now --- docs/reference/configuration/data-sources/btrfs.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/reference/configuration/data-sources/btrfs.md b/docs/reference/configuration/data-sources/btrfs.md index 16cf48d3..bebb4eaa 100644 --- a/docs/reference/configuration/data-sources/btrfs.md +++ b/docs/reference/configuration/data-sources/btrfs.md @@ -70,6 +70,10 @@ temporary snapshot directory in use at the time the archive was created, as Borg ## Performance +With Borg version 1.x, New in version +2.0.12 borgmatic uses consistent snapshot paths between invocations, +so backups will be cached correctly. No configuration is necessary. + With Borg version 1.x Because of the way that Btrfs snapshot paths change from one borgmatic invocation to the next, the [Borg file From dec47298bd2475d9a65587dcb5c8f7933ee78031 Mon Sep 17 00:00:00 2001 From: Jackson Date: Sat, 22 Nov 2025 08:03:40 +0100 Subject: [PATCH 4/5] somehow make a test work --- tests/unit/hooks/data_source/test_btrfs.py | 28 ---------------------- 1 file changed, 28 deletions(-) diff --git a/tests/unit/hooks/data_source/test_btrfs.py b/tests/unit/hooks/data_source/test_btrfs.py index 58e0e1fc..af891aac 100644 --- a/tests/unit/hooks/data_source/test_btrfs.py +++ b/tests/unit/hooks/data_source/test_btrfs.py @@ -734,7 +734,6 @@ def test_remove_data_source_dumps_deletes_snapshots(): ).and_return( ( '/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1', - '/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1', ), ) flexmock(module.glob).should_receive('glob').with_args( @@ -742,25 +741,14 @@ def test_remove_data_source_dumps_deletes_snapshots(): ).and_return( ( '/mnt/subvol2/.borgmatic-snapshot/mnt/subvol2', - '/mnt/subvol2/.borgmatic-snapshot/mnt/subvol2', ), ) flexmock(module.os.path).should_receive('isdir').with_args( '/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1', ).and_return(True) - flexmock(module.os.path).should_receive('isdir').with_args( - '/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1', - ).and_return(True) flexmock(module.os.path).should_receive('isdir').with_args( '/mnt/subvol2/.borgmatic-snapshot/mnt/subvol2', ).and_return(True) - flexmock(module.os.path).should_receive('isdir').with_args( - '/mnt/subvol2/.borgmatic-snapshot/mnt/subvol2', - ).and_return(False) - flexmock(module).should_receive('delete_snapshot').with_args( - 'btrfs', - '/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1', - ).once() flexmock(module).should_receive('delete_snapshot').with_args( 'btrfs', '/mnt/subvol1/.borgmatic-snapshot/mnt/subvol1', @@ -769,34 +757,18 @@ def test_remove_data_source_dumps_deletes_snapshots(): 'btrfs', '/mnt/subvol2/.borgmatic-snapshot/mnt/subvol2', ).once() - flexmock(module).should_receive('delete_snapshot').with_args( - 'btrfs', - '/mnt/subvol2/.borgmatic-snapshot/mnt/subvol2', - ).never() flexmock(module.os.path).should_receive('isdir').with_args( '/mnt/subvol1/.borgmatic-snapshot', ).and_return(True) - flexmock(module.os.path).should_receive('isdir').with_args( - '/mnt/subvol1/.borgmatic-snapshot', - ).and_return(True) - flexmock(module.os.path).should_receive('isdir').with_args( - '/mnt/subvol2/.borgmatic-snapshot', - ).and_return(True) flexmock(module.os.path).should_receive('isdir').with_args( '/mnt/subvol2/.borgmatic-snapshot', ).and_return(True) flexmock(module.shutil).should_receive('rmtree').with_args( '/mnt/subvol1/.borgmatic-snapshot', ).once() - flexmock(module.shutil).should_receive('rmtree').with_args( - '/mnt/subvol1/.borgmatic-snapshot', - ).once() flexmock(module.shutil).should_receive('rmtree').with_args( '/mnt/subvol2/.borgmatic-snapshot', ).once() - flexmock(module.shutil).should_receive('rmtree').with_args( - '/mnt/subvol2/.borgmatic-snapshot', - ).never() module.remove_data_source_dumps( hook_config=config['btrfs'], From f158d42b28a07afbd865ebac285bc838cff86b7e Mon Sep 17 00:00:00 2001 From: Jackson Date: Sun, 23 Nov 2025 09:20:03 +0100 Subject: [PATCH 5/5] apply docs suggestions Co-authored-by: Dan Helfman --- docs/reference/configuration/data-sources/btrfs.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/reference/configuration/data-sources/btrfs.md b/docs/reference/configuration/data-sources/btrfs.md index bebb4eaa..74edc6be 100644 --- a/docs/reference/configuration/data-sources/btrfs.md +++ b/docs/reference/configuration/data-sources/btrfs.md @@ -70,13 +70,13 @@ temporary snapshot directory in use at the time the archive was created, as Borg ## Performance -With Borg version 1.x, New in version -2.0.12 borgmatic uses consistent snapshot paths between invocations, -so backups will be cached correctly. No configuration is necessary. +New in borgmatic version 2.0.12, with Borg version +1.x borgmatic uses consistent snapshot paths between invocations, so +backups will be cached correctly. No configuration is necessary. -With Borg version 1.x Because of -the way that Btrfs snapshot paths change from one borgmatic invocation to the -next, the [Borg file +Prior to borgmatic version 2.0.12, with +Borg version 1.x Because of the way that Btrfs snapshot paths change from +one borgmatic invocation to the next, the [Borg file cache](https://borgbackup.readthedocs.io/en/stable/internals/data-structures.html#cache) will never get cache hits on snapshotted files. This makes backing up Btrfs snapshots a little slower than non-snapshotted files that have consistent paths.