From 09745d22fdd61744c4f1d9d511f1fc2df1ae3e23 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Tue, 24 Dec 2024 19:34:21 +0100 Subject: [PATCH] compact: support --dry-run (do nothing), fixes #8300 Sole purpose of this is to simplify scripting. --- src/borg/archiver.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/borg/archiver.py b/src/borg/archiver.py index 530e0dbfb..17471e706 100644 --- a/src/borg/archiver.py +++ b/src/borg/archiver.py @@ -1893,11 +1893,12 @@ class Archiver: @with_repository(manifest=False, exclusive=True) def do_compact(self, args, repository): """compact segment files in the repository""" - # see the comment in do_with_lock about why we do it like this: - data = repository.get(Manifest.MANIFEST_ID) - repository.put(Manifest.MANIFEST_ID, data) - threshold = args.threshold / 100 - repository.commit(compact=True, threshold=threshold, cleanup_commits=args.cleanup_commits) + if not args.dry_run: # support --dry-run to simplify scripting + # see the comment in do_with_lock about why we do it like this: + data = repository.get(Manifest.MANIFEST_ID) + repository.put(Manifest.MANIFEST_ID, data) + threshold = args.threshold / 100 + repository.commit(compact=True, threshold=threshold, cleanup_commits=args.cleanup_commits) @with_repository(exclusive=True, manifest=False) def do_config(self, args, repository): @@ -3417,6 +3418,7 @@ class Archiver: subparser.add_argument('location', metavar='REPOSITORY', nargs='?', default='', type=location_validator(archive=False), help='repository to compact') + subparser.add_argument('-n', '--dry-run', dest='dry_run', action='store_true', help='do nothing') subparser.add_argument('--cleanup-commits', dest='cleanup_commits', action='store_true', help='cleanup commit-only 17-byte segment files') subparser.add_argument('--threshold', metavar='PERCENT', dest='threshold',