From a3750d1e060ac1886c5fab5875b93f7c76e3b3e0 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Tue, 23 Dec 2025 20:28:15 -0800 Subject: [PATCH] Fix an error when restoring multiple directory-format database dumps at once (#1212). --- NEWS | 3 +++ borgmatic/actions/restore.py | 18 +++++++++--------- pyproject.toml | 2 +- tests/unit/actions/test_restore.py | 1 + 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/NEWS b/NEWS index 185b4483..c9562283 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,6 @@ +2.0.14.dev0 + * #1212: Fix an error when restoring multiple directory-format database dumps at once. + 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: diff --git a/borgmatic/actions/restore.py b/borgmatic/actions/restore.py index 40ba95ca..0503f77f 100644 --- a/borgmatic/actions/restore.py +++ b/borgmatic/actions/restore.py @@ -129,14 +129,14 @@ def get_configured_data_source(config, restore_dump): def strip_path_prefix_from_extracted_dump_destination( - destination_path, + extract_path, borgmatic_runtime_directory, ): ''' Directory-format dump files get extracted into a temporary directory containing a path prefix - that depends how the files were stored in the archive. So, given the destination path where the - dump was extracted and the borgmatic runtime directory, move the dump files such that the - restore doesn't have to deal with that varying path prefix. + that depends how the files were stored in the archive. So, given the path where the dump was + extracted and the borgmatic runtime directory, move the dump files such that the restore doesn't + have to deal with that varying path prefix. For instance, if the dump was extracted to: @@ -150,16 +150,16 @@ def strip_path_prefix_from_extracted_dump_destination( /run/user/0/borgmatic/postgresql_databases/test/... ''' - for subdirectory_path, _, _ in os.walk(destination_path): + for subdirectory_path, _, _ in os.walk(extract_path): databases_directory = os.path.basename(subdirectory_path) if not databases_directory.endswith('_databases'): continue - shutil.move( - subdirectory_path, - os.path.join(borgmatic_runtime_directory, databases_directory), - ) + destination_path = os.path.join(borgmatic_runtime_directory, databases_directory) + shutil.rmtree(destination_path, ignore_errors=True) + shutil.move(subdirectory_path, destination_path) + break diff --git a/pyproject.toml b/pyproject.toml index 8a7eb600..2a0a0ff9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "borgmatic" -version = "2.0.13" +version = "2.0.14.dev0" authors = [ { name="Dan Helfman", email="witten@torsion.org" }, ] diff --git a/tests/unit/actions/test_restore.py b/tests/unit/actions/test_restore.py index d167b254..fa64e9c4 100644 --- a/tests/unit/actions/test_restore.py +++ b/tests/unit/actions/test_restore.py @@ -295,6 +295,7 @@ def test_strip_path_prefix_from_extracted_dump_destination_renames_first_matchin ], ) + flexmock(module.shutil).should_receive('rmtree') flexmock(module.shutil).should_receive('move').with_args( '/foo/bar/postgresql_databases', '/run/user/0/borgmatic/postgresql_databases',