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

This commit is contained in:
Dan Helfman 2022-08-17 17:33:09 -07:00
parent 57009e22b5
commit 3b6ed06686
5 changed files with 30 additions and 3 deletions

View file

@ -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 ())

View file

@ -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',

View file

@ -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,

View file

@ -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'))

View file

@ -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(),
),
}