Browse Source

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

tags/1.2.13
Felix Buehler 6 months ago
parent
commit
73d67e29b4

+ 2
- 0
borgmatic/borg/create.py View File

@@ -91,6 +91,7 @@ def create_archive(
91 91
     local_path='borg',
92 92
     remote_path=None,
93 93
     progress=False,
94
+    stats=False,
94 95
     json=False,
95 96
 ):
96 97
     '''
@@ -139,6 +140,7 @@ def create_archive(
139 140
         + (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
140 141
         + (('--dry-run',) if dry_run else ())
141 142
         + (('--progress',) if progress else ())
143
+        + (('--stats',) if stats else ())
142 144
         + (('--json',) if json else ())
143 145
     )
144 146
 

+ 8
- 1
borgmatic/borg/prune.py View File

@@ -31,7 +31,13 @@ def _make_prune_flags(retention_config):
31 31
 
32 32
 
33 33
 def prune_archives(
34
-    dry_run, repository, storage_config, retention_config, local_path='borg', remote_path=None
34
+    dry_run,
35
+    repository,
36
+    storage_config,
37
+    retention_config,
38
+    local_path='borg',
39
+    remote_path=None,
40
+    stats=False,
35 41
 ):
36 42
     '''
37 43
     Given dry-run flag, a local or remote repository path, a storage config dict, and a
@@ -51,6 +57,7 @@ def prune_archives(
51 57
         + (('--info',) if logger.getEffectiveLevel() == logging.INFO else ())
52 58
         + (('--debug', '--list', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
53 59
         + (('--dry-run',) if dry_run else ())
60
+        + (('--stats',) if stats else ())
54 61
     )
55 62
 
56 63
     logger.debug(' '.join(full_command))

+ 12
- 0
borgmatic/commands/borgmatic.py View File

@@ -107,6 +107,13 @@ def parse_arguments(*arguments):
107 107
         action='store_true',
108 108
         help='Display progress with --create option for each file as it is backed up',
109 109
     )
110
+    parser.add_argument(
111
+        '--stats',
112
+        dest='stats',
113
+        default=False,
114
+        action='store_true',
115
+        help='Display status with --create or --prune option for each file as it is backed up',
116
+    )
110 117
     parser.add_argument(
111 118
         '--json',
112 119
         dest='json',
@@ -152,6 +159,9 @@ def parse_arguments(*arguments):
152 159
     if args.progress and not args.create:
153 160
         raise ValueError('The --progress option can only be used with the --create option')
154 161
 
162
+    if args.stats and not (args.create or args.prune):
163
+        raise ValueError('The --stats option can only be used with the --create, or --prune options')
164
+
155 165
     if args.json and not (args.create or args.list or args.info):
156 166
         raise ValueError(
157 167
             'The --json option can only be used with the --create, --list, or --info options'
@@ -261,6 +271,7 @@ def _run_commands_on_repository(
261 271
             retention,
262 272
             local_path=local_path,
263 273
             remote_path=remote_path,
274
+            stats=args.stats,
264 275
         )
265 276
     if args.create:
266 277
         logger.info('{}: Creating archive{}'.format(repository, dry_run_label))
@@ -272,6 +283,7 @@ def _run_commands_on_repository(
272 283
             local_path=local_path,
273 284
             remote_path=remote_path,
274 285
             progress=args.progress,
286
+            stats=args.stats,
275 287
         )
276 288
     if args.check and checks.repository_enabled_for_checks(repository, consistency):
277 289
         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
41 41
             | grep -v '^--nobsdflags$' \
42 42
             | grep -v '^--pattern$' \
43 43
             | grep -v '^--progress$' \
44
+            | grep -v '^--stats$' \
44 45
             | grep -v '^--read-special$' \
45 46
             | grep -v '^--repository-only$' \
46 47
             | 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():
143 143
         module.parse_arguments('--progress', '--list')
144 144
 
145 145
 
146
+def test_parse_arguments_with_stats_and_create_flags_does_not_raise():
147
+    module.parse_arguments('--stats', '--create', '--list')
148
+
149
+
150
+def test_parse_arguments_with_stats_and_prune_flags_does_not_raise():
151
+    module.parse_arguments('--stats', '--prune', '--list')
152
+
153
+
154
+def test_parse_arguments_with_stats_flag_but_no_create_or_prune_flag_raises_value_error():
155
+    with pytest.raises(ValueError):
156
+        module.parse_arguments('--stats', '--list')
157
+
158
+
146 159
 def test_parse_arguments_allows_json_with_list_or_info():
147 160
     module.parse_arguments('--list', '--json')
148 161
     module.parse_arguments('--info', '--json')

Loading…
Cancel
Save