Browse Source

Fix repository does not exist error with "borgmatic extract" when repository is remote (#243).

Dan Helfman 5 years ago
parent
commit
04e5b42606
3 changed files with 20 additions and 3 deletions
  1. 1 0
      NEWS
  2. 3 3
      borgmatic/borg/extract.py
  3. 16 0
      tests/unit/borg/test_extract.py

+ 1 - 0
NEWS

@@ -1,6 +1,7 @@
 1.4.9.dev0
  * #228: Database dump hooks for MySQL/MariaDB, so you can easily dump your databases before backups
    run.
+ * #243: Fix repository does not exist error with "borgmatic extract" when repository is remote.
 
 1.4.8
  * Monitor backups with Cronhub hook integration. See the documentation for more information:

+ 3 - 3
borgmatic/borg/extract.py

@@ -83,7 +83,7 @@ def extract_archive(
         + (('--debug', '--list', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
         + (('--dry-run',) if dry_run else ())
         + (('--progress',) if progress else ())
-        + ('::'.join((os.path.abspath(repository), archive)),)
+        + ('::'.join((repository if ':' in repository else os.path.abspath(repository), archive)),)
         + (tuple(paths) if paths else ())
     )
 
@@ -95,8 +95,8 @@ def extract_archive(
         )
         return
 
-    # Error on warnings, as Borg only gives a warning if the restore paths don't exist in the
-    # archive!
+    # Error on warnings by default, as Borg only gives a warning if the restore paths don't exist in
+    # the archive!
     execute_command(
         full_command, working_directory=destination_path, error_on_warnings=error_on_warnings
     )

+ 16 - 0
tests/unit/borg/test_extract.py

@@ -236,3 +236,19 @@ def test_extract_archive_calls_borg_with_progress_parameter():
         storage_config={},
         progress=True,
     )
+
+
+def test_extract_archive_skips_abspath_for_remote_repository():
+    flexmock(module.os.path).should_receive('abspath').never()
+    flexmock(module).should_receive('execute_command').with_args(
+        ('borg', 'extract', 'server:repo::archive'), working_directory=None, error_on_warnings=True
+    ).once()
+
+    module.extract_archive(
+        dry_run=False,
+        repository='server:repo',
+        archive='archive',
+        paths=None,
+        location_config={},
+        storage_config={},
+    )