From c36c75db59382ba122fbdb63751802de53cbdd27 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Sat, 25 Jun 2022 22:17:29 +0200 Subject: [PATCH] borg check: remove --name, better use -a The glob can also match precisely one archive, so this does the same with less code. --- src/borg/archive.py | 38 ++++++++++++++------------------------ src/borg/archiver.py | 8 +++----- 2 files changed, 17 insertions(+), 29 deletions(-) diff --git a/src/borg/archive.py b/src/borg/archive.py index 016544da6..2c49c18fd 100644 --- a/src/borg/archive.py +++ b/src/borg/archive.py @@ -1534,19 +1534,18 @@ def __init__(self): self.error_found = False self.possibly_superseded = set() - def check(self, repository, repair=False, archive=None, first=0, last=0, sort_by='', glob=None, + def check(self, repository, repair=False, first=0, last=0, sort_by='', glob=None, verify_data=False, save_space=False): """Perform a set of checks on 'repository' :param repair: enable repair mode, write updated or corrected data into repository - :param archive: only check this archive :param first/last/sort_by: only check this number of first/last archives ordered by sort_by :param glob: only check archives matching this glob :param verify_data: integrity verification of data referenced by archives :param save_space: Repository.commit(save_space) """ logger.info('Starting archive consistency check...') - self.check_all = archive is None and not any((first, last, glob)) + self.check_all = not any((first, last, glob)) self.repair = repair self.repository = repository self.init_chunks() @@ -1568,7 +1567,7 @@ def check(self, repository, repair=False, archive=None, first=0, last=0, sort_by self.error_found = True del self.chunks[Manifest.MANIFEST_ID] self.manifest = self.rebuild_manifest() - self.rebuild_refcounts(archive=archive, first=first, last=last, sort_by=sort_by, glob=glob) + self.rebuild_refcounts(glob=glob, first=first, last=last, sort_by=sort_by) self.orphan_chunks_check() self.finish(save_space=save_space) if self.error_found: @@ -1738,7 +1737,7 @@ def valid_archive(obj): logger.info('Manifest rebuild complete.') return manifest - def rebuild_refcounts(self, archive=None, first=0, last=0, sort_by='', glob=None): + def rebuild_refcounts(self, first=0, last=0, sort_by='', glob=None): """Rebuild object reference counts by walking the metadata Missing and/or incorrect data is repaired when detected @@ -1909,26 +1908,17 @@ def valid_item(obj): raise i += 1 - if archive is None: - sort_by = sort_by.split(',') - if any((first, last, glob)): - archive_infos = self.manifest.archives.list(sort_by=sort_by, glob=glob, first=first, last=last) - if glob and not archive_infos: - logger.warning('--glob-archives %s does not match any archives', glob) - if first and len(archive_infos) < first: - logger.warning('--first %d archives: only found %d archives', first, len(archive_infos)) - if last and len(archive_infos) < last: - logger.warning('--last %d archives: only found %d archives', last, len(archive_infos)) - else: - archive_infos = self.manifest.archives.list(sort_by=sort_by) + sort_by = sort_by.split(',') + if any((first, last, glob)): + archive_infos = self.manifest.archives.list(sort_by=sort_by, glob=glob, first=first, last=last) + if glob and not archive_infos: + logger.warning('--glob-archives %s does not match any archives', glob) + if first and len(archive_infos) < first: + logger.warning('--first %d archives: only found %d archives', first, len(archive_infos)) + if last and len(archive_infos) < last: + logger.warning('--last %d archives: only found %d archives', last, len(archive_infos)) else: - # we only want one specific archive - try: - archive_infos = [self.manifest.archives[archive]] - except KeyError: - logger.error("Archive '%s' not found.", archive) - self.error_found = True - return + archive_infos = self.manifest.archives.list(sort_by=sort_by) num_archives = len(archive_infos) pi = ProgressIndicatorPercent(total=num_archives, msg='Checking archives %3.1f%%', step=0.1, diff --git a/src/borg/archiver.py b/src/borg/archiver.py index 8218ca1cf..c734d4bdb 100644 --- a/src/borg/archiver.py +++ b/src/borg/archiver.py @@ -525,7 +525,8 @@ def do_check(self, args, repository): return EXIT_ERROR if args.repo_only and any( (args.verify_data, args.first, args.last, args.prefix is not None, args.glob_archives)): - self.print_error("--repository-only contradicts --first, --last, --prefix and --verify-data arguments.") + self.print_error("--repository-only contradicts --first, --last, --prefix, --glob-archives " + " and --verify-data arguments.") return EXIT_ERROR if args.repair and args.max_duration: self.print_error("--repair does not allow --max-duration argument.") @@ -542,8 +543,7 @@ def do_check(self, args, repository): return EXIT_WARNING if args.prefix is not None: args.glob_archives = args.prefix + '*' - if not args.repo_only and not ArchiveChecker().check( - repository, repair=args.repair, archive=args.name, + if not args.repo_only and not ArchiveChecker().check(repository, repair=args.repair, first=args.first, last=args.last, sort_by=args.sort_by or 'ts', glob=args.glob_archives, verify_data=args.verify_data, save_space=args.save_space): return EXIT_WARNING @@ -3501,8 +3501,6 @@ def define_borg_mount(parser): formatter_class=argparse.RawDescriptionHelpFormatter, help='verify repository') subparser.set_defaults(func=self.do_check) - subparser.add_argument('--name', dest='name', metavar='NAME', type=NameSpec, - help='specify the archive name') subparser.add_argument('--repository-only', dest='repo_only', action='store_true', help='only perform repository checks') subparser.add_argument('--archives-only', dest='archives_only', action='store_true',