|
@@ -399,8 +399,8 @@ def test_make_borg_snapshot_pattern_includes_slashdot_hack_and_stripped_pattern_
|
|
|
assert module.make_borg_snapshot_pattern(subvolume_path, pattern) == expected_pattern
|
|
assert module.make_borg_snapshot_pattern(subvolume_path, pattern) == expected_pattern
|
|
|
|
|
|
|
|
|
|
|
|
|
-def test_dump_data_sources_snapshots_each_subvolume_and_updates_patterns():
|
|
|
|
|
- patterns = [Pattern('/foo'), Pattern('/mnt/subvol1')]
|
|
|
|
|
|
|
+def test_dump_data_sources_snapshots_each_subvolume_and_replaces_patterns():
|
|
|
|
|
+ patterns = [Pattern('/foo'), Pattern('/mnt/subvol1'), Pattern('/mnt/subvol2')]
|
|
|
config = {'btrfs': {}}
|
|
config = {'btrfs': {}}
|
|
|
flexmock(module).should_receive('get_subvolumes').and_return(
|
|
flexmock(module).should_receive('get_subvolumes').and_return(
|
|
|
(
|
|
(
|
|
@@ -409,26 +409,26 @@ def test_dump_data_sources_snapshots_each_subvolume_and_updates_patterns():
|
|
|
),
|
|
),
|
|
|
)
|
|
)
|
|
|
flexmock(module).should_receive('make_snapshot_path').with_args('/mnt/subvol1').and_return(
|
|
flexmock(module).should_receive('make_snapshot_path').with_args('/mnt/subvol1').and_return(
|
|
|
- '/mnt/subvol1/.borgmatic-1234/mnt/subvol1',
|
|
|
|
|
|
|
+ '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1',
|
|
|
)
|
|
)
|
|
|
flexmock(module).should_receive('make_snapshot_path').with_args('/mnt/subvol2').and_return(
|
|
flexmock(module).should_receive('make_snapshot_path').with_args('/mnt/subvol2').and_return(
|
|
|
- '/mnt/subvol2/.borgmatic-1234/mnt/subvol2',
|
|
|
|
|
|
|
+ '/mnt/subvol2/.borgmatic-snapshot-1234/mnt/subvol2',
|
|
|
)
|
|
)
|
|
|
flexmock(module).should_receive('snapshot_subvolume').with_args(
|
|
flexmock(module).should_receive('snapshot_subvolume').with_args(
|
|
|
'btrfs',
|
|
'btrfs',
|
|
|
'/mnt/subvol1',
|
|
'/mnt/subvol1',
|
|
|
- '/mnt/subvol1/.borgmatic-1234/mnt/subvol1',
|
|
|
|
|
|
|
+ '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1',
|
|
|
).once()
|
|
).once()
|
|
|
flexmock(module).should_receive('snapshot_subvolume').with_args(
|
|
flexmock(module).should_receive('snapshot_subvolume').with_args(
|
|
|
'btrfs',
|
|
'btrfs',
|
|
|
'/mnt/subvol2',
|
|
'/mnt/subvol2',
|
|
|
- '/mnt/subvol2/.borgmatic-1234/mnt/subvol2',
|
|
|
|
|
|
|
+ '/mnt/subvol2/.borgmatic-snapshot-1234/mnt/subvol2',
|
|
|
).once()
|
|
).once()
|
|
|
flexmock(module).should_receive('make_snapshot_exclude_pattern').with_args(
|
|
flexmock(module).should_receive('make_snapshot_exclude_pattern').with_args(
|
|
|
'/mnt/subvol1',
|
|
'/mnt/subvol1',
|
|
|
).and_return(
|
|
).and_return(
|
|
|
Pattern(
|
|
Pattern(
|
|
|
- '/mnt/subvol1/.borgmatic-1234/mnt/subvol1/.borgmatic-1234',
|
|
|
|
|
|
|
+ '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1/.borgmatic-snapshot-1234',
|
|
|
Pattern_type.NO_RECURSE,
|
|
Pattern_type.NO_RECURSE,
|
|
|
Pattern_style.FNMATCH,
|
|
Pattern_style.FNMATCH,
|
|
|
),
|
|
),
|
|
@@ -437,7 +437,7 @@ def test_dump_data_sources_snapshots_each_subvolume_and_updates_patterns():
|
|
|
'/mnt/subvol2',
|
|
'/mnt/subvol2',
|
|
|
).and_return(
|
|
).and_return(
|
|
|
Pattern(
|
|
Pattern(
|
|
|
- '/mnt/subvol2/.borgmatic-1234/mnt/subvol2/.borgmatic-1234',
|
|
|
|
|
|
|
+ '/mnt/subvol2/.borgmatic-snapshot-1234/mnt/subvol2/.borgmatic-snapshot-1234',
|
|
|
Pattern_type.NO_RECURSE,
|
|
Pattern_type.NO_RECURSE,
|
|
|
Pattern_style.FNMATCH,
|
|
Pattern_style.FNMATCH,
|
|
|
),
|
|
),
|
|
@@ -445,11 +445,43 @@ def test_dump_data_sources_snapshots_each_subvolume_and_updates_patterns():
|
|
|
flexmock(module).should_receive('make_borg_snapshot_pattern').with_args(
|
|
flexmock(module).should_receive('make_borg_snapshot_pattern').with_args(
|
|
|
'/mnt/subvol1',
|
|
'/mnt/subvol1',
|
|
|
object,
|
|
object,
|
|
|
- ).and_return(Pattern('/mnt/subvol1/.borgmatic-1234/mnt/subvol1'))
|
|
|
|
|
|
|
+ ).and_return(Pattern('/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1'))
|
|
|
flexmock(module).should_receive('make_borg_snapshot_pattern').with_args(
|
|
flexmock(module).should_receive('make_borg_snapshot_pattern').with_args(
|
|
|
'/mnt/subvol2',
|
|
'/mnt/subvol2',
|
|
|
object,
|
|
object,
|
|
|
- ).and_return(Pattern('/mnt/subvol2/.borgmatic-1234/mnt/subvol2'))
|
|
|
|
|
|
|
+ ).and_return(Pattern('/mnt/subvol2/.borgmatic-snapshot-1234/mnt/subvol2'))
|
|
|
|
|
+ flexmock(module.borgmatic.hooks.data_source.config).should_receive('replace_pattern').with_args(
|
|
|
|
|
+ object,
|
|
|
|
|
+ Pattern('/mnt/subvol1'),
|
|
|
|
|
+ module.borgmatic.borg.pattern.Pattern(
|
|
|
|
|
+ '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1',
|
|
|
|
|
+ source=module.borgmatic.borg.pattern.Pattern_source.HOOK,
|
|
|
|
|
+ ),
|
|
|
|
|
+ ).once()
|
|
|
|
|
+ flexmock(module.borgmatic.hooks.data_source.config).should_receive('replace_pattern').with_args(
|
|
|
|
|
+ object,
|
|
|
|
|
+ Pattern('/mnt/subvol2'),
|
|
|
|
|
+ module.borgmatic.borg.pattern.Pattern(
|
|
|
|
|
+ '/mnt/subvol2/.borgmatic-snapshot-1234/mnt/subvol2',
|
|
|
|
|
+ source=module.borgmatic.borg.pattern.Pattern_source.HOOK,
|
|
|
|
|
+ ),
|
|
|
|
|
+ ).once()
|
|
|
|
|
+ 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',
|
|
|
|
|
+ Pattern_type.NO_RECURSE,
|
|
|
|
|
+ Pattern_style.FNMATCH,
|
|
|
|
|
+ ),
|
|
|
|
|
+ ).once()
|
|
|
|
|
+ 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',
|
|
|
|
|
+ Pattern_type.NO_RECURSE,
|
|
|
|
|
+ Pattern_style.FNMATCH,
|
|
|
|
|
+ ),
|
|
|
|
|
+ ).once()
|
|
|
|
|
|
|
|
assert (
|
|
assert (
|
|
|
module.dump_data_sources(
|
|
module.dump_data_sources(
|
|
@@ -463,21 +495,6 @@ def test_dump_data_sources_snapshots_each_subvolume_and_updates_patterns():
|
|
|
== []
|
|
== []
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
- assert patterns == [
|
|
|
|
|
- Pattern('/foo'),
|
|
|
|
|
- Pattern('/mnt/subvol1/.borgmatic-1234/mnt/subvol1'),
|
|
|
|
|
- Pattern(
|
|
|
|
|
- '/mnt/subvol1/.borgmatic-1234/mnt/subvol1/.borgmatic-1234',
|
|
|
|
|
- Pattern_type.NO_RECURSE,
|
|
|
|
|
- Pattern_style.FNMATCH,
|
|
|
|
|
- ),
|
|
|
|
|
- Pattern('/mnt/subvol2/.borgmatic-1234/mnt/subvol2'),
|
|
|
|
|
- Pattern(
|
|
|
|
|
- '/mnt/subvol2/.borgmatic-1234/mnt/subvol2/.borgmatic-1234',
|
|
|
|
|
- Pattern_type.NO_RECURSE,
|
|
|
|
|
- Pattern_style.FNMATCH,
|
|
|
|
|
- ),
|
|
|
|
|
- ]
|
|
|
|
|
assert config == {
|
|
assert config == {
|
|
|
'btrfs': {},
|
|
'btrfs': {},
|
|
|
}
|
|
}
|
|
@@ -490,18 +507,18 @@ def test_dump_data_sources_uses_custom_btrfs_command_in_commands():
|
|
|
(module.Subvolume('/mnt/subvol1', contained_patterns=(Pattern('/mnt/subvol1'),)),),
|
|
(module.Subvolume('/mnt/subvol1', contained_patterns=(Pattern('/mnt/subvol1'),)),),
|
|
|
)
|
|
)
|
|
|
flexmock(module).should_receive('make_snapshot_path').with_args('/mnt/subvol1').and_return(
|
|
flexmock(module).should_receive('make_snapshot_path').with_args('/mnt/subvol1').and_return(
|
|
|
- '/mnt/subvol1/.borgmatic-1234/mnt/subvol1',
|
|
|
|
|
|
|
+ '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1',
|
|
|
)
|
|
)
|
|
|
flexmock(module).should_receive('snapshot_subvolume').with_args(
|
|
flexmock(module).should_receive('snapshot_subvolume').with_args(
|
|
|
'/usr/local/bin/btrfs',
|
|
'/usr/local/bin/btrfs',
|
|
|
'/mnt/subvol1',
|
|
'/mnt/subvol1',
|
|
|
- '/mnt/subvol1/.borgmatic-1234/mnt/subvol1',
|
|
|
|
|
|
|
+ '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1',
|
|
|
).once()
|
|
).once()
|
|
|
flexmock(module).should_receive('make_snapshot_exclude_pattern').with_args(
|
|
flexmock(module).should_receive('make_snapshot_exclude_pattern').with_args(
|
|
|
'/mnt/subvol1',
|
|
'/mnt/subvol1',
|
|
|
).and_return(
|
|
).and_return(
|
|
|
Pattern(
|
|
Pattern(
|
|
|
- '/mnt/subvol1/.borgmatic-1234/mnt/subvol1/.borgmatic-1234',
|
|
|
|
|
|
|
+ '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1/.borgmatic-snapshot-1234',
|
|
|
Pattern_type.NO_RECURSE,
|
|
Pattern_type.NO_RECURSE,
|
|
|
Pattern_style.FNMATCH,
|
|
Pattern_style.FNMATCH,
|
|
|
),
|
|
),
|
|
@@ -509,7 +526,23 @@ def test_dump_data_sources_uses_custom_btrfs_command_in_commands():
|
|
|
flexmock(module).should_receive('make_borg_snapshot_pattern').with_args(
|
|
flexmock(module).should_receive('make_borg_snapshot_pattern').with_args(
|
|
|
'/mnt/subvol1',
|
|
'/mnt/subvol1',
|
|
|
object,
|
|
object,
|
|
|
- ).and_return(Pattern('/mnt/subvol1/.borgmatic-1234/mnt/subvol1'))
|
|
|
|
|
|
|
+ ).and_return(Pattern('/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1'))
|
|
|
|
|
+ flexmock(module.borgmatic.hooks.data_source.config).should_receive('replace_pattern').with_args(
|
|
|
|
|
+ object,
|
|
|
|
|
+ Pattern('/mnt/subvol1'),
|
|
|
|
|
+ module.borgmatic.borg.pattern.Pattern(
|
|
|
|
|
+ '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1',
|
|
|
|
|
+ source=module.borgmatic.borg.pattern.Pattern_source.HOOK,
|
|
|
|
|
+ ),
|
|
|
|
|
+ ).once()
|
|
|
|
|
+ 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',
|
|
|
|
|
+ Pattern_type.NO_RECURSE,
|
|
|
|
|
+ Pattern_style.FNMATCH,
|
|
|
|
|
+ ),
|
|
|
|
|
+ ).once()
|
|
|
|
|
|
|
|
assert (
|
|
assert (
|
|
|
module.dump_data_sources(
|
|
module.dump_data_sources(
|
|
@@ -523,15 +556,6 @@ def test_dump_data_sources_uses_custom_btrfs_command_in_commands():
|
|
|
== []
|
|
== []
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
- assert patterns == [
|
|
|
|
|
- Pattern('/foo'),
|
|
|
|
|
- Pattern('/mnt/subvol1/.borgmatic-1234/mnt/subvol1'),
|
|
|
|
|
- Pattern(
|
|
|
|
|
- '/mnt/subvol1/.borgmatic-1234/mnt/subvol1/.borgmatic-1234',
|
|
|
|
|
- Pattern_type.NO_RECURSE,
|
|
|
|
|
- Pattern_style.FNMATCH,
|
|
|
|
|
- ),
|
|
|
|
|
- ]
|
|
|
|
|
assert config == {
|
|
assert config == {
|
|
|
'btrfs': {
|
|
'btrfs': {
|
|
|
'btrfs_command': '/usr/local/bin/btrfs',
|
|
'btrfs_command': '/usr/local/bin/btrfs',
|
|
@@ -550,18 +574,18 @@ def test_dump_data_sources_with_findmnt_command_warns():
|
|
|
(module.Subvolume('/mnt/subvol1', contained_patterns=(Pattern('/mnt/subvol1'),)),),
|
|
(module.Subvolume('/mnt/subvol1', contained_patterns=(Pattern('/mnt/subvol1'),)),),
|
|
|
).once()
|
|
).once()
|
|
|
flexmock(module).should_receive('make_snapshot_path').with_args('/mnt/subvol1').and_return(
|
|
flexmock(module).should_receive('make_snapshot_path').with_args('/mnt/subvol1').and_return(
|
|
|
- '/mnt/subvol1/.borgmatic-1234/mnt/subvol1',
|
|
|
|
|
|
|
+ '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1',
|
|
|
)
|
|
)
|
|
|
flexmock(module).should_receive('snapshot_subvolume').with_args(
|
|
flexmock(module).should_receive('snapshot_subvolume').with_args(
|
|
|
'btrfs',
|
|
'btrfs',
|
|
|
'/mnt/subvol1',
|
|
'/mnt/subvol1',
|
|
|
- '/mnt/subvol1/.borgmatic-1234/mnt/subvol1',
|
|
|
|
|
|
|
+ '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1',
|
|
|
).once()
|
|
).once()
|
|
|
flexmock(module).should_receive('make_snapshot_exclude_pattern').with_args(
|
|
flexmock(module).should_receive('make_snapshot_exclude_pattern').with_args(
|
|
|
'/mnt/subvol1',
|
|
'/mnt/subvol1',
|
|
|
).and_return(
|
|
).and_return(
|
|
|
Pattern(
|
|
Pattern(
|
|
|
- '/mnt/subvol1/.borgmatic-1234/mnt/subvol1/.borgmatic-1234',
|
|
|
|
|
|
|
+ '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1/.borgmatic-snapshot-1234',
|
|
|
Pattern_type.NO_RECURSE,
|
|
Pattern_type.NO_RECURSE,
|
|
|
Pattern_style.FNMATCH,
|
|
Pattern_style.FNMATCH,
|
|
|
),
|
|
),
|
|
@@ -569,7 +593,23 @@ def test_dump_data_sources_with_findmnt_command_warns():
|
|
|
flexmock(module).should_receive('make_borg_snapshot_pattern').with_args(
|
|
flexmock(module).should_receive('make_borg_snapshot_pattern').with_args(
|
|
|
'/mnt/subvol1',
|
|
'/mnt/subvol1',
|
|
|
object,
|
|
object,
|
|
|
- ).and_return(Pattern('/mnt/subvol1/.borgmatic-1234/mnt/subvol1'))
|
|
|
|
|
|
|
+ ).and_return(Pattern('/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1'))
|
|
|
|
|
+ flexmock(module.borgmatic.hooks.data_source.config).should_receive('replace_pattern').with_args(
|
|
|
|
|
+ object,
|
|
|
|
|
+ Pattern('/mnt/subvol1'),
|
|
|
|
|
+ module.borgmatic.borg.pattern.Pattern(
|
|
|
|
|
+ '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1',
|
|
|
|
|
+ source=module.borgmatic.borg.pattern.Pattern_source.HOOK,
|
|
|
|
|
+ ),
|
|
|
|
|
+ ).once()
|
|
|
|
|
+ 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',
|
|
|
|
|
+ Pattern_type.NO_RECURSE,
|
|
|
|
|
+ Pattern_style.FNMATCH,
|
|
|
|
|
+ ),
|
|
|
|
|
+ ).once()
|
|
|
|
|
|
|
|
assert (
|
|
assert (
|
|
|
module.dump_data_sources(
|
|
module.dump_data_sources(
|
|
@@ -583,15 +623,6 @@ def test_dump_data_sources_with_findmnt_command_warns():
|
|
|
== []
|
|
== []
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
- assert patterns == [
|
|
|
|
|
- Pattern('/foo'),
|
|
|
|
|
- Pattern('/mnt/subvol1/.borgmatic-1234/mnt/subvol1'),
|
|
|
|
|
- Pattern(
|
|
|
|
|
- '/mnt/subvol1/.borgmatic-1234/mnt/subvol1/.borgmatic-1234',
|
|
|
|
|
- Pattern_type.NO_RECURSE,
|
|
|
|
|
- Pattern_style.FNMATCH,
|
|
|
|
|
- ),
|
|
|
|
|
- ]
|
|
|
|
|
assert config == {
|
|
assert config == {
|
|
|
'btrfs': {
|
|
'btrfs': {
|
|
|
'findmnt_command': '/usr/local/bin/findmnt',
|
|
'findmnt_command': '/usr/local/bin/findmnt',
|
|
@@ -606,10 +637,12 @@ def test_dump_data_sources_with_dry_run_skips_snapshot_and_patterns_update():
|
|
|
(module.Subvolume('/mnt/subvol1', contained_patterns=(Pattern('/mnt/subvol1'),)),),
|
|
(module.Subvolume('/mnt/subvol1', contained_patterns=(Pattern('/mnt/subvol1'),)),),
|
|
|
)
|
|
)
|
|
|
flexmock(module).should_receive('make_snapshot_path').with_args('/mnt/subvol1').and_return(
|
|
flexmock(module).should_receive('make_snapshot_path').with_args('/mnt/subvol1').and_return(
|
|
|
- '/mnt/subvol1/.borgmatic-1234/mnt/subvol1',
|
|
|
|
|
|
|
+ '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1',
|
|
|
)
|
|
)
|
|
|
flexmock(module).should_receive('snapshot_subvolume').never()
|
|
flexmock(module).should_receive('snapshot_subvolume').never()
|
|
|
flexmock(module).should_receive('make_snapshot_exclude_pattern').never()
|
|
flexmock(module).should_receive('make_snapshot_exclude_pattern').never()
|
|
|
|
|
+ flexmock(module.borgmatic.hooks.data_source.config).should_receive('replace_pattern').never()
|
|
|
|
|
+ flexmock(module.borgmatic.hooks.data_source.config).should_receive('inject_pattern').never()
|
|
|
|
|
|
|
|
assert (
|
|
assert (
|
|
|
module.dump_data_sources(
|
|
module.dump_data_sources(
|
|
@@ -623,7 +656,6 @@ def test_dump_data_sources_with_dry_run_skips_snapshot_and_patterns_update():
|
|
|
== []
|
|
== []
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
- assert patterns == [Pattern('/foo'), Pattern('/mnt/subvol1')]
|
|
|
|
|
assert config == {'btrfs': {}}
|
|
assert config == {'btrfs': {}}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -634,6 +666,8 @@ def test_dump_data_sources_without_matching_subvolumes_skips_snapshot_and_patter
|
|
|
flexmock(module).should_receive('make_snapshot_path').never()
|
|
flexmock(module).should_receive('make_snapshot_path').never()
|
|
|
flexmock(module).should_receive('snapshot_subvolume').never()
|
|
flexmock(module).should_receive('snapshot_subvolume').never()
|
|
|
flexmock(module).should_receive('make_snapshot_exclude_pattern').never()
|
|
flexmock(module).should_receive('make_snapshot_exclude_pattern').never()
|
|
|
|
|
+ flexmock(module.borgmatic.hooks.data_source.config).should_receive('replace_pattern').never()
|
|
|
|
|
+ flexmock(module.borgmatic.hooks.data_source.config).should_receive('inject_pattern').never()
|
|
|
|
|
|
|
|
assert (
|
|
assert (
|
|
|
module.dump_data_sources(
|
|
module.dump_data_sources(
|
|
@@ -647,95 +681,9 @@ def test_dump_data_sources_without_matching_subvolumes_skips_snapshot_and_patter
|
|
|
== []
|
|
== []
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
- assert patterns == [Pattern('/foo'), Pattern('/mnt/subvol1')]
|
|
|
|
|
assert config == {'btrfs': {}}
|
|
assert config == {'btrfs': {}}
|
|
|
|
|
|
|
|
|
|
|
|
|
-def test_dump_data_sources_snapshots_adds_to_existing_exclude_patterns():
|
|
|
|
|
- patterns = [Pattern('/foo'), Pattern('/mnt/subvol1')]
|
|
|
|
|
- config = {'btrfs': {}, 'exclude_patterns': ['/bar']}
|
|
|
|
|
- flexmock(module).should_receive('get_subvolumes').and_return(
|
|
|
|
|
- (
|
|
|
|
|
- module.Subvolume('/mnt/subvol1', contained_patterns=(Pattern('/mnt/subvol1'),)),
|
|
|
|
|
- module.Subvolume('/mnt/subvol2', contained_patterns=(Pattern('/mnt/subvol2'),)),
|
|
|
|
|
- ),
|
|
|
|
|
- )
|
|
|
|
|
- flexmock(module).should_receive('make_snapshot_path').with_args('/mnt/subvol1').and_return(
|
|
|
|
|
- '/mnt/subvol1/.borgmatic-1234/mnt/subvol1',
|
|
|
|
|
- )
|
|
|
|
|
- flexmock(module).should_receive('make_snapshot_path').with_args('/mnt/subvol2').and_return(
|
|
|
|
|
- '/mnt/subvol2/.borgmatic-1234/mnt/subvol2',
|
|
|
|
|
- )
|
|
|
|
|
- flexmock(module).should_receive('snapshot_subvolume').with_args(
|
|
|
|
|
- 'btrfs',
|
|
|
|
|
- '/mnt/subvol1',
|
|
|
|
|
- '/mnt/subvol1/.borgmatic-1234/mnt/subvol1',
|
|
|
|
|
- ).once()
|
|
|
|
|
- flexmock(module).should_receive('snapshot_subvolume').with_args(
|
|
|
|
|
- 'btrfs',
|
|
|
|
|
- '/mnt/subvol2',
|
|
|
|
|
- '/mnt/subvol2/.borgmatic-1234/mnt/subvol2',
|
|
|
|
|
- ).once()
|
|
|
|
|
- flexmock(module).should_receive('make_snapshot_exclude_pattern').with_args(
|
|
|
|
|
- '/mnt/subvol1',
|
|
|
|
|
- ).and_return(
|
|
|
|
|
- Pattern(
|
|
|
|
|
- '/mnt/subvol1/.borgmatic-1234/mnt/subvol1/.borgmatic-1234',
|
|
|
|
|
- Pattern_type.NO_RECURSE,
|
|
|
|
|
- Pattern_style.FNMATCH,
|
|
|
|
|
- ),
|
|
|
|
|
- )
|
|
|
|
|
- flexmock(module).should_receive('make_snapshot_exclude_pattern').with_args(
|
|
|
|
|
- '/mnt/subvol2',
|
|
|
|
|
- ).and_return(
|
|
|
|
|
- Pattern(
|
|
|
|
|
- '/mnt/subvol2/.borgmatic-1234/mnt/subvol2/.borgmatic-1234',
|
|
|
|
|
- Pattern_type.NO_RECURSE,
|
|
|
|
|
- Pattern_style.FNMATCH,
|
|
|
|
|
- ),
|
|
|
|
|
- )
|
|
|
|
|
- flexmock(module).should_receive('make_borg_snapshot_pattern').with_args(
|
|
|
|
|
- '/mnt/subvol1',
|
|
|
|
|
- object,
|
|
|
|
|
- ).and_return(Pattern('/mnt/subvol1/.borgmatic-1234/mnt/subvol1'))
|
|
|
|
|
- flexmock(module).should_receive('make_borg_snapshot_pattern').with_args(
|
|
|
|
|
- '/mnt/subvol2',
|
|
|
|
|
- object,
|
|
|
|
|
- ).and_return(Pattern('/mnt/subvol2/.borgmatic-1234/mnt/subvol2'))
|
|
|
|
|
-
|
|
|
|
|
- assert (
|
|
|
|
|
- module.dump_data_sources(
|
|
|
|
|
- hook_config=config['btrfs'],
|
|
|
|
|
- config=config,
|
|
|
|
|
- config_paths=('test.yaml',),
|
|
|
|
|
- borgmatic_runtime_directory='/run/borgmatic',
|
|
|
|
|
- patterns=patterns,
|
|
|
|
|
- dry_run=False,
|
|
|
|
|
- )
|
|
|
|
|
- == []
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
- assert patterns == [
|
|
|
|
|
- Pattern('/foo'),
|
|
|
|
|
- Pattern('/mnt/subvol1/.borgmatic-1234/mnt/subvol1'),
|
|
|
|
|
- Pattern(
|
|
|
|
|
- '/mnt/subvol1/.borgmatic-1234/mnt/subvol1/.borgmatic-1234',
|
|
|
|
|
- Pattern_type.NO_RECURSE,
|
|
|
|
|
- Pattern_style.FNMATCH,
|
|
|
|
|
- ),
|
|
|
|
|
- Pattern('/mnt/subvol2/.borgmatic-1234/mnt/subvol2'),
|
|
|
|
|
- Pattern(
|
|
|
|
|
- '/mnt/subvol2/.borgmatic-1234/mnt/subvol2/.borgmatic-1234',
|
|
|
|
|
- Pattern_type.NO_RECURSE,
|
|
|
|
|
- Pattern_style.FNMATCH,
|
|
|
|
|
- ),
|
|
|
|
|
- ]
|
|
|
|
|
- assert config == {
|
|
|
|
|
- 'btrfs': {},
|
|
|
|
|
- 'exclude_patterns': ['/bar'],
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
def test_remove_data_source_dumps_deletes_snapshots():
|
|
def test_remove_data_source_dumps_deletes_snapshots():
|
|
|
config = {'btrfs': {}}
|
|
config = {'btrfs': {}}
|
|
|
flexmock(module).should_receive('get_subvolumes').and_return(
|
|
flexmock(module).should_receive('get_subvolumes').and_return(
|
|
@@ -745,84 +693,90 @@ def test_remove_data_source_dumps_deletes_snapshots():
|
|
|
),
|
|
),
|
|
|
)
|
|
)
|
|
|
flexmock(module).should_receive('make_snapshot_path').with_args('/mnt/subvol1').and_return(
|
|
flexmock(module).should_receive('make_snapshot_path').with_args('/mnt/subvol1').and_return(
|
|
|
- '/mnt/subvol1/.borgmatic-1234/./mnt/subvol1',
|
|
|
|
|
|
|
+ '/mnt/subvol1/.borgmatic-snapshot-1234/./mnt/subvol1',
|
|
|
)
|
|
)
|
|
|
flexmock(module).should_receive('make_snapshot_path').with_args('/mnt/subvol2').and_return(
|
|
flexmock(module).should_receive('make_snapshot_path').with_args('/mnt/subvol2').and_return(
|
|
|
- '/mnt/subvol2/.borgmatic-1234/./mnt/subvol2',
|
|
|
|
|
|
|
+ '/mnt/subvol2/.borgmatic-snapshot-1234/./mnt/subvol2',
|
|
|
)
|
|
)
|
|
|
flexmock(module.borgmatic.config.paths).should_receive(
|
|
flexmock(module.borgmatic.config.paths).should_receive(
|
|
|
'replace_temporary_subdirectory_with_glob',
|
|
'replace_temporary_subdirectory_with_glob',
|
|
|
).with_args(
|
|
).with_args(
|
|
|
- '/mnt/subvol1/.borgmatic-1234/mnt/subvol1',
|
|
|
|
|
|
|
+ '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1',
|
|
|
temporary_directory_prefix=module.BORGMATIC_SNAPSHOT_PREFIX,
|
|
temporary_directory_prefix=module.BORGMATIC_SNAPSHOT_PREFIX,
|
|
|
).and_return('/mnt/subvol1/.borgmatic-*/mnt/subvol1')
|
|
).and_return('/mnt/subvol1/.borgmatic-*/mnt/subvol1')
|
|
|
flexmock(module.borgmatic.config.paths).should_receive(
|
|
flexmock(module.borgmatic.config.paths).should_receive(
|
|
|
'replace_temporary_subdirectory_with_glob',
|
|
'replace_temporary_subdirectory_with_glob',
|
|
|
).with_args(
|
|
).with_args(
|
|
|
- '/mnt/subvol2/.borgmatic-1234/mnt/subvol2',
|
|
|
|
|
|
|
+ '/mnt/subvol2/.borgmatic-snapshot-1234/mnt/subvol2',
|
|
|
temporary_directory_prefix=module.BORGMATIC_SNAPSHOT_PREFIX,
|
|
temporary_directory_prefix=module.BORGMATIC_SNAPSHOT_PREFIX,
|
|
|
).and_return('/mnt/subvol2/.borgmatic-*/mnt/subvol2')
|
|
).and_return('/mnt/subvol2/.borgmatic-*/mnt/subvol2')
|
|
|
flexmock(module.glob).should_receive('glob').with_args(
|
|
flexmock(module.glob).should_receive('glob').with_args(
|
|
|
'/mnt/subvol1/.borgmatic-*/mnt/subvol1',
|
|
'/mnt/subvol1/.borgmatic-*/mnt/subvol1',
|
|
|
).and_return(
|
|
).and_return(
|
|
|
- ('/mnt/subvol1/.borgmatic-1234/mnt/subvol1', '/mnt/subvol1/.borgmatic-5678/mnt/subvol1'),
|
|
|
|
|
|
|
+ (
|
|
|
|
|
+ '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1',
|
|
|
|
|
+ '/mnt/subvol1/.borgmatic-snapshot-5678/mnt/subvol1',
|
|
|
|
|
+ ),
|
|
|
)
|
|
)
|
|
|
flexmock(module.glob).should_receive('glob').with_args(
|
|
flexmock(module.glob).should_receive('glob').with_args(
|
|
|
'/mnt/subvol2/.borgmatic-*/mnt/subvol2',
|
|
'/mnt/subvol2/.borgmatic-*/mnt/subvol2',
|
|
|
).and_return(
|
|
).and_return(
|
|
|
- ('/mnt/subvol2/.borgmatic-1234/mnt/subvol2', '/mnt/subvol2/.borgmatic-5678/mnt/subvol2'),
|
|
|
|
|
|
|
+ (
|
|
|
|
|
+ '/mnt/subvol2/.borgmatic-snapshot-1234/mnt/subvol2',
|
|
|
|
|
+ '/mnt/subvol2/.borgmatic-snapshot-5678/mnt/subvol2',
|
|
|
|
|
+ ),
|
|
|
)
|
|
)
|
|
|
flexmock(module.os.path).should_receive('isdir').with_args(
|
|
flexmock(module.os.path).should_receive('isdir').with_args(
|
|
|
- '/mnt/subvol1/.borgmatic-1234/mnt/subvol1',
|
|
|
|
|
|
|
+ '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1',
|
|
|
).and_return(True)
|
|
).and_return(True)
|
|
|
flexmock(module.os.path).should_receive('isdir').with_args(
|
|
flexmock(module.os.path).should_receive('isdir').with_args(
|
|
|
- '/mnt/subvol1/.borgmatic-5678/mnt/subvol1',
|
|
|
|
|
|
|
+ '/mnt/subvol1/.borgmatic-snapshot-5678/mnt/subvol1',
|
|
|
).and_return(True)
|
|
).and_return(True)
|
|
|
flexmock(module.os.path).should_receive('isdir').with_args(
|
|
flexmock(module.os.path).should_receive('isdir').with_args(
|
|
|
- '/mnt/subvol2/.borgmatic-1234/mnt/subvol2',
|
|
|
|
|
|
|
+ '/mnt/subvol2/.borgmatic-snapshot-1234/mnt/subvol2',
|
|
|
).and_return(True)
|
|
).and_return(True)
|
|
|
flexmock(module.os.path).should_receive('isdir').with_args(
|
|
flexmock(module.os.path).should_receive('isdir').with_args(
|
|
|
- '/mnt/subvol2/.borgmatic-5678/mnt/subvol2',
|
|
|
|
|
|
|
+ '/mnt/subvol2/.borgmatic-snapshot-5678/mnt/subvol2',
|
|
|
).and_return(False)
|
|
).and_return(False)
|
|
|
flexmock(module).should_receive('delete_snapshot').with_args(
|
|
flexmock(module).should_receive('delete_snapshot').with_args(
|
|
|
'btrfs',
|
|
'btrfs',
|
|
|
- '/mnt/subvol1/.borgmatic-1234/mnt/subvol1',
|
|
|
|
|
|
|
+ '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1',
|
|
|
).once()
|
|
).once()
|
|
|
flexmock(module).should_receive('delete_snapshot').with_args(
|
|
flexmock(module).should_receive('delete_snapshot').with_args(
|
|
|
'btrfs',
|
|
'btrfs',
|
|
|
- '/mnt/subvol1/.borgmatic-5678/mnt/subvol1',
|
|
|
|
|
|
|
+ '/mnt/subvol1/.borgmatic-snapshot-5678/mnt/subvol1',
|
|
|
).once()
|
|
).once()
|
|
|
flexmock(module).should_receive('delete_snapshot').with_args(
|
|
flexmock(module).should_receive('delete_snapshot').with_args(
|
|
|
'btrfs',
|
|
'btrfs',
|
|
|
- '/mnt/subvol2/.borgmatic-1234/mnt/subvol2',
|
|
|
|
|
|
|
+ '/mnt/subvol2/.borgmatic-snapshot-1234/mnt/subvol2',
|
|
|
).once()
|
|
).once()
|
|
|
flexmock(module).should_receive('delete_snapshot').with_args(
|
|
flexmock(module).should_receive('delete_snapshot').with_args(
|
|
|
'btrfs',
|
|
'btrfs',
|
|
|
- '/mnt/subvol2/.borgmatic-5678/mnt/subvol2',
|
|
|
|
|
|
|
+ '/mnt/subvol2/.borgmatic-snapshot-5678/mnt/subvol2',
|
|
|
).never()
|
|
).never()
|
|
|
flexmock(module.os.path).should_receive('isdir').with_args(
|
|
flexmock(module.os.path).should_receive('isdir').with_args(
|
|
|
- '/mnt/subvol1/.borgmatic-1234',
|
|
|
|
|
|
|
+ '/mnt/subvol1/.borgmatic-snapshot-1234',
|
|
|
).and_return(True)
|
|
).and_return(True)
|
|
|
flexmock(module.os.path).should_receive('isdir').with_args(
|
|
flexmock(module.os.path).should_receive('isdir').with_args(
|
|
|
- '/mnt/subvol1/.borgmatic-5678',
|
|
|
|
|
|
|
+ '/mnt/subvol1/.borgmatic-snapshot-5678',
|
|
|
).and_return(True)
|
|
).and_return(True)
|
|
|
flexmock(module.os.path).should_receive('isdir').with_args(
|
|
flexmock(module.os.path).should_receive('isdir').with_args(
|
|
|
- '/mnt/subvol2/.borgmatic-1234',
|
|
|
|
|
|
|
+ '/mnt/subvol2/.borgmatic-snapshot-1234',
|
|
|
).and_return(True)
|
|
).and_return(True)
|
|
|
flexmock(module.os.path).should_receive('isdir').with_args(
|
|
flexmock(module.os.path).should_receive('isdir').with_args(
|
|
|
- '/mnt/subvol2/.borgmatic-5678',
|
|
|
|
|
|
|
+ '/mnt/subvol2/.borgmatic-snapshot-5678',
|
|
|
).and_return(True)
|
|
).and_return(True)
|
|
|
flexmock(module.shutil).should_receive('rmtree').with_args(
|
|
flexmock(module.shutil).should_receive('rmtree').with_args(
|
|
|
- '/mnt/subvol1/.borgmatic-1234',
|
|
|
|
|
|
|
+ '/mnt/subvol1/.borgmatic-snapshot-1234',
|
|
|
).once()
|
|
).once()
|
|
|
flexmock(module.shutil).should_receive('rmtree').with_args(
|
|
flexmock(module.shutil).should_receive('rmtree').with_args(
|
|
|
- '/mnt/subvol1/.borgmatic-5678',
|
|
|
|
|
|
|
+ '/mnt/subvol1/.borgmatic-snapshot-5678',
|
|
|
).once()
|
|
).once()
|
|
|
flexmock(module.shutil).should_receive('rmtree').with_args(
|
|
flexmock(module.shutil).should_receive('rmtree').with_args(
|
|
|
- '/mnt/subvol2/.borgmatic-1234',
|
|
|
|
|
|
|
+ '/mnt/subvol2/.borgmatic-snapshot-1234',
|
|
|
).once()
|
|
).once()
|
|
|
flexmock(module.shutil).should_receive('rmtree').with_args(
|
|
flexmock(module.shutil).should_receive('rmtree').with_args(
|
|
|
- '/mnt/subvol2/.borgmatic-5678',
|
|
|
|
|
|
|
+ '/mnt/subvol2/.borgmatic-snapshot-5678',
|
|
|
).never()
|
|
).never()
|
|
|
|
|
|
|
|
module.remove_data_source_dumps(
|
|
module.remove_data_source_dumps(
|
|
@@ -901,44 +855,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(
|
|
flexmock(module).should_receive('make_snapshot_path').with_args('/mnt/subvol1').and_return(
|
|
|
- '/mnt/subvol1/.borgmatic-1234/./mnt/subvol1',
|
|
|
|
|
|
|
+ '/mnt/subvol1/.borgmatic-snapshot-1234/./mnt/subvol1',
|
|
|
)
|
|
)
|
|
|
flexmock(module).should_receive('make_snapshot_path').with_args('/mnt/subvol2').and_return(
|
|
flexmock(module).should_receive('make_snapshot_path').with_args('/mnt/subvol2').and_return(
|
|
|
- '/mnt/subvol2/.borgmatic-1234/./mnt/subvol2',
|
|
|
|
|
|
|
+ '/mnt/subvol2/.borgmatic-snapshot-1234/./mnt/subvol2',
|
|
|
)
|
|
)
|
|
|
flexmock(module.borgmatic.config.paths).should_receive(
|
|
flexmock(module.borgmatic.config.paths).should_receive(
|
|
|
'replace_temporary_subdirectory_with_glob',
|
|
'replace_temporary_subdirectory_with_glob',
|
|
|
).with_args(
|
|
).with_args(
|
|
|
- '/mnt/subvol1/.borgmatic-1234/mnt/subvol1',
|
|
|
|
|
|
|
+ '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1',
|
|
|
temporary_directory_prefix=module.BORGMATIC_SNAPSHOT_PREFIX,
|
|
temporary_directory_prefix=module.BORGMATIC_SNAPSHOT_PREFIX,
|
|
|
).and_return('/mnt/subvol1/.borgmatic-*/mnt/subvol1')
|
|
).and_return('/mnt/subvol1/.borgmatic-*/mnt/subvol1')
|
|
|
flexmock(module.borgmatic.config.paths).should_receive(
|
|
flexmock(module.borgmatic.config.paths).should_receive(
|
|
|
'replace_temporary_subdirectory_with_glob',
|
|
'replace_temporary_subdirectory_with_glob',
|
|
|
).with_args(
|
|
).with_args(
|
|
|
- '/mnt/subvol2/.borgmatic-1234/mnt/subvol2',
|
|
|
|
|
|
|
+ '/mnt/subvol2/.borgmatic-snapshot-1234/mnt/subvol2',
|
|
|
temporary_directory_prefix=module.BORGMATIC_SNAPSHOT_PREFIX,
|
|
temporary_directory_prefix=module.BORGMATIC_SNAPSHOT_PREFIX,
|
|
|
).and_return('/mnt/subvol2/.borgmatic-*/mnt/subvol2')
|
|
).and_return('/mnt/subvol2/.borgmatic-*/mnt/subvol2')
|
|
|
flexmock(module.glob).should_receive('glob').with_args(
|
|
flexmock(module.glob).should_receive('glob').with_args(
|
|
|
'/mnt/subvol1/.borgmatic-*/mnt/subvol1',
|
|
'/mnt/subvol1/.borgmatic-*/mnt/subvol1',
|
|
|
).and_return(
|
|
).and_return(
|
|
|
- ('/mnt/subvol1/.borgmatic-1234/mnt/subvol1', '/mnt/subvol1/.borgmatic-5678/mnt/subvol1'),
|
|
|
|
|
|
|
+ (
|
|
|
|
|
+ '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1',
|
|
|
|
|
+ '/mnt/subvol1/.borgmatic-snapshot-5678/mnt/subvol1',
|
|
|
|
|
+ ),
|
|
|
)
|
|
)
|
|
|
flexmock(module.glob).should_receive('glob').with_args(
|
|
flexmock(module.glob).should_receive('glob').with_args(
|
|
|
'/mnt/subvol2/.borgmatic-*/mnt/subvol2',
|
|
'/mnt/subvol2/.borgmatic-*/mnt/subvol2',
|
|
|
).and_return(
|
|
).and_return(
|
|
|
- ('/mnt/subvol2/.borgmatic-1234/mnt/subvol2', '/mnt/subvol2/.borgmatic-5678/mnt/subvol2'),
|
|
|
|
|
|
|
+ (
|
|
|
|
|
+ '/mnt/subvol2/.borgmatic-snapshot-1234/mnt/subvol2',
|
|
|
|
|
+ '/mnt/subvol2/.borgmatic-snapshot-5678/mnt/subvol2',
|
|
|
|
|
+ ),
|
|
|
)
|
|
)
|
|
|
flexmock(module.os.path).should_receive('isdir').with_args(
|
|
flexmock(module.os.path).should_receive('isdir').with_args(
|
|
|
- '/mnt/subvol1/.borgmatic-1234/mnt/subvol1',
|
|
|
|
|
|
|
+ '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1',
|
|
|
).and_return(True)
|
|
).and_return(True)
|
|
|
flexmock(module.os.path).should_receive('isdir').with_args(
|
|
flexmock(module.os.path).should_receive('isdir').with_args(
|
|
|
- '/mnt/subvol1/.borgmatic-5678/mnt/subvol1',
|
|
|
|
|
|
|
+ '/mnt/subvol1/.borgmatic-snapshot-5678/mnt/subvol1',
|
|
|
).and_return(True)
|
|
).and_return(True)
|
|
|
flexmock(module.os.path).should_receive('isdir').with_args(
|
|
flexmock(module.os.path).should_receive('isdir').with_args(
|
|
|
- '/mnt/subvol2/.borgmatic-1234/mnt/subvol2',
|
|
|
|
|
|
|
+ '/mnt/subvol2/.borgmatic-snapshot-1234/mnt/subvol2',
|
|
|
).and_return(True)
|
|
).and_return(True)
|
|
|
flexmock(module.os.path).should_receive('isdir').with_args(
|
|
flexmock(module.os.path).should_receive('isdir').with_args(
|
|
|
- '/mnt/subvol2/.borgmatic-5678/mnt/subvol2',
|
|
|
|
|
|
|
+ '/mnt/subvol2/.borgmatic-snapshot-5678/mnt/subvol2',
|
|
|
).and_return(False)
|
|
).and_return(False)
|
|
|
flexmock(module).should_receive('delete_snapshot').never()
|
|
flexmock(module).should_receive('delete_snapshot').never()
|
|
|
flexmock(module.shutil).should_receive('rmtree').never()
|
|
flexmock(module.shutil).should_receive('rmtree').never()
|
|
@@ -980,21 +940,21 @@ def test_remove_data_source_without_snapshots_skips_deletes():
|
|
|
),
|
|
),
|
|
|
)
|
|
)
|
|
|
flexmock(module).should_receive('make_snapshot_path').with_args('/mnt/subvol1').and_return(
|
|
flexmock(module).should_receive('make_snapshot_path').with_args('/mnt/subvol1').and_return(
|
|
|
- '/mnt/subvol1/.borgmatic-1234/./mnt/subvol1',
|
|
|
|
|
|
|
+ '/mnt/subvol1/.borgmatic-snapshot-1234/./mnt/subvol1',
|
|
|
)
|
|
)
|
|
|
flexmock(module).should_receive('make_snapshot_path').with_args('/mnt/subvol2').and_return(
|
|
flexmock(module).should_receive('make_snapshot_path').with_args('/mnt/subvol2').and_return(
|
|
|
- '/mnt/subvol2/.borgmatic-1234/./mnt/subvol2',
|
|
|
|
|
|
|
+ '/mnt/subvol2/.borgmatic-snapshot-1234/./mnt/subvol2',
|
|
|
)
|
|
)
|
|
|
flexmock(module.borgmatic.config.paths).should_receive(
|
|
flexmock(module.borgmatic.config.paths).should_receive(
|
|
|
'replace_temporary_subdirectory_with_glob',
|
|
'replace_temporary_subdirectory_with_glob',
|
|
|
).with_args(
|
|
).with_args(
|
|
|
- '/mnt/subvol1/.borgmatic-1234/mnt/subvol1',
|
|
|
|
|
|
|
+ '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1',
|
|
|
temporary_directory_prefix=module.BORGMATIC_SNAPSHOT_PREFIX,
|
|
temporary_directory_prefix=module.BORGMATIC_SNAPSHOT_PREFIX,
|
|
|
).and_return('/mnt/subvol1/.borgmatic-*/mnt/subvol1')
|
|
).and_return('/mnt/subvol1/.borgmatic-*/mnt/subvol1')
|
|
|
flexmock(module.borgmatic.config.paths).should_receive(
|
|
flexmock(module.borgmatic.config.paths).should_receive(
|
|
|
'replace_temporary_subdirectory_with_glob',
|
|
'replace_temporary_subdirectory_with_glob',
|
|
|
).with_args(
|
|
).with_args(
|
|
|
- '/mnt/subvol2/.borgmatic-1234/mnt/subvol2',
|
|
|
|
|
|
|
+ '/mnt/subvol2/.borgmatic-snapshot-1234/mnt/subvol2',
|
|
|
temporary_directory_prefix=module.BORGMATIC_SNAPSHOT_PREFIX,
|
|
temporary_directory_prefix=module.BORGMATIC_SNAPSHOT_PREFIX,
|
|
|
).and_return('/mnt/subvol2/.borgmatic-*/mnt/subvol2')
|
|
).and_return('/mnt/subvol2/.borgmatic-*/mnt/subvol2')
|
|
|
flexmock(module.glob).should_receive('glob').and_return(())
|
|
flexmock(module.glob).should_receive('glob').and_return(())
|
|
@@ -1020,44 +980,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(
|
|
flexmock(module).should_receive('make_snapshot_path').with_args('/mnt/subvol1').and_return(
|
|
|
- '/mnt/subvol1/.borgmatic-1234/./mnt/subvol1',
|
|
|
|
|
|
|
+ '/mnt/subvol1/.borgmatic-snapshot-1234/./mnt/subvol1',
|
|
|
)
|
|
)
|
|
|
flexmock(module).should_receive('make_snapshot_path').with_args('/mnt/subvol2').and_return(
|
|
flexmock(module).should_receive('make_snapshot_path').with_args('/mnt/subvol2').and_return(
|
|
|
- '/mnt/subvol2/.borgmatic-1234/./mnt/subvol2',
|
|
|
|
|
|
|
+ '/mnt/subvol2/.borgmatic-snapshot-1234/./mnt/subvol2',
|
|
|
)
|
|
)
|
|
|
flexmock(module.borgmatic.config.paths).should_receive(
|
|
flexmock(module.borgmatic.config.paths).should_receive(
|
|
|
'replace_temporary_subdirectory_with_glob',
|
|
'replace_temporary_subdirectory_with_glob',
|
|
|
).with_args(
|
|
).with_args(
|
|
|
- '/mnt/subvol1/.borgmatic-1234/mnt/subvol1',
|
|
|
|
|
|
|
+ '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1',
|
|
|
temporary_directory_prefix=module.BORGMATIC_SNAPSHOT_PREFIX,
|
|
temporary_directory_prefix=module.BORGMATIC_SNAPSHOT_PREFIX,
|
|
|
).and_return('/mnt/subvol1/.borgmatic-*/mnt/subvol1')
|
|
).and_return('/mnt/subvol1/.borgmatic-*/mnt/subvol1')
|
|
|
flexmock(module.borgmatic.config.paths).should_receive(
|
|
flexmock(module.borgmatic.config.paths).should_receive(
|
|
|
'replace_temporary_subdirectory_with_glob',
|
|
'replace_temporary_subdirectory_with_glob',
|
|
|
).with_args(
|
|
).with_args(
|
|
|
- '/mnt/subvol2/.borgmatic-1234/mnt/subvol2',
|
|
|
|
|
|
|
+ '/mnt/subvol2/.borgmatic-snapshot-1234/mnt/subvol2',
|
|
|
temporary_directory_prefix=module.BORGMATIC_SNAPSHOT_PREFIX,
|
|
temporary_directory_prefix=module.BORGMATIC_SNAPSHOT_PREFIX,
|
|
|
).and_return('/mnt/subvol2/.borgmatic-*/mnt/subvol2')
|
|
).and_return('/mnt/subvol2/.borgmatic-*/mnt/subvol2')
|
|
|
flexmock(module.glob).should_receive('glob').with_args(
|
|
flexmock(module.glob).should_receive('glob').with_args(
|
|
|
'/mnt/subvol1/.borgmatic-*/mnt/subvol1',
|
|
'/mnt/subvol1/.borgmatic-*/mnt/subvol1',
|
|
|
).and_return(
|
|
).and_return(
|
|
|
- ('/mnt/subvol1/.borgmatic-1234/mnt/subvol1', '/mnt/subvol1/.borgmatic-5678/mnt/subvol1'),
|
|
|
|
|
|
|
+ (
|
|
|
|
|
+ '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1',
|
|
|
|
|
+ '/mnt/subvol1/.borgmatic-snapshot-5678/mnt/subvol1',
|
|
|
|
|
+ ),
|
|
|
)
|
|
)
|
|
|
flexmock(module.glob).should_receive('glob').with_args(
|
|
flexmock(module.glob).should_receive('glob').with_args(
|
|
|
'/mnt/subvol2/.borgmatic-*/mnt/subvol2',
|
|
'/mnt/subvol2/.borgmatic-*/mnt/subvol2',
|
|
|
).and_return(
|
|
).and_return(
|
|
|
- ('/mnt/subvol2/.borgmatic-1234/mnt/subvol2', '/mnt/subvol2/.borgmatic-5678/mnt/subvol2'),
|
|
|
|
|
|
|
+ (
|
|
|
|
|
+ '/mnt/subvol2/.borgmatic-snapshot-1234/mnt/subvol2',
|
|
|
|
|
+ '/mnt/subvol2/.borgmatic-snapshot-5678/mnt/subvol2',
|
|
|
|
|
+ ),
|
|
|
)
|
|
)
|
|
|
flexmock(module.os.path).should_receive('isdir').with_args(
|
|
flexmock(module.os.path).should_receive('isdir').with_args(
|
|
|
- '/mnt/subvol1/.borgmatic-1234/mnt/subvol1',
|
|
|
|
|
|
|
+ '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1',
|
|
|
).and_return(True)
|
|
).and_return(True)
|
|
|
flexmock(module.os.path).should_receive('isdir').with_args(
|
|
flexmock(module.os.path).should_receive('isdir').with_args(
|
|
|
- '/mnt/subvol1/.borgmatic-5678/mnt/subvol1',
|
|
|
|
|
|
|
+ '/mnt/subvol1/.borgmatic-snapshot-5678/mnt/subvol1',
|
|
|
).and_return(True)
|
|
).and_return(True)
|
|
|
flexmock(module.os.path).should_receive('isdir').with_args(
|
|
flexmock(module.os.path).should_receive('isdir').with_args(
|
|
|
- '/mnt/subvol2/.borgmatic-1234/mnt/subvol2',
|
|
|
|
|
|
|
+ '/mnt/subvol2/.borgmatic-snapshot-1234/mnt/subvol2',
|
|
|
).and_return(True)
|
|
).and_return(True)
|
|
|
flexmock(module.os.path).should_receive('isdir').with_args(
|
|
flexmock(module.os.path).should_receive('isdir').with_args(
|
|
|
- '/mnt/subvol2/.borgmatic-5678/mnt/subvol2',
|
|
|
|
|
|
|
+ '/mnt/subvol2/.borgmatic-snapshot-5678/mnt/subvol2',
|
|
|
).and_return(False)
|
|
).and_return(False)
|
|
|
flexmock(module).should_receive('delete_snapshot').and_raise(FileNotFoundError)
|
|
flexmock(module).should_receive('delete_snapshot').and_raise(FileNotFoundError)
|
|
|
flexmock(module.shutil).should_receive('rmtree').never()
|
|
flexmock(module.shutil).should_receive('rmtree').never()
|
|
@@ -1080,44 +1046,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(
|
|
flexmock(module).should_receive('make_snapshot_path').with_args('/mnt/subvol1').and_return(
|
|
|
- '/mnt/subvol1/.borgmatic-1234/./mnt/subvol1',
|
|
|
|
|
|
|
+ '/mnt/subvol1/.borgmatic-snapshot-1234/./mnt/subvol1',
|
|
|
)
|
|
)
|
|
|
flexmock(module).should_receive('make_snapshot_path').with_args('/mnt/subvol2').and_return(
|
|
flexmock(module).should_receive('make_snapshot_path').with_args('/mnt/subvol2').and_return(
|
|
|
- '/mnt/subvol2/.borgmatic-1234/./mnt/subvol2',
|
|
|
|
|
|
|
+ '/mnt/subvol2/.borgmatic-snapshot-1234/./mnt/subvol2',
|
|
|
)
|
|
)
|
|
|
flexmock(module.borgmatic.config.paths).should_receive(
|
|
flexmock(module.borgmatic.config.paths).should_receive(
|
|
|
'replace_temporary_subdirectory_with_glob',
|
|
'replace_temporary_subdirectory_with_glob',
|
|
|
).with_args(
|
|
).with_args(
|
|
|
- '/mnt/subvol1/.borgmatic-1234/mnt/subvol1',
|
|
|
|
|
|
|
+ '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1',
|
|
|
temporary_directory_prefix=module.BORGMATIC_SNAPSHOT_PREFIX,
|
|
temporary_directory_prefix=module.BORGMATIC_SNAPSHOT_PREFIX,
|
|
|
).and_return('/mnt/subvol1/.borgmatic-*/mnt/subvol1')
|
|
).and_return('/mnt/subvol1/.borgmatic-*/mnt/subvol1')
|
|
|
flexmock(module.borgmatic.config.paths).should_receive(
|
|
flexmock(module.borgmatic.config.paths).should_receive(
|
|
|
'replace_temporary_subdirectory_with_glob',
|
|
'replace_temporary_subdirectory_with_glob',
|
|
|
).with_args(
|
|
).with_args(
|
|
|
- '/mnt/subvol2/.borgmatic-1234/mnt/subvol2',
|
|
|
|
|
|
|
+ '/mnt/subvol2/.borgmatic-snapshot-1234/mnt/subvol2',
|
|
|
temporary_directory_prefix=module.BORGMATIC_SNAPSHOT_PREFIX,
|
|
temporary_directory_prefix=module.BORGMATIC_SNAPSHOT_PREFIX,
|
|
|
).and_return('/mnt/subvol2/.borgmatic-*/mnt/subvol2')
|
|
).and_return('/mnt/subvol2/.borgmatic-*/mnt/subvol2')
|
|
|
flexmock(module.glob).should_receive('glob').with_args(
|
|
flexmock(module.glob).should_receive('glob').with_args(
|
|
|
'/mnt/subvol1/.borgmatic-*/mnt/subvol1',
|
|
'/mnt/subvol1/.borgmatic-*/mnt/subvol1',
|
|
|
).and_return(
|
|
).and_return(
|
|
|
- ('/mnt/subvol1/.borgmatic-1234/mnt/subvol1', '/mnt/subvol1/.borgmatic-5678/mnt/subvol1'),
|
|
|
|
|
|
|
+ (
|
|
|
|
|
+ '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1',
|
|
|
|
|
+ '/mnt/subvol1/.borgmatic-snapshot-5678/mnt/subvol1',
|
|
|
|
|
+ ),
|
|
|
)
|
|
)
|
|
|
flexmock(module.glob).should_receive('glob').with_args(
|
|
flexmock(module.glob).should_receive('glob').with_args(
|
|
|
'/mnt/subvol2/.borgmatic-*/mnt/subvol2',
|
|
'/mnt/subvol2/.borgmatic-*/mnt/subvol2',
|
|
|
).and_return(
|
|
).and_return(
|
|
|
- ('/mnt/subvol2/.borgmatic-1234/mnt/subvol2', '/mnt/subvol2/.borgmatic-5678/mnt/subvol2'),
|
|
|
|
|
|
|
+ (
|
|
|
|
|
+ '/mnt/subvol2/.borgmatic-snapshot-1234/mnt/subvol2',
|
|
|
|
|
+ '/mnt/subvol2/.borgmatic-snapshot-5678/mnt/subvol2',
|
|
|
|
|
+ ),
|
|
|
)
|
|
)
|
|
|
flexmock(module.os.path).should_receive('isdir').with_args(
|
|
flexmock(module.os.path).should_receive('isdir').with_args(
|
|
|
- '/mnt/subvol1/.borgmatic-1234/mnt/subvol1',
|
|
|
|
|
|
|
+ '/mnt/subvol1/.borgmatic-snapshot-1234/mnt/subvol1',
|
|
|
).and_return(True)
|
|
).and_return(True)
|
|
|
flexmock(module.os.path).should_receive('isdir').with_args(
|
|
flexmock(module.os.path).should_receive('isdir').with_args(
|
|
|
- '/mnt/subvol1/.borgmatic-5678/mnt/subvol1',
|
|
|
|
|
|
|
+ '/mnt/subvol1/.borgmatic-snapshot-5678/mnt/subvol1',
|
|
|
).and_return(True)
|
|
).and_return(True)
|
|
|
flexmock(module.os.path).should_receive('isdir').with_args(
|
|
flexmock(module.os.path).should_receive('isdir').with_args(
|
|
|
- '/mnt/subvol2/.borgmatic-1234/mnt/subvol2',
|
|
|
|
|
|
|
+ '/mnt/subvol2/.borgmatic-snapshot-1234/mnt/subvol2',
|
|
|
).and_return(True)
|
|
).and_return(True)
|
|
|
flexmock(module.os.path).should_receive('isdir').with_args(
|
|
flexmock(module.os.path).should_receive('isdir').with_args(
|
|
|
- '/mnt/subvol2/.borgmatic-5678/mnt/subvol2',
|
|
|
|
|
|
|
+ '/mnt/subvol2/.borgmatic-snapshot-5678/mnt/subvol2',
|
|
|
).and_return(False)
|
|
).and_return(False)
|
|
|
flexmock(module).should_receive('delete_snapshot').and_raise(
|
|
flexmock(module).should_receive('delete_snapshot').and_raise(
|
|
|
module.subprocess.CalledProcessError(1, 'command', 'error'),
|
|
module.subprocess.CalledProcessError(1, 'command', 'error'),
|
|
@@ -1140,29 +1112,37 @@ def test_remove_data_source_dumps_with_root_subvolume_skips_duplicate_removal():
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
flexmock(module).should_receive('make_snapshot_path').with_args('/').and_return(
|
|
flexmock(module).should_receive('make_snapshot_path').with_args('/').and_return(
|
|
|
- '/.borgmatic-1234',
|
|
|
|
|
|
|
+ '/.borgmatic-snapshot-1234',
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
flexmock(module.borgmatic.config.paths).should_receive(
|
|
flexmock(module.borgmatic.config.paths).should_receive(
|
|
|
'replace_temporary_subdirectory_with_glob',
|
|
'replace_temporary_subdirectory_with_glob',
|
|
|
).with_args(
|
|
).with_args(
|
|
|
- '/.borgmatic-1234',
|
|
|
|
|
|
|
+ '/.borgmatic-snapshot-1234',
|
|
|
temporary_directory_prefix=module.BORGMATIC_SNAPSHOT_PREFIX,
|
|
temporary_directory_prefix=module.BORGMATIC_SNAPSHOT_PREFIX,
|
|
|
).and_return('/.borgmatic-*')
|
|
).and_return('/.borgmatic-*')
|
|
|
|
|
|
|
|
flexmock(module.glob).should_receive('glob').with_args('/.borgmatic-*').and_return(
|
|
flexmock(module.glob).should_receive('glob').with_args('/.borgmatic-*').and_return(
|
|
|
- ('/.borgmatic-1234', '/.borgmatic-5678'),
|
|
|
|
|
|
|
+ ('/.borgmatic-snapshot-1234', '/.borgmatic-snapshot-5678'),
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
- flexmock(module.os.path).should_receive('isdir').with_args('/.borgmatic-1234').and_return(
|
|
|
|
|
|
|
+ flexmock(module.os.path).should_receive('isdir').with_args(
|
|
|
|
|
+ '/.borgmatic-snapshot-1234'
|
|
|
|
|
+ ).and_return(
|
|
|
True,
|
|
True,
|
|
|
).and_return(False)
|
|
).and_return(False)
|
|
|
- flexmock(module.os.path).should_receive('isdir').with_args('/.borgmatic-5678').and_return(
|
|
|
|
|
|
|
+ flexmock(module.os.path).should_receive('isdir').with_args(
|
|
|
|
|
+ '/.borgmatic-snapshot-5678'
|
|
|
|
|
+ ).and_return(
|
|
|
True,
|
|
True,
|
|
|
).and_return(False)
|
|
).and_return(False)
|
|
|
|
|
|
|
|
- flexmock(module).should_receive('delete_snapshot').with_args('btrfs', '/.borgmatic-1234').once()
|
|
|
|
|
- flexmock(module).should_receive('delete_snapshot').with_args('btrfs', '/.borgmatic-5678').once()
|
|
|
|
|
|
|
+ flexmock(module).should_receive('delete_snapshot').with_args(
|
|
|
|
|
+ 'btrfs', '/.borgmatic-snapshot-1234'
|
|
|
|
|
+ ).once()
|
|
|
|
|
+ flexmock(module).should_receive('delete_snapshot').with_args(
|
|
|
|
|
+ 'btrfs', '/.borgmatic-snapshot-5678'
|
|
|
|
|
+ ).once()
|
|
|
|
|
|
|
|
flexmock(module.os.path).should_receive('isdir').with_args('').and_return(False)
|
|
flexmock(module.os.path).should_receive('isdir').with_args('').and_return(False)
|
|
|
|
|
|