View consistency check progress via "--progress" flag for "check" action (#287).

This commit is contained in:
Dan Helfman 2020-01-24 11:27:16 -08:00
parent 94b9ef56be
commit fdbb2ee905
5 changed files with 35 additions and 9 deletions

1
NEWS
View file

@ -3,6 +3,7 @@
* #277: Customize Healthchecks log level via borgmatic "--monitoring-verbosity" flag.
* #280: Change "exclude_if_present" option to support multiple filenames that indicate a directory
should be excluded from backups, rather than just a single filename.
* #287: View consistency check progress via "--progress" flag for "check" action.
* For "create" and "prune" actions, no longer list files or show detailed stats at any verbosities
by default. You can opt back in with "--files" or "--stats" flags.
* For "list" and "info" actions, show repository names even at verbosity 0.

View file

@ -91,13 +91,15 @@ def check_archives(
consistency_config,
local_path='borg',
remote_path=None,
progress=None,
repair=None,
only_checks=None,
):
'''
Given a local or remote repository path, a storage config dict, a consistency config dict,
local/remote commands to run, whether to attempt a repair, and an optional list of checks
to use instead of configured checks, check the contained Borg archives for consistency.
local/remote commands to run, whether to include progress information, whether to attempt a
repair, and an optional list of checks to use instead of configured checks, check the contained
Borg archives for consistency.
If there are no consistency checks to run, skip running them.
'''
@ -124,16 +126,16 @@ def check_archives(
+ (('--remote-path', remote_path) if remote_path else ())
+ (('--lock-wait', str(lock_wait)) if lock_wait else ())
+ verbosity_flags
+ (('--progress',) if progress else ())
+ (tuple(extra_borg_options.split(' ')) if extra_borg_options else ())
+ (repository,)
)
# The Borg repair option trigger an interactive prompt, which won't work when output is
# captured.
if repair:
# captured. And progress messes with the terminal directly.
if repair or progress:
execute_command_without_capture(full_command, error_on_warnings=True)
return
else:
execute_command(full_command, error_on_warnings=True)
if 'extract' in checks:

View file

@ -262,7 +262,7 @@ def parse_arguments(*unparsed_arguments):
dest='progress',
default=False,
action='store_true',
help='Display progress for each file as it is processed',
help='Display progress for each file as it is backed up',
)
create_group.add_argument(
'--stats',
@ -287,6 +287,13 @@ def parse_arguments(*unparsed_arguments):
add_help=False,
)
check_group = check_parser.add_argument_group('check arguments')
check_group.add_argument(
'--progress',
dest='progress',
default=False,
action='store_true',
help='Display progress for each file as it is checked',
)
check_group.add_argument(
'--repair',
dest='repair',
@ -336,7 +343,7 @@ def parse_arguments(*unparsed_arguments):
dest='progress',
default=False,
action='store_true',
help='Display progress for each file as it is processed',
help='Display progress for each file as it is extracted',
)
extract_group.add_argument(
'-h', '--help', action='help', help='Show this help message and exit'

View file

@ -242,6 +242,7 @@ def run_actions(
consistency,
local_path=local_path,
remote_path=remote_path,
progress=arguments['check'].progress,
repair=arguments['check'].repair,
only_checks=arguments['check'].only,
)

View file

@ -158,6 +158,21 @@ def test_make_check_flags_with_default_checks_and_prefix_includes_prefix_flag():
assert flags == ('--prefix', 'foo-')
def test_check_archives_with_progress_calls_borg_with_progress_parameter():
checks = ('repository',)
consistency_config = {'check_last': None}
flexmock(module).should_receive('_parse_checks').and_return(checks)
flexmock(module).should_receive('_make_check_flags').and_return(())
flexmock(module).should_receive('execute_command').never()
flexmock(module).should_receive('execute_command_without_capture').with_args(
('borg', 'check', '--progress', 'repo'), error_on_warnings=True
).once()
module.check_archives(
repository='repo', storage_config={}, consistency_config=consistency_config, progress=True
)
def test_check_archives_with_repair_calls_borg_with_repair_parameter():
checks = ('repository',)
consistency_config = {'check_last': None}