diff --git a/borgmatic/borg/create.py b/borgmatic/borg/create.py index a446380..818ccac 100644 --- a/borgmatic/borg/create.py +++ b/borgmatic/borg/create.py @@ -91,6 +91,7 @@ def create_archive( local_path='borg', remote_path=None, progress=False, + stats=False, json=False, ): ''' @@ -139,6 +140,7 @@ def create_archive( + (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ()) + (('--dry-run',) if dry_run else ()) + (('--progress',) if progress else ()) + + (('--stats',) if stats else ()) + (('--json',) if json else ()) ) diff --git a/borgmatic/borg/prune.py b/borgmatic/borg/prune.py index fa1277d..54e4ba5 100644 --- a/borgmatic/borg/prune.py +++ b/borgmatic/borg/prune.py @@ -31,7 +31,13 @@ def _make_prune_flags(retention_config): def prune_archives( - dry_run, repository, storage_config, retention_config, local_path='borg', remote_path=None + dry_run, + repository, + storage_config, + retention_config, + local_path='borg', + remote_path=None, + stats=False, ): ''' Given dry-run flag, a local or remote repository path, a storage config dict, and a @@ -51,6 +57,7 @@ def prune_archives( + (('--info',) if logger.getEffectiveLevel() == logging.INFO else ()) + (('--debug', '--list', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ()) + (('--dry-run',) if dry_run else ()) + + (('--stats',) if stats else ()) ) logger.debug(' '.join(full_command)) diff --git a/borgmatic/commands/borgmatic.py b/borgmatic/commands/borgmatic.py index 6be3933..09b66ae 100644 --- a/borgmatic/commands/borgmatic.py +++ b/borgmatic/commands/borgmatic.py @@ -107,6 +107,13 @@ def parse_arguments(*arguments): action='store_true', help='Display progress with --create option for each file as it is backed up', ) + parser.add_argument( + '--stats', + dest='stats', + default=False, + action='store_true', + help='Display status with --create or --prune option for each file as it is backed up', + ) parser.add_argument( '--json', dest='json', @@ -152,6 +159,9 @@ def parse_arguments(*arguments): if args.progress and not args.create: raise ValueError('The --progress option can only be used with the --create option') + if args.stats and not (args.create or args.prune): + raise ValueError('The --stats option can only be used with the --create, or --prune options') + if args.json and not (args.create or args.list or args.info): raise ValueError( 'The --json option can only be used with the --create, --list, or --info options' @@ -261,6 +271,7 @@ def _run_commands_on_repository( retention, local_path=local_path, remote_path=remote_path, + stats=args.stats, ) if args.create: logger.info('{}: Creating archive{}'.format(repository, dry_run_label)) @@ -272,6 +283,7 @@ def _run_commands_on_repository( local_path=local_path, remote_path=remote_path, progress=args.progress, + stats=args.stats, ) if args.check and checks.repository_enabled_for_checks(repository, consistency): logger.info('{}: Running consistency checks'.format(repository)) diff --git a/scripts/find-unsupported-borg-options b/scripts/find-unsupported-borg-options index 8b98142..ee66ed7 100755 --- a/scripts/find-unsupported-borg-options +++ b/scripts/find-unsupported-borg-options @@ -41,6 +41,7 @@ for sub_command in prune create check list info; do | grep -v '^--nobsdflags$' \ | grep -v '^--pattern$' \ | grep -v '^--progress$' \ + | grep -v '^--stats$' \ | grep -v '^--read-special$' \ | grep -v '^--repository-only$' \ | grep -v '^--show-rc$' \ diff --git a/tests/integration/commands/test_borgmatic.py b/tests/integration/commands/test_borgmatic.py index cbbd4a0..82058aa 100644 --- a/tests/integration/commands/test_borgmatic.py +++ b/tests/integration/commands/test_borgmatic.py @@ -143,6 +143,19 @@ def test_parse_arguments_disallows_progress_without_create(): module.parse_arguments('--progress', '--list') +def test_parse_arguments_with_stats_and_create_flags_does_not_raise(): + module.parse_arguments('--stats', '--create', '--list') + + +def test_parse_arguments_with_stats_and_prune_flags_does_not_raise(): + module.parse_arguments('--stats', '--prune', '--list') + + +def test_parse_arguments_with_stats_flag_but_no_create_or_prune_flag_raises_value_error(): + with pytest.raises(ValueError): + module.parse_arguments('--stats', '--list') + + def test_parse_arguments_allows_json_with_list_or_info(): module.parse_arguments('--list', '--json') module.parse_arguments('--info', '--json')