Fix for the database "restore" action restoring more databases than the "--database" flag specifies (#1208).

This commit is contained in:
Dan Helfman
2025-12-22 15:46:28 -08:00
parent 3c8935fd69
commit b8642439cd
15 changed files with 118 additions and 18 deletions
+4
View File
@@ -1,3 +1,7 @@
2.0.14.dev0
* #1208: Fix for the database "restore" action restoring more databases than the "--database" flag
specifies.
2.0.13
* #1054: Allow the Btrfs hook to create and delete snapshots even when running
as a non-root user. See the documentation for more information:
+4
View File
@@ -200,6 +200,10 @@ def restore_single_dump(
borgmatic.hooks.dispatch.Hook_type.DATA_SOURCE,
borgmatic_runtime_directory,
data_source['name'],
data_source.get('hostname'),
data_source.get('port'),
data_source.get('container'),
data_source.get('label'),
)[hook_name.split('_databases', 1)[0]]
destination_path = (
+4
View File
@@ -116,6 +116,10 @@ def make_data_source_dump_patterns(
config,
borgmatic_runtime_directory,
name=None,
hostname=None,
port=None,
container=None,
label=None,
): # pragma: no cover
'''
Restores are implemented via the separate, purpose-specific "bootstrap" action rather than the
+4
View File
@@ -412,6 +412,10 @@ def make_data_source_dump_patterns(
config,
borgmatic_runtime_directory,
name=None,
hostname=None,
port=None,
container=None,
label=None,
): # pragma: no cover
'''
Restores aren't implemented, because stored files can be extracted directly with "extract".
+1 -1
View File
@@ -124,6 +124,6 @@ def convert_glob_patterns_to_borg_pattern(patterns):
# longer than the pattern. E.g., a pattern of "borgmatic/*/foo_databases/test" should also match
# paths like "borgmatic/*/foo_databases/test/toc.dat"
return 're:' + '|'.join(
fnmatch.translate(pattern.lstrip('/')).replace('\\z', '').replace('\\Z', '')
fnmatch.translate(pattern.lstrip('/')).replace('\\z', '').replace('\\Z', '') + '$'
for pattern in patterns
)
+4
View File
@@ -452,6 +452,10 @@ def make_data_source_dump_patterns(
config,
borgmatic_runtime_directory,
name=None,
hostname=None,
port=None,
container=None,
label=None,
): # pragma: no cover
'''
Restores aren't implemented, because stored files can be extracted directly with "extract".
+15 -3
View File
@@ -410,6 +410,10 @@ def make_data_source_dump_patterns(
config,
borgmatic_runtime_directory,
name=None,
hostname=None,
port=None,
container=None,
label=None,
): # pragma: no cover
'''
Given a sequence of configurations dicts, a configuration dict, the borgmatic runtime directory,
@@ -419,16 +423,24 @@ def make_data_source_dump_patterns(
borgmatic_source_directory = borgmatic.config.paths.get_borgmatic_source_directory(config)
return (
dump.make_data_source_dump_filename(make_dump_path('borgmatic'), name, label='*'),
dump.make_data_source_dump_filename(
make_dump_path('borgmatic'), name, hostname, port, container, label
),
dump.make_data_source_dump_filename(
make_dump_path(borgmatic_runtime_directory),
name,
label='*',
hostname,
port,
container,
label,
),
dump.make_data_source_dump_filename(
make_dump_path(borgmatic_source_directory),
name,
label='*',
hostname,
port,
container,
label,
),
)
+15 -3
View File
@@ -212,6 +212,10 @@ def make_data_source_dump_patterns(
config,
borgmatic_runtime_directory,
name=None,
hostname=None,
port=None,
container=None,
label=None,
): # pragma: no cover
'''
Given a sequence of configurations dicts, a configuration dict, the borgmatic runtime directory,
@@ -221,16 +225,24 @@ def make_data_source_dump_patterns(
borgmatic_source_directory = borgmatic.config.paths.get_borgmatic_source_directory(config)
return (
dump.make_data_source_dump_filename(make_dump_path('borgmatic'), name, label='*'),
dump.make_data_source_dump_filename(
make_dump_path('borgmatic'), name, hostname, port, container, label
),
dump.make_data_source_dump_filename(
make_dump_path(borgmatic_runtime_directory),
name,
label='*',
hostname,
port,
container,
label,
),
dump.make_data_source_dump_filename(
make_dump_path(borgmatic_source_directory),
name,
label='*',
hostname,
port,
container,
label,
),
)
+15 -3
View File
@@ -341,6 +341,10 @@ def make_data_source_dump_patterns(
config,
borgmatic_runtime_directory,
name=None,
hostname=None,
port=None,
container=None,
label=None,
): # pragma: no cover
'''
Given a sequence of configurations dicts, a configuration dict, the borgmatic runtime directory,
@@ -350,16 +354,24 @@ def make_data_source_dump_patterns(
borgmatic_source_directory = borgmatic.config.paths.get_borgmatic_source_directory(config)
return (
dump.make_data_source_dump_filename(make_dump_path('borgmatic'), name, label='*'),
dump.make_data_source_dump_filename(
make_dump_path('borgmatic'), name, name, hostname, port, container, label
),
dump.make_data_source_dump_filename(
make_dump_path(borgmatic_runtime_directory),
name,
label='*',
hostname,
port,
container,
label,
),
dump.make_data_source_dump_filename(
make_dump_path(borgmatic_source_directory),
name,
label='*',
hostname,
port,
container,
label,
),
)
+15 -3
View File
@@ -302,6 +302,10 @@ def make_data_source_dump_patterns(
config,
borgmatic_runtime_directory,
name=None,
hostname=None,
port=None,
container=None,
label=None,
): # pragma: no cover
'''
Given a sequence of configurations dicts, a configuration dict, the borgmatic runtime directory,
@@ -311,16 +315,24 @@ def make_data_source_dump_patterns(
borgmatic_source_directory = borgmatic.config.paths.get_borgmatic_source_directory(config)
return (
dump.make_data_source_dump_filename(make_dump_path('borgmatic'), name, label='*'),
dump.make_data_source_dump_filename(
make_dump_path('borgmatic'), name, hostname, port, container, label
),
dump.make_data_source_dump_filename(
make_dump_path(borgmatic_runtime_directory),
name,
label='*',
hostname,
port,
container,
label,
),
dump.make_data_source_dump_filename(
make_dump_path(borgmatic_source_directory),
name,
label='*',
hostname,
port,
container,
label,
),
)
+15 -3
View File
@@ -144,6 +144,10 @@ def make_data_source_dump_patterns(
config,
borgmatic_runtime_directory,
name=None,
hostname=None,
port=None,
container=None,
label=None,
): # pragma: no cover
'''
Given a sequence of configurations dicts, a configuration dict, the borgmatic runtime directory,
@@ -153,16 +157,24 @@ def make_data_source_dump_patterns(
borgmatic_source_directory = borgmatic.config.paths.get_borgmatic_source_directory(config)
return (
dump.make_data_source_dump_filename(make_dump_path('borgmatic'), name, label='*'),
dump.make_data_source_dump_filename(
make_dump_path('borgmatic'), name, hostname, port, container, label
),
dump.make_data_source_dump_filename(
make_dump_path(borgmatic_runtime_directory),
name,
label='*',
hostname,
port,
container,
label,
),
dump.make_data_source_dump_filename(
make_dump_path(borgmatic_source_directory),
name,
label='*',
hostname,
port,
container,
label,
),
)
+4
View File
@@ -453,6 +453,10 @@ def make_data_source_dump_patterns(
config,
borgmatic_runtime_directory,
name=None,
hostname=None,
port=None,
container=None,
label=None,
): # pragma: no cover
'''
Restores aren't implemented, because stored files can be extracted directly with "extract".
+1 -1
View File
@@ -1,6 +1,6 @@
[project]
name = "borgmatic"
version = "2.0.13"
version = "2.0.14.dev0"
authors = [
{ name="Dan Helfman", email="witten@torsion.org" },
]
+16
View File
@@ -315,6 +315,10 @@ def test_restore_single_dump_extracts_and_restores_single_file_dump():
object,
object,
object,
object,
object,
object,
object,
).and_return({'postgresql': flexmock()})
flexmock(module.tempfile).should_receive('mkdtemp').never()
flexmock(module.borgmatic.hooks.data_source.dump).should_receive(
@@ -359,6 +363,10 @@ def test_restore_single_dump_extracts_and_restores_directory_dump():
object,
object,
object,
object,
object,
object,
object,
).and_return({'postgresql': flexmock()})
flexmock(module.tempfile).should_receive('mkdtemp').once().and_return(
'/run/user/0/borgmatic/tmp1234',
@@ -405,6 +413,10 @@ def test_restore_single_dump_with_directory_dump_error_cleans_up_temporary_direc
object,
object,
object,
object,
object,
object,
object,
).and_return({'postgresql': flexmock()})
flexmock(module.tempfile).should_receive('mkdtemp').once().and_return(
'/run/user/0/borgmatic/tmp1234',
@@ -452,6 +464,10 @@ def test_restore_single_dump_with_directory_dump_and_dry_run_skips_directory_mov
object,
object,
object,
object,
object,
object,
object,
).and_return({'postgresql': flexmock()})
flexmock(module.tempfile).should_receive('mkdtemp').once().and_return('/run/borgmatic/tmp1234')
flexmock(module.borgmatic.hooks.data_source.dump).should_receive(
+1 -1
View File
@@ -158,5 +158,5 @@ def test_remove_data_source_dumps_without_dump_path_present_skips_removal():
def test_convert_glob_patterns_to_borg_pattern_makes_multipart_regular_expression():
assert (
module.convert_glob_patterns_to_borg_pattern(('/etc/foo/bar', '/bar/*/baz'))
== 're:(?s:etc/foo/bar)|(?s:bar/.*/baz)'
== 're:(?s:etc/foo/bar)$|(?s:bar/.*/baz)$'
)