Browse Source

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

tags/1.2.13
Felix Buehler 1 year ago
parent
commit
73d67e29b4
5 changed files with 36 additions and 1 deletions
  1. +2
    -0
      borgmatic/borg/create.py
  2. +8
    -1
      borgmatic/borg/prune.py
  3. +12
    -0
      borgmatic/commands/borgmatic.py
  4. +1
    -0
      scripts/find-unsupported-borg-options
  5. +13
    -0
      tests/integration/commands/test_borgmatic.py

+ 2
- 0
borgmatic/borg/create.py 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 ())
)



+ 8
- 1
borgmatic/borg/prune.py 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))


+ 12
- 0
borgmatic/commands/borgmatic.py 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))


+ 1
- 0
scripts/find-unsupported-borg-options 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$' \


+ 13
- 0
tests/integration/commands/test_borgmatic.py 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')


Loading…
Cancel
Save