From c0b4c596efa6ec7ad34a679c7b95faa245659747 Mon Sep 17 00:00:00 2001 From: Simon Pilkington Date: Mon, 5 Jan 2026 03:39:48 +0100 Subject: [PATCH] Run borg with --progress during extract dry run if passed to borgmatic check. --- borgmatic/borg/extract.py | 27 +++++++++++++++++++-------- tests/unit/borg/test_extract.py | 24 ++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/borgmatic/borg/extract.py b/borgmatic/borg/extract.py index de418a0d..1765b744 100644 --- a/borgmatic/borg/extract.py +++ b/borgmatic/borg/extract.py @@ -49,9 +49,10 @@ def extract_last_archive_dry_run( full_extract_command = ( (local_path, 'extract', '--dry-run') + (('--remote-path', remote_path) if remote_path else ()) - + ('--log-json',) + + (('--log-json',) if not config.get('progress') else ()) + (('--lock-wait', str(lock_wait)) if lock_wait else ()) + verbosity_flags + + (('--progress',) if config.get('progress') else ()) + list_flag + (tuple(shlex.split(extra_borg_options)) if extra_borg_options else ()) + flags.make_repository_archive_flags( @@ -61,13 +62,23 @@ def extract_last_archive_dry_run( ) ) - execute_command( - full_extract_command, - environment=environment.make_environment(config), - working_directory=borgmatic.config.paths.get_working_directory(config), - borg_local_path=local_path, - borg_exit_codes=config.get('borg_exit_codes'), - ) + if config.get('progress'): + execute_command( + full_extract_command, + output_file=DO_NOT_CAPTURE, + environment=environment.make_environment(config), + working_directory=borgmatic.config.paths.get_working_directory(config), + borg_local_path=local_path, + borg_exit_codes=config.get('borg_exit_codes'), + ) + else: + execute_command( + full_extract_command, + environment=environment.make_environment(config), + working_directory=borgmatic.config.paths.get_working_directory(config), + borg_local_path=local_path, + borg_exit_codes=config.get('borg_exit_codes'), + ) def extract_archive( diff --git a/tests/unit/borg/test_extract.py b/tests/unit/borg/test_extract.py index 8704c08d..6983248d 100644 --- a/tests/unit/borg/test_extract.py +++ b/tests/unit/borg/test_extract.py @@ -95,6 +95,30 @@ def test_extract_last_archive_dry_run_with_log_debug_calls_borg_with_debug_param ) +def test_extract_last_archive_dry_run_calls_borg_with_progress_flag(): + flexmock(module.repo_list).should_receive('resolve_archive_name').and_return('archive') + flexmock(module.environment).should_receive('make_environment') + flexmock(module).should_receive('execute_command').with_args( + ('borg', 'extract', '--dry-run', '--progress', 'repo::archive'), + output_file=module.DO_NOT_CAPTURE, + environment=None, + working_directory=None, + borg_local_path='borg', + borg_exit_codes=None, + ).once() + flexmock(module.flags).should_receive('make_repository_archive_flags').and_return( + ('repo::archive',), + ) + + module.extract_last_archive_dry_run( + config={'progress': True}, + local_borg_version='1.2.3', + global_arguments=flexmock(), + repository_path='repo', + lock_wait=None, + ) + + def test_extract_last_archive_dry_run_calls_borg_via_local_path(): flexmock(module.repo_list).should_receive('resolve_archive_name').and_return('archive') insert_execute_command_mock(('borg1', 'extract', '--dry-run', '--log-json', 'repo::archive'))