瀏覽代碼

Add --other-repo flag to rcreate action (#557).

Dan Helfman 2 年之前
父節點
當前提交
3b6ed06686

+ 5 - 2
borgmatic/borg/rcreate.py

@@ -16,6 +16,7 @@ def create_repository(
     storage_config,
     storage_config,
     local_borg_version,
     local_borg_version,
     encryption_mode,
     encryption_mode,
+    other_repo=None,
     append_only=None,
     append_only=None,
     storage_quota=None,
     storage_quota=None,
     local_path='borg',
     local_path='borg',
@@ -23,8 +24,9 @@ def create_repository(
 ):
 ):
     '''
     '''
     Given a local or remote repository path, a storage configuration dict, the local Borg version, a
     Given a local or remote repository path, a storage configuration dict, the local Borg version, a
-    Borg encryption mode, whether the repository should be append-only, and the storage quota to
-    use, create the repository. If the repository already exists, then log and skip creation.
+    Borg encryption mode, the path to another repo whose key material should be reused, whether the
+    repository should be append-only, and the storage quota to use, create the repository. If the
+    repository already exists, then log and skip creation.
     '''
     '''
     try:
     try:
         rinfo.display_repository_info(
         rinfo.display_repository_info(
@@ -51,6 +53,7 @@ def create_repository(
             else ('init',)
             else ('init',)
         )
         )
         + (('--encryption', encryption_mode) if encryption_mode else ())
         + (('--encryption', encryption_mode) if encryption_mode else ())
+        + (('--other-repo', other_repo) if other_repo else ())
         + (('--append-only',) if append_only else ())
         + (('--append-only',) if append_only else ())
         + (('--storage-quota', storage_quota) if storage_quota else ())
         + (('--storage-quota', storage_quota) if storage_quota else ())
         + (('--info',) if logger.getEffectiveLevel() == logging.INFO else ())
         + (('--info',) if logger.getEffectiveLevel() == logging.INFO else ())

+ 5 - 0
borgmatic/commands/arguments.py

@@ -239,6 +239,11 @@ def make_parsers():
         help='Borg repository encryption mode',
         help='Borg repository encryption mode',
         required=True,
         required=True,
     )
     )
+    rcreate_group.add_argument(
+        '--other-repo',
+        metavar='SOURCE_REPOSITORY',
+        help='Path to an existing Borg repository whose key material should be reused (Borg 2.x+ only)',
+    )
     rcreate_group.add_argument(
     rcreate_group.add_argument(
         '--append-only',
         '--append-only',
         dest='append_only',
         dest='append_only',

+ 1 - 0
borgmatic/commands/borgmatic.py

@@ -258,6 +258,7 @@ def run_actions(
             storage,
             storage,
             local_borg_version,
             local_borg_version,
             arguments['rcreate'].encryption_mode,
             arguments['rcreate'].encryption_mode,
+            arguments['rcreate'].other_repo,
             arguments['rcreate'].append_only,
             arguments['rcreate'].append_only,
             arguments['rcreate'].storage_quota,
             arguments['rcreate'].storage_quota,
             local_path=local_path,
             local_path=local_path,

+ 15 - 0
tests/unit/borg/test_rcreate.py

@@ -85,6 +85,21 @@ def test_create_repository_raises_for_unknown_rinfo_command_error():
         )
         )
 
 
 
 
+def test_create_repository_with_append_only_calls_borg_with_other_repo_parameter():
+    insert_rinfo_command_not_found_mock()
+    insert_rcreate_command_mock(RCREATE_COMMAND + ('--other-repo', 'other.borg', '--repo', 'repo'))
+    flexmock(module.feature).should_receive('available').and_return(True)
+    flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
+
+    module.create_repository(
+        repository='repo',
+        storage_config={},
+        local_borg_version='2.3.4',
+        encryption_mode='repokey',
+        other_repo='other.borg',
+    )
+
+
 def test_create_repository_with_append_only_calls_borg_with_append_only_parameter():
 def test_create_repository_with_append_only_calls_borg_with_append_only_parameter():
     insert_rinfo_command_not_found_mock()
     insert_rinfo_command_not_found_mock()
     insert_rcreate_command_mock(RCREATE_COMMAND + ('--append-only', '--repo', 'repo'))
     insert_rcreate_command_mock(RCREATE_COMMAND + ('--append-only', '--repo', 'repo'))

+ 4 - 1
tests/unit/commands/test_borgmatic.py

@@ -345,7 +345,10 @@ def test_run_actions_does_not_raise_for_rcreate_action():
     arguments = {
     arguments = {
         'global': flexmock(monitoring_verbosity=1, dry_run=False),
         'global': flexmock(monitoring_verbosity=1, dry_run=False),
         'rcreate': flexmock(
         'rcreate': flexmock(
-            encryption_mode=flexmock(), append_only=flexmock(), storage_quota=flexmock()
+            encryption_mode=flexmock(),
+            other_repo=flexmock(),
+            append_only=flexmock(),
+            storage_quota=flexmock(),
         ),
         ),
     }
     }