Reorder arguments passed to Borg to fix duplicate directories when using Borg patterns (#213).

This commit is contained in:
Dan Helfman 2019-09-12 15:27:04 -07:00
parent 896401088e
commit c085bacccf
15 changed files with 135 additions and 136 deletions

1
NEWS
View file

@ -2,6 +2,7 @@
* #208: Fix for traceback when the "checks" option has an empty value. * #208: Fix for traceback when the "checks" option has an empty value.
* #209: Bypass Borg error about a moved repository via "relocated_repo_access_is_ok" option in * #209: Bypass Borg error about a moved repository via "relocated_repo_access_is_ok" option in
borgmatic storage configuration section. borgmatic storage configuration section.
* #213: Reorder arguments passed to Borg to fix duplicate directories when using Borg patterns.
1.3.14 1.3.14
* #204: Do not treat Borg warnings (exit code 1) as failures. * #204: Do not treat Borg warnings (exit code 1) as failures.

View file

@ -105,11 +105,12 @@ def check_archives(
prefix = consistency_config.get('prefix', DEFAULT_PREFIX) prefix = consistency_config.get('prefix', DEFAULT_PREFIX)
full_command = ( full_command = (
(local_path, 'check', repository) (local_path, 'check')
+ _make_check_flags(checks, check_last, prefix) + _make_check_flags(checks, check_last, prefix)
+ remote_path_flags + remote_path_flags
+ lock_wait_flags + lock_wait_flags
+ verbosity_flags + verbosity_flags
+ (repository,)
) )
execute_command(full_command) execute_command(full_command)

View file

@ -126,14 +126,7 @@ def create_archive(
archive_name_format = storage_config.get('archive_name_format', default_archive_name_format) archive_name_format = storage_config.get('archive_name_format', default_archive_name_format)
full_command = ( full_command = (
( (local_path, 'create')
local_path,
'create',
'{repository}::{archive_name_format}'.format(
repository=repository, archive_name_format=archive_name_format
),
)
+ sources
+ _make_pattern_flags(location_config, pattern_file.name if pattern_file else None) + _make_pattern_flags(location_config, pattern_file.name if pattern_file else None)
+ _make_exclude_flags(location_config, exclude_file.name if exclude_file else None) + _make_exclude_flags(location_config, exclude_file.name if exclude_file else None)
+ (('--checkpoint-interval', str(checkpoint_interval)) if checkpoint_interval else ()) + (('--checkpoint-interval', str(checkpoint_interval)) if checkpoint_interval else ())
@ -162,6 +155,12 @@ def create_archive(
+ (('--dry-run',) if dry_run else ()) + (('--dry-run',) if dry_run else ())
+ (('--progress',) if progress else ()) + (('--progress',) if progress else ())
+ (('--json',) if json else ()) + (('--json',) if json else ())
+ (
'{repository}::{archive_name_format}'.format(
repository=repository, archive_name_format=archive_name_format
),
)
+ sources
) )
if json: if json:

View file

@ -19,10 +19,11 @@ def extract_last_archive_dry_run(repository, lock_wait=None, local_path='borg',
verbosity_flags = ('--info',) verbosity_flags = ('--info',)
full_list_command = ( full_list_command = (
(local_path, 'list', '--short', repository) (local_path, 'list', '--short')
+ remote_path_flags + remote_path_flags
+ lock_wait_flags + lock_wait_flags
+ verbosity_flags + verbosity_flags
+ (repository,)
) )
list_output = execute_command(full_list_command, output_log_level=None) list_output = execute_command(full_list_command, output_log_level=None)
@ -34,18 +35,16 @@ def extract_last_archive_dry_run(repository, lock_wait=None, local_path='borg',
list_flag = ('--list',) if logger.isEnabledFor(logging.DEBUG) else () list_flag = ('--list',) if logger.isEnabledFor(logging.DEBUG) else ()
full_extract_command = ( full_extract_command = (
( (local_path, 'extract', '--dry-run')
local_path,
'extract',
'--dry-run',
'{repository}::{last_archive_name}'.format(
repository=repository, last_archive_name=last_archive_name
),
)
+ remote_path_flags + remote_path_flags
+ lock_wait_flags + lock_wait_flags
+ verbosity_flags + verbosity_flags
+ list_flag + list_flag
+ (
'{repository}::{last_archive_name}'.format(
repository=repository, last_archive_name=last_archive_name
),
)
) )
execute_command(full_extract_command) execute_command(full_extract_command)
@ -71,8 +70,7 @@ def extract_archive(
lock_wait = storage_config.get('lock_wait', None) lock_wait = storage_config.get('lock_wait', None)
full_command = ( full_command = (
(local_path, 'extract', '::'.join((repository, archive))) (local_path, 'extract')
+ (tuple(restore_paths) if restore_paths else ())
+ (('--remote-path', remote_path) if remote_path else ()) + (('--remote-path', remote_path) if remote_path else ())
+ (('--numeric-owner',) if location_config.get('numeric_owner') else ()) + (('--numeric-owner',) if location_config.get('numeric_owner') else ())
+ (('--umask', str(umask)) if umask else ()) + (('--umask', str(umask)) if umask else ())
@ -81,6 +79,8 @@ def extract_archive(
+ (('--debug', '--list', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ()) + (('--debug', '--list', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
+ (('--dry-run',) if dry_run else ()) + (('--dry-run',) if dry_run else ())
+ (('--progress',) if progress else ()) + (('--progress',) if progress else ())
+ ('::'.join((repository, archive)),)
+ (tuple(restore_paths) if restore_paths else ())
) )
execute_command(full_command) execute_command(full_command)

View file

@ -17,13 +17,7 @@ def display_archives_info(
lock_wait = storage_config.get('lock_wait', None) lock_wait = storage_config.get('lock_wait', None)
full_command = ( full_command = (
( (local_path, 'info')
local_path,
'info',
'::'.join((repository, info_arguments.archive))
if info_arguments.archive
else repository,
)
+ ( + (
('--info',) ('--info',)
if logger.getEffectiveLevel() == logging.INFO and not info_arguments.json if logger.getEffectiveLevel() == logging.INFO and not info_arguments.json
@ -37,6 +31,11 @@ def display_archives_info(
+ make_flags('remote-path', remote_path) + make_flags('remote-path', remote_path)
+ make_flags('lock-wait', lock_wait) + make_flags('lock-wait', lock_wait)
+ make_flags_from_arguments(info_arguments, excludes=('repository', 'archive')) + make_flags_from_arguments(info_arguments, excludes=('repository', 'archive'))
+ (
'::'.join((repository, info_arguments.archive))
if info_arguments.archive
else repository,
)
) )
return execute_command( return execute_command(

View file

@ -34,13 +34,14 @@ def initialize_repository(
raise raise
init_command = ( init_command = (
(local_path, 'init', repository) (local_path, 'init')
+ (('--encryption', encryption_mode) if encryption_mode else ()) + (('--encryption', encryption_mode) if encryption_mode 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 ())
+ (('--debug',) if logger.isEnabledFor(logging.DEBUG) else ()) + (('--debug',) if logger.isEnabledFor(logging.DEBUG) else ())
+ (('--remote-path', remote_path) if remote_path else ()) + (('--remote-path', remote_path) if remote_path else ())
+ (repository,)
) )
# Don't use execute_command() here because it doesn't support interactive prompts. # Don't use execute_command() here because it doesn't support interactive prompts.

View file

@ -15,13 +15,7 @@ def list_archives(repository, storage_config, list_arguments, local_path='borg',
lock_wait = storage_config.get('lock_wait', None) lock_wait = storage_config.get('lock_wait', None)
full_command = ( full_command = (
( (local_path, 'list')
local_path,
'list',
'::'.join((repository, list_arguments.archive))
if list_arguments.archive
else repository,
)
+ ( + (
('--info',) ('--info',)
if logger.getEffectiveLevel() == logging.INFO and not list_arguments.json if logger.getEffectiveLevel() == logging.INFO and not list_arguments.json
@ -35,6 +29,11 @@ def list_archives(repository, storage_config, list_arguments, local_path='borg',
+ make_flags('remote-path', remote_path) + make_flags('remote-path', remote_path)
+ make_flags('lock-wait', lock_wait) + make_flags('lock-wait', lock_wait)
+ make_flags_from_arguments(list_arguments, excludes=('repository', 'archive')) + make_flags_from_arguments(list_arguments, excludes=('repository', 'archive'))
+ (
'::'.join((repository, list_arguments.archive))
if list_arguments.archive
else repository,
)
) )
return execute_command( return execute_command(

View file

@ -51,7 +51,7 @@ def prune_archives(
lock_wait = storage_config.get('lock_wait', None) lock_wait = storage_config.get('lock_wait', None)
full_command = ( full_command = (
(local_path, 'prune', repository) (local_path, 'prune')
+ tuple(element for pair in _make_prune_flags(retention_config) for element in pair) + tuple(element for pair in _make_prune_flags(retention_config) for element in pair)
+ (('--remote-path', remote_path) if remote_path else ()) + (('--remote-path', remote_path) if remote_path else ())
+ (('--umask', str(umask)) if umask else ()) + (('--umask', str(umask)) if umask else ())
@ -61,6 +61,7 @@ def prune_archives(
+ (('--debug', '--list', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ()) + (('--debug', '--list', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
+ (('--dry-run',) if dry_run else ()) + (('--dry-run',) if dry_run else ())
+ (('--stats',) if stats else ()) + (('--stats',) if stats else ())
+ (repository,)
) )
execute_command(full_command) execute_command(full_command)

View file

@ -163,7 +163,7 @@ def test_check_archives_with_log_info_calls_borg_with_info_parameter():
flexmock(module).should_receive('_parse_checks').and_return(checks) flexmock(module).should_receive('_parse_checks').and_return(checks)
flexmock(module).should_receive('_make_check_flags').and_return(()) flexmock(module).should_receive('_make_check_flags').and_return(())
insert_logging_mock(logging.INFO) insert_logging_mock(logging.INFO)
insert_execute_command_mock(('borg', 'check', 'repo', '--info')) insert_execute_command_mock(('borg', 'check', '--info', 'repo'))
module.check_archives( module.check_archives(
repository='repo', storage_config={}, consistency_config=consistency_config repository='repo', storage_config={}, consistency_config=consistency_config
@ -176,7 +176,7 @@ def test_check_archives_with_log_debug_calls_borg_with_debug_parameter():
flexmock(module).should_receive('_parse_checks').and_return(checks) flexmock(module).should_receive('_parse_checks').and_return(checks)
flexmock(module).should_receive('_make_check_flags').and_return(()) flexmock(module).should_receive('_make_check_flags').and_return(())
insert_logging_mock(logging.DEBUG) insert_logging_mock(logging.DEBUG)
insert_execute_command_mock(('borg', 'check', 'repo', '--debug', '--show-rc')) insert_execute_command_mock(('borg', 'check', '--debug', '--show-rc', 'repo'))
module.check_archives( module.check_archives(
repository='repo', storage_config={}, consistency_config=consistency_config repository='repo', storage_config={}, consistency_config=consistency_config
@ -219,7 +219,7 @@ def test_check_archives_with_remote_path_calls_borg_with_remote_path_parameters(
flexmock(module).should_receive('_make_check_flags').with_args( flexmock(module).should_receive('_make_check_flags').with_args(
checks, check_last, module.DEFAULT_PREFIX checks, check_last, module.DEFAULT_PREFIX
).and_return(()) ).and_return(())
insert_execute_command_mock(('borg', 'check', 'repo', '--remote-path', 'borg1')) insert_execute_command_mock(('borg', 'check', '--remote-path', 'borg1', 'repo'))
module.check_archives( module.check_archives(
repository='repo', repository='repo',
@ -237,7 +237,7 @@ def test_check_archives_with_lock_wait_calls_borg_with_lock_wait_parameters():
flexmock(module).should_receive('_make_check_flags').with_args( flexmock(module).should_receive('_make_check_flags').with_args(
checks, check_last, module.DEFAULT_PREFIX checks, check_last, module.DEFAULT_PREFIX
).and_return(()) ).and_return(())
insert_execute_command_mock(('borg', 'check', 'repo', '--lock-wait', '5')) insert_execute_command_mock(('borg', 'check', '--lock-wait', '5', 'repo'))
module.check_archives( module.check_archives(
repository='repo', storage_config={'lock_wait': 5}, consistency_config=consistency_config repository='repo', storage_config={'lock_wait': 5}, consistency_config=consistency_config

View file

@ -157,7 +157,7 @@ def test_make_exclude_flags_is_empty_when_config_has_no_excludes():
DEFAULT_ARCHIVE_NAME = '{hostname}-{now:%Y-%m-%dT%H:%M:%S.%f}' DEFAULT_ARCHIVE_NAME = '{hostname}-{now:%Y-%m-%dT%H:%M:%S.%f}'
CREATE_COMMAND = ('borg', 'create', 'repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo', 'bar') ARCHIVE_WITH_PATHS = ('repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo', 'bar')
def test_create_archive_calls_borg_with_parameters(): def test_create_archive_calls_borg_with_parameters():
@ -167,7 +167,7 @@ def test_create_archive_calls_borg_with_parameters():
flexmock(module).should_receive('_make_pattern_flags').and_return(()) flexmock(module).should_receive('_make_pattern_flags').and_return(())
flexmock(module).should_receive('_make_exclude_flags').and_return(()) flexmock(module).should_receive('_make_exclude_flags').and_return(())
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
CREATE_COMMAND, output_log_level=logging.INFO ('borg', 'create') + ARCHIVE_WITH_PATHS, output_log_level=logging.INFO
) )
module.create_archive( module.create_archive(
@ -192,7 +192,7 @@ def test_create_archive_with_patterns_calls_borg_with_patterns():
flexmock(module).should_receive('_make_pattern_flags').and_return(pattern_flags) flexmock(module).should_receive('_make_pattern_flags').and_return(pattern_flags)
flexmock(module).should_receive('_make_exclude_flags').and_return(()) flexmock(module).should_receive('_make_exclude_flags').and_return(())
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
CREATE_COMMAND + pattern_flags, output_log_level=logging.INFO ('borg', 'create') + pattern_flags + ARCHIVE_WITH_PATHS, output_log_level=logging.INFO
) )
module.create_archive( module.create_archive(
@ -217,7 +217,7 @@ def test_create_archive_with_exclude_patterns_calls_borg_with_excludes():
flexmock(module).should_receive('_make_pattern_flags').and_return(()) flexmock(module).should_receive('_make_pattern_flags').and_return(())
flexmock(module).should_receive('_make_exclude_flags').and_return(exclude_flags) flexmock(module).should_receive('_make_exclude_flags').and_return(exclude_flags)
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
CREATE_COMMAND + exclude_flags, output_log_level=logging.INFO ('borg', 'create') + exclude_flags + ARCHIVE_WITH_PATHS, output_log_level=logging.INFO
) )
module.create_archive( module.create_archive(
@ -240,7 +240,7 @@ def test_create_archive_with_log_info_calls_borg_with_info_parameter():
flexmock(module).should_receive('_make_pattern_flags').and_return(()) flexmock(module).should_receive('_make_pattern_flags').and_return(())
flexmock(module).should_receive('_make_exclude_flags').and_return(()) flexmock(module).should_receive('_make_exclude_flags').and_return(())
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
CREATE_COMMAND + ('--list', '--filter', 'AME-', '--info', '--stats'), ('borg', 'create', '--list', '--filter', 'AME-', '--info', '--stats') + ARCHIVE_WITH_PATHS,
output_log_level=logging.INFO, output_log_level=logging.INFO,
) )
insert_logging_mock(logging.INFO) insert_logging_mock(logging.INFO)
@ -265,7 +265,7 @@ def test_create_archive_with_log_info_and_json_suppresses_most_borg_output():
flexmock(module).should_receive('_make_pattern_flags').and_return(()) flexmock(module).should_receive('_make_pattern_flags').and_return(())
flexmock(module).should_receive('_make_exclude_flags').and_return(()) flexmock(module).should_receive('_make_exclude_flags').and_return(())
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
CREATE_COMMAND + ('--json',), output_log_level=None ('borg', 'create', '--json') + ARCHIVE_WITH_PATHS, output_log_level=None
) )
insert_logging_mock(logging.INFO) insert_logging_mock(logging.INFO)
@ -289,7 +289,8 @@ def test_create_archive_with_log_debug_calls_borg_with_debug_parameter():
flexmock(module).should_receive('_make_pattern_flags').and_return(()) flexmock(module).should_receive('_make_pattern_flags').and_return(())
flexmock(module).should_receive('_make_exclude_flags').and_return(()) flexmock(module).should_receive('_make_exclude_flags').and_return(())
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
CREATE_COMMAND + ('--list', '--filter', 'AME-', '--stats', '--debug', '--show-rc'), ('borg', 'create', '--list', '--filter', 'AME-', '--stats', '--debug', '--show-rc')
+ ARCHIVE_WITH_PATHS,
output_log_level=logging.INFO, output_log_level=logging.INFO,
) )
insert_logging_mock(logging.DEBUG) insert_logging_mock(logging.DEBUG)
@ -313,7 +314,7 @@ def test_create_archive_with_log_debug_and_json_suppresses_most_borg_output():
flexmock(module).should_receive('_make_pattern_flags').and_return(()) flexmock(module).should_receive('_make_pattern_flags').and_return(())
flexmock(module).should_receive('_make_exclude_flags').and_return(()) flexmock(module).should_receive('_make_exclude_flags').and_return(())
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
CREATE_COMMAND + ('--json',), output_log_level=None ('borg', 'create', '--json') + ARCHIVE_WITH_PATHS, output_log_level=None
) )
insert_logging_mock(logging.DEBUG) insert_logging_mock(logging.DEBUG)
@ -338,7 +339,7 @@ def test_create_archive_with_dry_run_calls_borg_with_dry_run_parameter():
flexmock(module).should_receive('_make_pattern_flags').and_return(()) flexmock(module).should_receive('_make_pattern_flags').and_return(())
flexmock(module).should_receive('_make_exclude_flags').and_return(()) flexmock(module).should_receive('_make_exclude_flags').and_return(())
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
CREATE_COMMAND + ('--dry-run',), output_log_level=logging.INFO ('borg', 'create', '--dry-run') + ARCHIVE_WITH_PATHS, output_log_level=logging.INFO
) )
module.create_archive( module.create_archive(
@ -363,7 +364,8 @@ def test_create_archive_with_dry_run_and_log_info_calls_borg_without_stats_param
flexmock(module).should_receive('_make_pattern_flags').and_return(()) flexmock(module).should_receive('_make_pattern_flags').and_return(())
flexmock(module).should_receive('_make_exclude_flags').and_return(()) flexmock(module).should_receive('_make_exclude_flags').and_return(())
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
CREATE_COMMAND + ('--list', '--filter', 'AME-', '--info', '--dry-run'), ('borg', 'create', '--list', '--filter', 'AME-', '--info', '--dry-run')
+ ARCHIVE_WITH_PATHS,
output_log_level=logging.INFO, output_log_level=logging.INFO,
) )
insert_logging_mock(logging.INFO) insert_logging_mock(logging.INFO)
@ -390,7 +392,8 @@ def test_create_archive_with_dry_run_and_log_debug_calls_borg_without_stats_para
flexmock(module).should_receive('_make_pattern_flags').and_return(()) flexmock(module).should_receive('_make_pattern_flags').and_return(())
flexmock(module).should_receive('_make_exclude_flags').and_return(()) flexmock(module).should_receive('_make_exclude_flags').and_return(())
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
CREATE_COMMAND + ('--list', '--filter', 'AME-', '--debug', '--show-rc', '--dry-run'), ('borg', 'create', '--list', '--filter', 'AME-', '--debug', '--show-rc', '--dry-run')
+ ARCHIVE_WITH_PATHS,
output_log_level=logging.INFO, output_log_level=logging.INFO,
) )
insert_logging_mock(logging.DEBUG) insert_logging_mock(logging.DEBUG)
@ -414,7 +417,8 @@ def test_create_archive_with_checkpoint_interval_calls_borg_with_checkpoint_inte
flexmock(module).should_receive('_make_pattern_flags').and_return(()) flexmock(module).should_receive('_make_pattern_flags').and_return(())
flexmock(module).should_receive('_make_exclude_flags').and_return(()) flexmock(module).should_receive('_make_exclude_flags').and_return(())
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
CREATE_COMMAND + ('--checkpoint-interval', '600'), output_log_level=logging.INFO ('borg', 'create', '--checkpoint-interval', '600') + ARCHIVE_WITH_PATHS,
output_log_level=logging.INFO,
) )
module.create_archive( module.create_archive(
@ -436,7 +440,8 @@ def test_create_archive_with_chunker_params_calls_borg_with_chunker_params_param
flexmock(module).should_receive('_make_pattern_flags').and_return(()) flexmock(module).should_receive('_make_pattern_flags').and_return(())
flexmock(module).should_receive('_make_exclude_flags').and_return(()) flexmock(module).should_receive('_make_exclude_flags').and_return(())
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
CREATE_COMMAND + ('--chunker-params', '1,2,3,4'), output_log_level=logging.INFO ('borg', 'create', '--chunker-params', '1,2,3,4') + ARCHIVE_WITH_PATHS,
output_log_level=logging.INFO,
) )
module.create_archive( module.create_archive(
@ -458,7 +463,8 @@ def test_create_archive_with_compression_calls_borg_with_compression_parameters(
flexmock(module).should_receive('_make_pattern_flags').and_return(()) flexmock(module).should_receive('_make_pattern_flags').and_return(())
flexmock(module).should_receive('_make_exclude_flags').and_return(()) flexmock(module).should_receive('_make_exclude_flags').and_return(())
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
CREATE_COMMAND + ('--compression', 'rle'), output_log_level=logging.INFO ('borg', 'create', '--compression', 'rle') + ARCHIVE_WITH_PATHS,
output_log_level=logging.INFO,
) )
module.create_archive( module.create_archive(
@ -480,7 +486,8 @@ def test_create_archive_with_remote_rate_limit_calls_borg_with_remote_ratelimit_
flexmock(module).should_receive('_make_pattern_flags').and_return(()) flexmock(module).should_receive('_make_pattern_flags').and_return(())
flexmock(module).should_receive('_make_exclude_flags').and_return(()) flexmock(module).should_receive('_make_exclude_flags').and_return(())
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
CREATE_COMMAND + ('--remote-ratelimit', '100'), output_log_level=logging.INFO ('borg', 'create', '--remote-ratelimit', '100') + ARCHIVE_WITH_PATHS,
output_log_level=logging.INFO,
) )
module.create_archive( module.create_archive(
@ -502,7 +509,7 @@ def test_create_archive_with_one_file_system_calls_borg_with_one_file_system_par
flexmock(module).should_receive('_make_pattern_flags').and_return(()) flexmock(module).should_receive('_make_pattern_flags').and_return(())
flexmock(module).should_receive('_make_exclude_flags').and_return(()) flexmock(module).should_receive('_make_exclude_flags').and_return(())
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
CREATE_COMMAND + ('--one-file-system',), output_log_level=logging.INFO ('borg', 'create', '--one-file-system') + ARCHIVE_WITH_PATHS, output_log_level=logging.INFO
) )
module.create_archive( module.create_archive(
@ -525,7 +532,7 @@ def test_create_archive_with_numeric_owner_calls_borg_with_numeric_owner_paramet
flexmock(module).should_receive('_make_pattern_flags').and_return(()) flexmock(module).should_receive('_make_pattern_flags').and_return(())
flexmock(module).should_receive('_make_exclude_flags').and_return(()) flexmock(module).should_receive('_make_exclude_flags').and_return(())
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
CREATE_COMMAND + ('--numeric-owner',), output_log_level=logging.INFO ('borg', 'create', '--numeric-owner') + ARCHIVE_WITH_PATHS, output_log_level=logging.INFO
) )
module.create_archive( module.create_archive(
@ -548,7 +555,7 @@ def test_create_archive_with_read_special_calls_borg_with_read_special_parameter
flexmock(module).should_receive('_make_pattern_flags').and_return(()) flexmock(module).should_receive('_make_pattern_flags').and_return(())
flexmock(module).should_receive('_make_exclude_flags').and_return(()) flexmock(module).should_receive('_make_exclude_flags').and_return(())
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
CREATE_COMMAND + ('--read-special',), output_log_level=logging.INFO ('borg', 'create', '--read-special') + ARCHIVE_WITH_PATHS, output_log_level=logging.INFO
) )
module.create_archive( module.create_archive(
@ -572,7 +579,7 @@ def test_create_archive_with_option_true_calls_borg_without_corresponding_parame
flexmock(module).should_receive('_make_pattern_flags').and_return(()) flexmock(module).should_receive('_make_pattern_flags').and_return(())
flexmock(module).should_receive('_make_exclude_flags').and_return(()) flexmock(module).should_receive('_make_exclude_flags').and_return(())
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
CREATE_COMMAND, output_log_level=logging.INFO ('borg', 'create') + ARCHIVE_WITH_PATHS, output_log_level=logging.INFO
) )
module.create_archive( module.create_archive(
@ -596,7 +603,8 @@ def test_create_archive_with_option_false_calls_borg_with_corresponding_paramete
flexmock(module).should_receive('_make_pattern_flags').and_return(()) flexmock(module).should_receive('_make_pattern_flags').and_return(())
flexmock(module).should_receive('_make_exclude_flags').and_return(()) flexmock(module).should_receive('_make_exclude_flags').and_return(())
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
CREATE_COMMAND + ('--no' + option_name.replace('_', ''),), output_log_level=logging.INFO ('borg', 'create', '--no' + option_name.replace('_', '')) + ARCHIVE_WITH_PATHS,
output_log_level=logging.INFO,
) )
module.create_archive( module.create_archive(
@ -619,7 +627,8 @@ def test_create_archive_with_files_cache_calls_borg_with_files_cache_parameters(
flexmock(module).should_receive('_make_pattern_flags').and_return(()) flexmock(module).should_receive('_make_pattern_flags').and_return(())
flexmock(module).should_receive('_make_exclude_flags').and_return(()) flexmock(module).should_receive('_make_exclude_flags').and_return(())
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
CREATE_COMMAND + ('--files-cache', 'ctime,size'), output_log_level=logging.INFO ('borg', 'create', '--files-cache', 'ctime,size') + ARCHIVE_WITH_PATHS,
output_log_level=logging.INFO,
) )
module.create_archive( module.create_archive(
@ -642,7 +651,7 @@ def test_create_archive_with_local_path_calls_borg_via_local_path():
flexmock(module).should_receive('_make_pattern_flags').and_return(()) flexmock(module).should_receive('_make_pattern_flags').and_return(())
flexmock(module).should_receive('_make_exclude_flags').and_return(()) flexmock(module).should_receive('_make_exclude_flags').and_return(())
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
('borg1',) + CREATE_COMMAND[1:], output_log_level=logging.INFO ('borg1', 'create') + ARCHIVE_WITH_PATHS, output_log_level=logging.INFO
) )
module.create_archive( module.create_archive(
@ -665,7 +674,8 @@ def test_create_archive_with_remote_path_calls_borg_with_remote_path_parameters(
flexmock(module).should_receive('_make_pattern_flags').and_return(()) flexmock(module).should_receive('_make_pattern_flags').and_return(())
flexmock(module).should_receive('_make_exclude_flags').and_return(()) flexmock(module).should_receive('_make_exclude_flags').and_return(())
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
CREATE_COMMAND + ('--remote-path', 'borg1'), output_log_level=logging.INFO ('borg', 'create', '--remote-path', 'borg1') + ARCHIVE_WITH_PATHS,
output_log_level=logging.INFO,
) )
module.create_archive( module.create_archive(
@ -688,7 +698,7 @@ def test_create_archive_with_umask_calls_borg_with_umask_parameters():
flexmock(module).should_receive('_make_pattern_flags').and_return(()) flexmock(module).should_receive('_make_pattern_flags').and_return(())
flexmock(module).should_receive('_make_exclude_flags').and_return(()) flexmock(module).should_receive('_make_exclude_flags').and_return(())
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
CREATE_COMMAND + ('--umask', '740'), output_log_level=logging.INFO ('borg', 'create', '--umask', '740') + ARCHIVE_WITH_PATHS, output_log_level=logging.INFO
) )
module.create_archive( module.create_archive(
@ -710,7 +720,7 @@ def test_create_archive_with_lock_wait_calls_borg_with_lock_wait_parameters():
flexmock(module).should_receive('_make_pattern_flags').and_return(()) flexmock(module).should_receive('_make_pattern_flags').and_return(())
flexmock(module).should_receive('_make_exclude_flags').and_return(()) flexmock(module).should_receive('_make_exclude_flags').and_return(())
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
CREATE_COMMAND + ('--lock-wait', '5'), output_log_level=logging.INFO ('borg', 'create', '--lock-wait', '5') + ARCHIVE_WITH_PATHS, output_log_level=logging.INFO
) )
module.create_archive( module.create_archive(
@ -732,7 +742,7 @@ def test_create_archive_with_stats_calls_borg_with_stats_parameter():
flexmock(module).should_receive('_make_pattern_flags').and_return(()) flexmock(module).should_receive('_make_pattern_flags').and_return(())
flexmock(module).should_receive('_make_exclude_flags').and_return(()) flexmock(module).should_receive('_make_exclude_flags').and_return(())
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
CREATE_COMMAND + ('--stats',), output_log_level=logging.WARNING ('borg', 'create', '--stats') + ARCHIVE_WITH_PATHS, output_log_level=logging.WARNING
) )
module.create_archive( module.create_archive(
@ -755,7 +765,7 @@ def test_create_archive_with_json_calls_borg_with_json_parameter():
flexmock(module).should_receive('_make_pattern_flags').and_return(()) flexmock(module).should_receive('_make_pattern_flags').and_return(())
flexmock(module).should_receive('_make_exclude_flags').and_return(()) flexmock(module).should_receive('_make_exclude_flags').and_return(())
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
CREATE_COMMAND + ('--json',), output_log_level=None ('borg', 'create', '--json') + ARCHIVE_WITH_PATHS, output_log_level=None
).and_return('[]') ).and_return('[]')
json_output = module.create_archive( json_output = module.create_archive(
@ -780,7 +790,7 @@ def test_create_archive_with_stats_and_json_calls_borg_without_stats_parameter()
flexmock(module).should_receive('_make_pattern_flags').and_return(()) flexmock(module).should_receive('_make_pattern_flags').and_return(())
flexmock(module).should_receive('_make_exclude_flags').and_return(()) flexmock(module).should_receive('_make_exclude_flags').and_return(())
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
CREATE_COMMAND + ('--json',), output_log_level=None ('borg', 'create', '--json') + ARCHIVE_WITH_PATHS, output_log_level=None
).and_return('[]') ).and_return('[]')
json_output = module.create_archive( json_output = module.create_archive(

View file

@ -34,9 +34,9 @@ def test_extract_last_archive_dry_run_without_any_archives_should_not_raise():
def test_extract_last_archive_dry_run_with_log_info_calls_borg_with_info_parameter(): def test_extract_last_archive_dry_run_with_log_info_calls_borg_with_info_parameter():
insert_execute_command_output_mock( insert_execute_command_output_mock(
('borg', 'list', '--short', 'repo', '--info'), result='archive1\narchive2\n' ('borg', 'list', '--short', '--info', 'repo'), result='archive1\narchive2\n'
) )
insert_execute_command_mock(('borg', 'extract', '--dry-run', 'repo::archive2', '--info')) insert_execute_command_mock(('borg', 'extract', '--dry-run', '--info', 'repo::archive2'))
insert_logging_mock(logging.INFO) insert_logging_mock(logging.INFO)
module.extract_last_archive_dry_run(repository='repo', lock_wait=None) module.extract_last_archive_dry_run(repository='repo', lock_wait=None)
@ -44,10 +44,10 @@ def test_extract_last_archive_dry_run_with_log_info_calls_borg_with_info_paramet
def test_extract_last_archive_dry_run_with_log_debug_calls_borg_with_debug_parameter(): def test_extract_last_archive_dry_run_with_log_debug_calls_borg_with_debug_parameter():
insert_execute_command_output_mock( insert_execute_command_output_mock(
('borg', 'list', '--short', 'repo', '--debug', '--show-rc'), result='archive1\narchive2\n' ('borg', 'list', '--short', '--debug', '--show-rc', 'repo'), result='archive1\narchive2\n'
) )
insert_execute_command_mock( insert_execute_command_mock(
('borg', 'extract', '--dry-run', 'repo::archive2', '--debug', '--show-rc', '--list') ('borg', 'extract', '--dry-run', '--debug', '--show-rc', '--list', 'repo::archive2')
) )
insert_logging_mock(logging.DEBUG) insert_logging_mock(logging.DEBUG)
@ -65,10 +65,10 @@ def test_extract_last_archive_dry_run_calls_borg_via_local_path():
def test_extract_last_archive_dry_run_calls_borg_with_remote_path_parameters(): def test_extract_last_archive_dry_run_calls_borg_with_remote_path_parameters():
insert_execute_command_output_mock( insert_execute_command_output_mock(
('borg', 'list', '--short', 'repo', '--remote-path', 'borg1'), result='archive1\narchive2\n' ('borg', 'list', '--short', '--remote-path', 'borg1', 'repo'), result='archive1\narchive2\n'
) )
insert_execute_command_mock( insert_execute_command_mock(
('borg', 'extract', '--dry-run', 'repo::archive2', '--remote-path', 'borg1') ('borg', 'extract', '--dry-run', '--remote-path', 'borg1', 'repo::archive2')
) )
module.extract_last_archive_dry_run(repository='repo', lock_wait=None, remote_path='borg1') module.extract_last_archive_dry_run(repository='repo', lock_wait=None, remote_path='borg1')
@ -76,10 +76,10 @@ def test_extract_last_archive_dry_run_calls_borg_with_remote_path_parameters():
def test_extract_last_archive_dry_run_calls_borg_with_lock_wait_parameters(): def test_extract_last_archive_dry_run_calls_borg_with_lock_wait_parameters():
insert_execute_command_output_mock( insert_execute_command_output_mock(
('borg', 'list', '--short', 'repo', '--lock-wait', '5'), result='archive1\narchive2\n' ('borg', 'list', '--short', '--lock-wait', '5', 'repo'), result='archive1\narchive2\n'
) )
insert_execute_command_mock( insert_execute_command_mock(
('borg', 'extract', '--dry-run', 'repo::archive2', '--lock-wait', '5') ('borg', 'extract', '--dry-run', '--lock-wait', '5', 'repo::archive2')
) )
module.extract_last_archive_dry_run(repository='repo', lock_wait=5) module.extract_last_archive_dry_run(repository='repo', lock_wait=5)
@ -99,7 +99,7 @@ def test_extract_archive_calls_borg_with_restore_path_parameters():
def test_extract_archive_calls_borg_with_remote_path_parameters(): def test_extract_archive_calls_borg_with_remote_path_parameters():
insert_execute_command_mock(('borg', 'extract', 'repo::archive', '--remote-path', 'borg1')) insert_execute_command_mock(('borg', 'extract', '--remote-path', 'borg1', 'repo::archive'))
module.extract_archive( module.extract_archive(
dry_run=False, dry_run=False,
@ -113,7 +113,7 @@ def test_extract_archive_calls_borg_with_remote_path_parameters():
def test_extract_archive_calls_borg_with_numeric_owner_parameter(): def test_extract_archive_calls_borg_with_numeric_owner_parameter():
insert_execute_command_mock(('borg', 'extract', 'repo::archive', '--numeric-owner')) insert_execute_command_mock(('borg', 'extract', '--numeric-owner', 'repo::archive'))
module.extract_archive( module.extract_archive(
dry_run=False, dry_run=False,
@ -126,7 +126,7 @@ def test_extract_archive_calls_borg_with_numeric_owner_parameter():
def test_extract_archive_calls_borg_with_umask_parameters(): def test_extract_archive_calls_borg_with_umask_parameters():
insert_execute_command_mock(('borg', 'extract', 'repo::archive', '--umask', '0770')) insert_execute_command_mock(('borg', 'extract', '--umask', '0770', 'repo::archive'))
module.extract_archive( module.extract_archive(
dry_run=False, dry_run=False,
@ -139,7 +139,7 @@ def test_extract_archive_calls_borg_with_umask_parameters():
def test_extract_archive_calls_borg_with_lock_wait_parameters(): def test_extract_archive_calls_borg_with_lock_wait_parameters():
insert_execute_command_mock(('borg', 'extract', 'repo::archive', '--lock-wait', '5')) insert_execute_command_mock(('borg', 'extract', '--lock-wait', '5', 'repo::archive'))
module.extract_archive( module.extract_archive(
dry_run=False, dry_run=False,
@ -152,7 +152,7 @@ def test_extract_archive_calls_borg_with_lock_wait_parameters():
def test_extract_archive_with_log_info_calls_borg_with_info_parameter(): def test_extract_archive_with_log_info_calls_borg_with_info_parameter():
insert_execute_command_mock(('borg', 'extract', 'repo::archive', '--info')) insert_execute_command_mock(('borg', 'extract', '--info', 'repo::archive'))
insert_logging_mock(logging.INFO) insert_logging_mock(logging.INFO)
module.extract_archive( module.extract_archive(
@ -167,7 +167,7 @@ def test_extract_archive_with_log_info_calls_borg_with_info_parameter():
def test_extract_archive_with_log_debug_calls_borg_with_debug_parameters(): def test_extract_archive_with_log_debug_calls_borg_with_debug_parameters():
insert_execute_command_mock( insert_execute_command_mock(
('borg', 'extract', 'repo::archive', '--debug', '--list', '--show-rc') ('borg', 'extract', '--debug', '--list', '--show-rc', 'repo::archive')
) )
insert_logging_mock(logging.DEBUG) insert_logging_mock(logging.DEBUG)
@ -182,7 +182,7 @@ def test_extract_archive_with_log_debug_calls_borg_with_debug_parameters():
def test_extract_archive_calls_borg_with_dry_run_parameter(): def test_extract_archive_calls_borg_with_dry_run_parameter():
insert_execute_command_mock(('borg', 'extract', 'repo::archive', '--dry-run')) insert_execute_command_mock(('borg', 'extract', '--dry-run', 'repo::archive'))
module.extract_archive( module.extract_archive(
dry_run=True, dry_run=True,
@ -195,7 +195,7 @@ def test_extract_archive_calls_borg_with_dry_run_parameter():
def test_extract_archive_calls_borg_with_progress_parameter(): def test_extract_archive_calls_borg_with_progress_parameter():
insert_execute_command_mock(('borg', 'extract', 'repo::archive', '--progress')) insert_execute_command_mock(('borg', 'extract', '--progress', 'repo::archive'))
module.extract_archive( module.extract_archive(
dry_run=False, dry_run=False,

View file

@ -7,12 +7,10 @@ from borgmatic.borg import info as module
from ..test_verbosity import insert_logging_mock from ..test_verbosity import insert_logging_mock
INFO_COMMAND = ('borg', 'info', 'repo')
def test_display_archives_info_calls_borg_with_parameters(): def test_display_archives_info_calls_borg_with_parameters():
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
INFO_COMMAND, output_log_level=logging.WARNING ('borg', 'info', 'repo'), output_log_level=logging.WARNING
) )
module.display_archives_info( module.display_archives_info(
@ -22,7 +20,7 @@ def test_display_archives_info_calls_borg_with_parameters():
def test_display_archives_info_with_log_info_calls_borg_with_info_parameter(): def test_display_archives_info_with_log_info_calls_borg_with_info_parameter():
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
INFO_COMMAND + ('--info',), output_log_level=logging.WARNING ('borg', 'info', '--info', 'repo'), output_log_level=logging.WARNING
) )
insert_logging_mock(logging.INFO) insert_logging_mock(logging.INFO)
module.display_archives_info( module.display_archives_info(
@ -32,7 +30,7 @@ def test_display_archives_info_with_log_info_calls_borg_with_info_parameter():
def test_display_archives_info_with_log_info_and_json_suppresses_most_borg_output(): def test_display_archives_info_with_log_info_and_json_suppresses_most_borg_output():
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
INFO_COMMAND + ('--json',), output_log_level=None ('borg', 'info', '--json', 'repo'), output_log_level=None
).and_return('[]') ).and_return('[]')
insert_logging_mock(logging.INFO) insert_logging_mock(logging.INFO)
@ -45,7 +43,7 @@ def test_display_archives_info_with_log_info_and_json_suppresses_most_borg_outpu
def test_display_archives_info_with_log_debug_calls_borg_with_debug_parameter(): def test_display_archives_info_with_log_debug_calls_borg_with_debug_parameter():
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
INFO_COMMAND + ('--debug', '--show-rc'), output_log_level=logging.WARNING ('borg', 'info', '--debug', '--show-rc', 'repo'), output_log_level=logging.WARNING
) )
insert_logging_mock(logging.DEBUG) insert_logging_mock(logging.DEBUG)
@ -56,7 +54,7 @@ def test_display_archives_info_with_log_debug_calls_borg_with_debug_parameter():
def test_display_archives_info_with_log_debug_and_json_suppresses_most_borg_output(): def test_display_archives_info_with_log_debug_and_json_suppresses_most_borg_output():
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
INFO_COMMAND + ('--json',), output_log_level=None ('borg', 'info', '--json', 'repo'), output_log_level=None
).and_return('[]') ).and_return('[]')
insert_logging_mock(logging.DEBUG) insert_logging_mock(logging.DEBUG)
@ -69,7 +67,7 @@ def test_display_archives_info_with_log_debug_and_json_suppresses_most_borg_outp
def test_display_archives_info_with_json_calls_borg_with_json_parameter(): def test_display_archives_info_with_json_calls_borg_with_json_parameter():
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
INFO_COMMAND + ('--json',), output_log_level=None ('borg', 'info', '--json', 'repo'), output_log_level=None
).and_return('[]') ).and_return('[]')
json_output = module.display_archives_info( json_output = module.display_archives_info(
@ -91,7 +89,7 @@ def test_display_archives_info_with_archive_calls_borg_with_archive_parameter():
def test_display_archives_info_with_local_path_calls_borg_via_local_path(): def test_display_archives_info_with_local_path_calls_borg_via_local_path():
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
('borg1',) + INFO_COMMAND[1:], output_log_level=logging.WARNING ('borg1', 'info', 'repo'), output_log_level=logging.WARNING
) )
module.display_archives_info( module.display_archives_info(
@ -104,7 +102,7 @@ def test_display_archives_info_with_local_path_calls_borg_via_local_path():
def test_display_archives_info_with_remote_path_calls_borg_with_remote_path_parameters(): def test_display_archives_info_with_remote_path_calls_borg_with_remote_path_parameters():
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
INFO_COMMAND + ('--remote-path', 'borg1'), output_log_level=logging.WARNING ('borg', 'info', '--remote-path', 'borg1', 'repo'), output_log_level=logging.WARNING
) )
module.display_archives_info( module.display_archives_info(
@ -118,7 +116,7 @@ def test_display_archives_info_with_remote_path_calls_borg_with_remote_path_para
def test_display_archives_info_with_lock_wait_calls_borg_with_lock_wait_parameters(): def test_display_archives_info_with_lock_wait_calls_borg_with_lock_wait_parameters():
storage_config = {'lock_wait': 5} storage_config = {'lock_wait': 5}
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
INFO_COMMAND + ('--lock-wait', '5'), output_log_level=logging.WARNING ('borg', 'info', '--lock-wait', '5', 'repo'), output_log_level=logging.WARNING
) )
module.display_archives_info( module.display_archives_info(
@ -131,7 +129,7 @@ def test_display_archives_info_with_lock_wait_calls_borg_with_lock_wait_paramete
@pytest.mark.parametrize('argument_name', ('prefix', 'glob_archives', 'sort_by', 'first', 'last')) @pytest.mark.parametrize('argument_name', ('prefix', 'glob_archives', 'sort_by', 'first', 'last'))
def test_display_archives_info_passes_through_arguments_to_borg(argument_name): def test_display_archives_info_passes_through_arguments_to_borg(argument_name):
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
INFO_COMMAND + ('--' + argument_name.replace('_', '-'), 'value'), ('borg', 'info', '--' + argument_name.replace('_', '-'), 'value', 'repo'),
output_log_level=logging.WARNING, output_log_level=logging.WARNING,
) )

View file

@ -9,7 +9,7 @@ from borgmatic.borg import init as module
from ..test_verbosity import insert_logging_mock from ..test_verbosity import insert_logging_mock
INFO_SOME_UNKNOWN_EXIT_CODE = -999 INFO_SOME_UNKNOWN_EXIT_CODE = -999
INIT_COMMAND = ('borg', 'init', 'repo', '--encryption', 'repokey') INIT_COMMAND = ('borg', 'init', '--encryption', 'repokey')
def insert_info_command_found_mock(): def insert_info_command_found_mock():
@ -30,7 +30,7 @@ def insert_init_command_mock(init_command, **kwargs):
def test_initialize_repository_calls_borg_with_parameters(): def test_initialize_repository_calls_borg_with_parameters():
insert_info_command_not_found_mock() insert_info_command_not_found_mock()
insert_init_command_mock(INIT_COMMAND) insert_init_command_mock(INIT_COMMAND + ('repo',))
module.initialize_repository(repository='repo', encryption_mode='repokey') module.initialize_repository(repository='repo', encryption_mode='repokey')
@ -72,21 +72,21 @@ def test_initialize_repository_raises_for_unknown_info_command_error():
def test_initialize_repository_with_append_only_calls_borg_with_append_only_parameter(): def test_initialize_repository_with_append_only_calls_borg_with_append_only_parameter():
insert_info_command_not_found_mock() insert_info_command_not_found_mock()
insert_init_command_mock(INIT_COMMAND + ('--append-only',)) insert_init_command_mock(INIT_COMMAND + ('--append-only', 'repo'))
module.initialize_repository(repository='repo', encryption_mode='repokey', append_only=True) module.initialize_repository(repository='repo', encryption_mode='repokey', append_only=True)
def test_initialize_repository_with_storage_quota_calls_borg_with_storage_quota_parameter(): def test_initialize_repository_with_storage_quota_calls_borg_with_storage_quota_parameter():
insert_info_command_not_found_mock() insert_info_command_not_found_mock()
insert_init_command_mock(INIT_COMMAND + ('--storage-quota', '5G')) insert_init_command_mock(INIT_COMMAND + ('--storage-quota', '5G', 'repo'))
module.initialize_repository(repository='repo', encryption_mode='repokey', storage_quota='5G') module.initialize_repository(repository='repo', encryption_mode='repokey', storage_quota='5G')
def test_initialize_repository_with_log_info_calls_borg_with_info_parameter(): def test_initialize_repository_with_log_info_calls_borg_with_info_parameter():
insert_info_command_not_found_mock() insert_info_command_not_found_mock()
insert_init_command_mock(INIT_COMMAND + ('--info',)) insert_init_command_mock(INIT_COMMAND + ('--info', 'repo'))
insert_logging_mock(logging.INFO) insert_logging_mock(logging.INFO)
module.initialize_repository(repository='repo', encryption_mode='repokey') module.initialize_repository(repository='repo', encryption_mode='repokey')
@ -94,7 +94,7 @@ def test_initialize_repository_with_log_info_calls_borg_with_info_parameter():
def test_initialize_repository_with_log_debug_calls_borg_with_debug_parameter(): def test_initialize_repository_with_log_debug_calls_borg_with_debug_parameter():
insert_info_command_not_found_mock() insert_info_command_not_found_mock()
insert_init_command_mock(INIT_COMMAND + ('--debug',)) insert_init_command_mock(INIT_COMMAND + ('--debug', 'repo'))
insert_logging_mock(logging.DEBUG) insert_logging_mock(logging.DEBUG)
module.initialize_repository(repository='repo', encryption_mode='repokey') module.initialize_repository(repository='repo', encryption_mode='repokey')
@ -102,13 +102,13 @@ def test_initialize_repository_with_log_debug_calls_borg_with_debug_parameter():
def test_initialize_repository_with_local_path_calls_borg_via_local_path(): def test_initialize_repository_with_local_path_calls_borg_via_local_path():
insert_info_command_not_found_mock() insert_info_command_not_found_mock()
insert_init_command_mock(('borg1',) + INIT_COMMAND[1:]) insert_init_command_mock(('borg1',) + INIT_COMMAND[1:] + ('repo',))
module.initialize_repository(repository='repo', encryption_mode='repokey', local_path='borg1') module.initialize_repository(repository='repo', encryption_mode='repokey', local_path='borg1')
def test_initialize_repository_with_remote_path_calls_borg_with_remote_path_parameter(): def test_initialize_repository_with_remote_path_calls_borg_with_remote_path_parameter():
insert_info_command_not_found_mock() insert_info_command_not_found_mock()
insert_init_command_mock(INIT_COMMAND + ('--remote-path', 'borg1')) insert_init_command_mock(INIT_COMMAND + ('--remote-path', 'borg1', 'repo'))
module.initialize_repository(repository='repo', encryption_mode='repokey', remote_path='borg1') module.initialize_repository(repository='repo', encryption_mode='repokey', remote_path='borg1')

View file

@ -7,12 +7,10 @@ from borgmatic.borg import list as module
from ..test_verbosity import insert_logging_mock from ..test_verbosity import insert_logging_mock
LIST_COMMAND = ('borg', 'list', 'repo')
def test_list_archives_calls_borg_with_parameters(): def test_list_archives_calls_borg_with_parameters():
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
LIST_COMMAND, output_log_level=logging.WARNING ('borg', 'list', 'repo'), output_log_level=logging.WARNING
) )
module.list_archives( module.list_archives(
@ -22,7 +20,7 @@ def test_list_archives_calls_borg_with_parameters():
def test_list_archives_with_log_info_calls_borg_with_info_parameter(): def test_list_archives_with_log_info_calls_borg_with_info_parameter():
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
LIST_COMMAND + ('--info',), output_log_level=logging.WARNING ('borg', 'list', '--info', 'repo'), output_log_level=logging.WARNING
) )
insert_logging_mock(logging.INFO) insert_logging_mock(logging.INFO)
@ -33,7 +31,7 @@ def test_list_archives_with_log_info_calls_borg_with_info_parameter():
def test_list_archives_with_log_info_and_json_suppresses_most_borg_output(): def test_list_archives_with_log_info_and_json_suppresses_most_borg_output():
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
LIST_COMMAND + ('--json',), output_log_level=None ('borg', 'list', '--json', 'repo'), output_log_level=None
) )
insert_logging_mock(logging.INFO) insert_logging_mock(logging.INFO)
@ -44,7 +42,7 @@ def test_list_archives_with_log_info_and_json_suppresses_most_borg_output():
def test_list_archives_with_log_debug_calls_borg_with_debug_parameter(): def test_list_archives_with_log_debug_calls_borg_with_debug_parameter():
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
LIST_COMMAND + ('--debug', '--show-rc'), output_log_level=logging.WARNING ('borg', 'list', '--debug', '--show-rc', 'repo'), output_log_level=logging.WARNING
) )
insert_logging_mock(logging.DEBUG) insert_logging_mock(logging.DEBUG)
@ -55,7 +53,7 @@ def test_list_archives_with_log_debug_calls_borg_with_debug_parameter():
def test_list_archives_with_log_debug_and_json_suppresses_most_borg_output(): def test_list_archives_with_log_debug_and_json_suppresses_most_borg_output():
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
LIST_COMMAND + ('--json',), output_log_level=None ('borg', 'list', '--json', 'repo'), output_log_level=None
) )
insert_logging_mock(logging.DEBUG) insert_logging_mock(logging.DEBUG)
@ -67,7 +65,7 @@ def test_list_archives_with_log_debug_and_json_suppresses_most_borg_output():
def test_list_archives_with_lock_wait_calls_borg_with_lock_wait_parameters(): def test_list_archives_with_lock_wait_calls_borg_with_lock_wait_parameters():
storage_config = {'lock_wait': 5} storage_config = {'lock_wait': 5}
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
LIST_COMMAND + ('--lock-wait', '5'), output_log_level=logging.WARNING ('borg', 'list', '--lock-wait', '5', 'repo'), output_log_level=logging.WARNING
) )
module.list_archives( module.list_archives(
@ -92,7 +90,7 @@ def test_list_archives_with_archive_calls_borg_with_archive_parameter():
def test_list_archives_with_local_path_calls_borg_via_local_path(): def test_list_archives_with_local_path_calls_borg_via_local_path():
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
('borg1',) + LIST_COMMAND[1:], output_log_level=logging.WARNING ('borg1', 'list', 'repo'), output_log_level=logging.WARNING
) )
module.list_archives( module.list_archives(
@ -105,7 +103,7 @@ def test_list_archives_with_local_path_calls_borg_via_local_path():
def test_list_archives_with_remote_path_calls_borg_with_remote_path_parameters(): def test_list_archives_with_remote_path_calls_borg_with_remote_path_parameters():
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
LIST_COMMAND + ('--remote-path', 'borg1'), output_log_level=logging.WARNING ('borg', 'list', '--remote-path', 'borg1', 'repo'), output_log_level=logging.WARNING
) )
module.list_archives( module.list_archives(
@ -118,7 +116,7 @@ def test_list_archives_with_remote_path_calls_borg_with_remote_path_parameters()
def test_list_archives_with_short_calls_borg_with_short_parameter(): def test_list_archives_with_short_calls_borg_with_short_parameter():
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
LIST_COMMAND + ('--short',), output_log_level=logging.WARNING ('borg', 'list', '--short', 'repo'), output_log_level=logging.WARNING
).and_return('[]') ).and_return('[]')
module.list_archives( module.list_archives(
@ -144,7 +142,7 @@ def test_list_archives_with_short_calls_borg_with_short_parameter():
) )
def test_list_archives_passes_through_arguments_to_borg(argument_name): def test_list_archives_passes_through_arguments_to_borg(argument_name):
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
LIST_COMMAND + ('--' + argument_name.replace('_', '-'), 'value'), ('borg', 'list', '--' + argument_name.replace('_', '-'), 'value', 'repo'),
output_log_level=logging.WARNING, output_log_level=logging.WARNING,
).and_return('[]') ).and_return('[]')
@ -157,7 +155,7 @@ def test_list_archives_passes_through_arguments_to_borg(argument_name):
def test_list_archives_with_json_calls_borg_with_json_parameter(): def test_list_archives_with_json_calls_borg_with_json_parameter():
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
LIST_COMMAND + ('--json',), output_log_level=None ('borg', 'list', '--json', 'repo'), output_log_level=None
).and_return('[]') ).and_return('[]')
json_output = module.list_archives( json_output = module.list_archives(

View file

@ -53,17 +53,7 @@ def test_make_prune_flags_treats_none_prefix_as_no_prefix():
assert tuple(result) == expected assert tuple(result) == expected
PRUNE_COMMAND = ( PRUNE_COMMAND = ('borg', 'prune', '--keep-daily', '1', '--keep-weekly', '2', '--keep-monthly', '3')
'borg',
'prune',
'repo',
'--keep-daily',
'1',
'--keep-weekly',
'2',
'--keep-monthly',
'3',
)
def test_prune_archives_calls_borg_with_parameters(): def test_prune_archives_calls_borg_with_parameters():
@ -71,7 +61,7 @@ def test_prune_archives_calls_borg_with_parameters():
flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return( flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return(
BASE_PRUNE_FLAGS BASE_PRUNE_FLAGS
) )
insert_execute_command_mock(PRUNE_COMMAND) insert_execute_command_mock(PRUNE_COMMAND + ('repo',))
module.prune_archives( module.prune_archives(
dry_run=False, repository='repo', storage_config={}, retention_config=retention_config dry_run=False, repository='repo', storage_config={}, retention_config=retention_config
@ -83,7 +73,7 @@ def test_prune_archives_with_log_info_calls_borg_with_info_parameter():
flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return( flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return(
BASE_PRUNE_FLAGS BASE_PRUNE_FLAGS
) )
insert_execute_command_mock(PRUNE_COMMAND + ('--stats', '--info')) insert_execute_command_mock(PRUNE_COMMAND + ('--stats', '--info', 'repo'))
insert_logging_mock(logging.INFO) insert_logging_mock(logging.INFO)
module.prune_archives( module.prune_archives(
@ -96,7 +86,9 @@ def test_prune_archives_with_log_debug_calls_borg_with_debug_parameter():
flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return( flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return(
BASE_PRUNE_FLAGS BASE_PRUNE_FLAGS
) )
insert_execute_command_mock(PRUNE_COMMAND + ('--stats', '--debug', '--list', '--show-rc')) insert_execute_command_mock(
PRUNE_COMMAND + ('--stats', '--debug', '--list', '--show-rc', 'repo')
)
insert_logging_mock(logging.DEBUG) insert_logging_mock(logging.DEBUG)
module.prune_archives( module.prune_archives(
@ -109,7 +101,7 @@ def test_prune_archives_with_dry_run_calls_borg_with_dry_run_parameter():
flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return( flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return(
BASE_PRUNE_FLAGS BASE_PRUNE_FLAGS
) )
insert_execute_command_mock(PRUNE_COMMAND + ('--dry-run',)) insert_execute_command_mock(PRUNE_COMMAND + ('--dry-run', 'repo'))
module.prune_archives( module.prune_archives(
repository='repo', storage_config={}, dry_run=True, retention_config=retention_config repository='repo', storage_config={}, dry_run=True, retention_config=retention_config
@ -121,7 +113,7 @@ def test_prune_archives_with_local_path_calls_borg_via_local_path():
flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return( flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return(
BASE_PRUNE_FLAGS BASE_PRUNE_FLAGS
) )
insert_execute_command_mock(('borg1',) + PRUNE_COMMAND[1:]) insert_execute_command_mock(('borg1',) + PRUNE_COMMAND[1:] + ('repo',))
module.prune_archives( module.prune_archives(
dry_run=False, dry_run=False,
@ -137,7 +129,7 @@ def test_prune_archives_with_remote_path_calls_borg_with_remote_path_parameters(
flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return( flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return(
BASE_PRUNE_FLAGS BASE_PRUNE_FLAGS
) )
insert_execute_command_mock(PRUNE_COMMAND + ('--remote-path', 'borg1')) insert_execute_command_mock(PRUNE_COMMAND + ('--remote-path', 'borg1', 'repo'))
module.prune_archives( module.prune_archives(
dry_run=False, dry_run=False,
@ -154,7 +146,7 @@ def test_prune_archives_with_umask_calls_borg_with_umask_parameters():
flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return( flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return(
BASE_PRUNE_FLAGS BASE_PRUNE_FLAGS
) )
insert_execute_command_mock(PRUNE_COMMAND + ('--umask', '077')) insert_execute_command_mock(PRUNE_COMMAND + ('--umask', '077', 'repo'))
module.prune_archives( module.prune_archives(
dry_run=False, dry_run=False,
@ -170,7 +162,7 @@ def test_prune_archives_with_lock_wait_calls_borg_with_lock_wait_parameters():
flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return( flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return(
BASE_PRUNE_FLAGS BASE_PRUNE_FLAGS
) )
insert_execute_command_mock(PRUNE_COMMAND + ('--lock-wait', '5')) insert_execute_command_mock(PRUNE_COMMAND + ('--lock-wait', '5', 'repo'))
module.prune_archives( module.prune_archives(
dry_run=False, dry_run=False,