diff --git a/borgmatic/borg/rcreate.py b/borgmatic/borg/rcreate.py index 5c0be8961..6babe0170 100644 --- a/borgmatic/borg/rcreate.py +++ b/borgmatic/borg/rcreate.py @@ -16,6 +16,7 @@ def create_repository( storage_config, local_borg_version, encryption_mode, + other_repo=None, append_only=None, storage_quota=None, 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 - 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: rinfo.display_repository_info( @@ -51,6 +53,7 @@ def create_repository( else ('init',) ) + (('--encryption', encryption_mode) if encryption_mode else ()) + + (('--other-repo', other_repo) if other_repo else ()) + (('--append-only',) if append_only else ()) + (('--storage-quota', storage_quota) if storage_quota else ()) + (('--info',) if logger.getEffectiveLevel() == logging.INFO else ()) diff --git a/borgmatic/commands/arguments.py b/borgmatic/commands/arguments.py index d817f26e1..bcc4b7450 100644 --- a/borgmatic/commands/arguments.py +++ b/borgmatic/commands/arguments.py @@ -239,6 +239,11 @@ def make_parsers(): help='Borg repository encryption mode', 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( '--append-only', dest='append_only', diff --git a/borgmatic/commands/borgmatic.py b/borgmatic/commands/borgmatic.py index 4ddd27734..343b9a64d 100644 --- a/borgmatic/commands/borgmatic.py +++ b/borgmatic/commands/borgmatic.py @@ -258,6 +258,7 @@ def run_actions( storage, local_borg_version, arguments['rcreate'].encryption_mode, + arguments['rcreate'].other_repo, arguments['rcreate'].append_only, arguments['rcreate'].storage_quota, local_path=local_path, diff --git a/tests/unit/borg/test_rcreate.py b/tests/unit/borg/test_rcreate.py index 292534588..1a22e8e01 100644 --- a/tests/unit/borg/test_rcreate.py +++ b/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(): insert_rinfo_command_not_found_mock() insert_rcreate_command_mock(RCREATE_COMMAND + ('--append-only', '--repo', 'repo')) diff --git a/tests/unit/commands/test_borgmatic.py b/tests/unit/commands/test_borgmatic.py index 2f67b469e..670377e7f 100644 --- a/tests/unit/commands/test_borgmatic.py +++ b/tests/unit/commands/test_borgmatic.py @@ -345,7 +345,10 @@ def test_run_actions_does_not_raise_for_rcreate_action(): arguments = { 'global': flexmock(monitoring_verbosity=1, dry_run=False), 'rcreate': flexmock( - encryption_mode=flexmock(), append_only=flexmock(), storage_quota=flexmock() + encryption_mode=flexmock(), + other_repo=flexmock(), + append_only=flexmock(), + storage_quota=flexmock(), ), }