diff --git a/borgmatic/borg/extract.py b/borgmatic/borg/extract.py index 3be3c8857..f302f49a2 100644 --- a/borgmatic/borg/extract.py +++ b/borgmatic/borg/extract.py @@ -57,28 +57,29 @@ def extract_archive( repository, archive, restore_paths, - location_config, storage_config, - local_path=None, + local_path='borg', remote_path=None, + progress=False, ): ''' Given a dry-run flag, a local or remote repository path, an archive name, zero or more paths to - restore from the archive, a location configuration dict, and a storage configuration dict, - extract the archive into the current directory. + restore from the archive, and a storage configuration dict, extract the archive into the current + directory. ''' umask = storage_config.get('umask', None) lock_wait = storage_config.get('lock_wait', None) full_command = ( - (local_path, 'extract', '::'.join(repository, archive)) - + restore_paths + (local_path, 'extract', '::'.join((repository, archive))) + + (restore_paths if restore_paths else ()) + (('--remote-path', remote_path) if remote_path else ()) + (('--umask', str(umask)) if umask else ()) + (('--lock-wait', str(lock_wait)) if lock_wait else ()) + (('--info',) if logger.getEffectiveLevel() == logging.INFO else ()) + (('--debug', '--list', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ()) + (('--dry-run',) if dry_run else ()) + + (('--progress',) if progress else ()) ) logger.debug(' '.join(full_command)) diff --git a/borgmatic/commands/borgmatic.py b/borgmatic/commands/borgmatic.py index 75a0d3aff..dd37b0bc5 100644 --- a/borgmatic/commands/borgmatic.py +++ b/borgmatic/commands/borgmatic.py @@ -357,6 +357,7 @@ def _run_commands_on_repository( storage, local_path=local_path, remote_path=remote_path, + progress=args.progress, ) if args.list: logger.info('{}: Listing archives'.format(repository)) diff --git a/tests/unit/borg/test_extract.py b/tests/unit/borg/test_extract.py index c970063a1..1cf23d2ee 100644 --- a/tests/unit/borg/test_extract.py +++ b/tests/unit/borg/test_extract.py @@ -24,7 +24,7 @@ def insert_subprocess_check_output_mock(check_output_command, result, **kwargs): ).once() -def test_extract_last_archive_dry_run_should_call_borg_with_last_archive(): +def test_extract_last_archive_dry_run_calls_borg_with_last_archive(): flexmock(sys.stdout).encoding = 'utf-8' insert_subprocess_check_output_mock( ('borg', 'list', '--short', 'repo'), result='archive1\narchive2\n'.encode('utf-8') @@ -44,7 +44,7 @@ def test_extract_last_archive_dry_run_without_any_archives_should_bail(): module.extract_last_archive_dry_run(repository='repo', lock_wait=None) -def test_extract_last_archive_dry_run_with_log_info_should_call_borg_with_info_parameter(): +def test_extract_last_archive_dry_run_with_log_info_calls_borg_with_info_parameter(): flexmock(sys.stdout).encoding = 'utf-8' insert_subprocess_check_output_mock( ('borg', 'list', '--short', 'repo', '--info'), result='archive1\narchive2\n'.encode('utf-8') @@ -55,7 +55,7 @@ def test_extract_last_archive_dry_run_with_log_info_should_call_borg_with_info_p module.extract_last_archive_dry_run(repository='repo', lock_wait=None) -def test_extract_last_archive_dry_run_with_log_debug_should_call_borg_with_debug_parameter(): +def test_extract_last_archive_dry_run_with_log_debug_calls_borg_with_debug_parameter(): flexmock(sys.stdout).encoding = 'utf-8' insert_subprocess_check_output_mock( ('borg', 'list', '--short', 'repo', '--debug', '--show-rc'), @@ -69,7 +69,7 @@ def test_extract_last_archive_dry_run_with_log_debug_should_call_borg_with_debug module.extract_last_archive_dry_run(repository='repo', lock_wait=None) -def test_extract_last_archive_dry_run_should_call_borg_via_local_path(): +def test_extract_last_archive_dry_run_calls_borg_via_local_path(): flexmock(sys.stdout).encoding = 'utf-8' insert_subprocess_check_output_mock( ('borg1', 'list', '--short', 'repo'), result='archive1\narchive2\n'.encode('utf-8') @@ -79,7 +79,7 @@ def test_extract_last_archive_dry_run_should_call_borg_via_local_path(): module.extract_last_archive_dry_run(repository='repo', lock_wait=None, local_path='borg1') -def test_extract_last_archive_dry_run_should_call_borg_with_remote_path_parameters(): +def test_extract_last_archive_dry_run_calls_borg_with_remote_path_parameters(): flexmock(sys.stdout).encoding = 'utf-8' insert_subprocess_check_output_mock( ('borg', 'list', '--short', 'repo', '--remote-path', 'borg1'), @@ -92,7 +92,7 @@ def test_extract_last_archive_dry_run_should_call_borg_with_remote_path_paramete module.extract_last_archive_dry_run(repository='repo', lock_wait=None, remote_path='borg1') -def test_extract_last_archive_dry_run_should_call_borg_with_lock_wait_parameters(): +def test_extract_last_archive_dry_run_calls_borg_with_lock_wait_parameters(): flexmock(sys.stdout).encoding = 'utf-8' insert_subprocess_check_output_mock( ('borg', 'list', '--short', 'repo', '--lock-wait', '5'), @@ -101,3 +101,79 @@ def test_extract_last_archive_dry_run_should_call_borg_with_lock_wait_parameters insert_subprocess_mock(('borg', 'extract', '--dry-run', 'repo::archive2', '--lock-wait', '5')) module.extract_last_archive_dry_run(repository='repo', lock_wait=5) + + +def test_extract_archive_calls_borg_with_remote_path_parameters(): + insert_subprocess_mock(('borg', 'extract', 'repo::archive', '--remote-path', 'borg1')) + + module.extract_archive( + dry_run=False, + repository='repo', + archive='archive', + restore_paths=None, + storage_config={}, + remote_path='borg1', + ) + + +def test_extract_archive_calls_borg_with_umask_parameters(): + insert_subprocess_mock(('borg', 'extract', 'repo::archive', '--umask', '0770')) + + module.extract_archive( + dry_run=False, + repository='repo', + archive='archive', + restore_paths=None, + storage_config={'umask': '0770'}, + ) + + +def test_extract_archive_calls_borg_with_lock_wait_parameters(): + insert_subprocess_mock(('borg', 'extract', 'repo::archive', '--lock-wait', '5')) + + module.extract_archive( + dry_run=False, + repository='repo', + archive='archive', + restore_paths=None, + storage_config={'lock_wait': '5'}, + ) + + +def test_extract_archive_with_log_info_calls_borg_with_info_parameter(): + insert_subprocess_mock(('borg', 'extract', 'repo::archive', '--info')) + insert_logging_mock(logging.INFO) + + module.extract_archive( + dry_run=False, repository='repo', archive='archive', restore_paths=None, storage_config={} + ) + + +def test_extract_archive_with_log_debug_calls_borg_with_debug_parameters(): + insert_subprocess_mock(('borg', 'extract', 'repo::archive', '--debug', '--list', '--show-rc')) + insert_logging_mock(logging.DEBUG) + + module.extract_archive( + dry_run=False, repository='repo', archive='archive', restore_paths=None, storage_config={} + ) + + +def test_extract_archive_calls_borg_with_dry_run_parameter(): + insert_subprocess_mock(('borg', 'extract', 'repo::archive', '--dry-run')) + + module.extract_archive( + dry_run=True, repository='repo', archive='archive', restore_paths=None, storage_config={} + ) + + +def test_extract_archive_calls_borg_with_progress_parameter(): + insert_subprocess_mock(('borg', 'extract', 'repo::archive', '--progress')) + + module.extract_archive( + dry_run=False, + repository='repo', + archive='archive', + restore_paths=None, + storage_config={}, + progress=True, + )