Support for Borg create & prune --stats via borgmatic command-line flag (#100)

This commit is contained in:
Felix Buehler 2018-12-06 23:58:14 +01:00
parent c3e7425f4c
commit 73d67e29b4
5 changed files with 36 additions and 1 deletions

View file

@ -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 ())
)

View file

@ -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))

View file

@ -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))

View file

@ -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$' \

View file

@ -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')