1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2024-12-25 09:19:31 +00:00

borg check: remove --name, better use -a

The glob can also match precisely one archive,
so this does the same with less code.
This commit is contained in:
Thomas Waldmann 2022-06-25 22:17:29 +02:00
parent b14bf8110f
commit c36c75db59
2 changed files with 17 additions and 29 deletions

View file

@ -1534,19 +1534,18 @@ def __init__(self):
self.error_found = False self.error_found = False
self.possibly_superseded = set() 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): verify_data=False, save_space=False):
"""Perform a set of checks on 'repository' """Perform a set of checks on 'repository'
:param repair: enable repair mode, write updated or corrected data into 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 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 glob: only check archives matching this glob
:param verify_data: integrity verification of data referenced by archives :param verify_data: integrity verification of data referenced by archives
:param save_space: Repository.commit(save_space) :param save_space: Repository.commit(save_space)
""" """
logger.info('Starting archive consistency check...') 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.repair = repair
self.repository = repository self.repository = repository
self.init_chunks() 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 self.error_found = True
del self.chunks[Manifest.MANIFEST_ID] del self.chunks[Manifest.MANIFEST_ID]
self.manifest = self.rebuild_manifest() 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.orphan_chunks_check()
self.finish(save_space=save_space) self.finish(save_space=save_space)
if self.error_found: if self.error_found:
@ -1738,7 +1737,7 @@ def valid_archive(obj):
logger.info('Manifest rebuild complete.') logger.info('Manifest rebuild complete.')
return manifest 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 """Rebuild object reference counts by walking the metadata
Missing and/or incorrect data is repaired when detected Missing and/or incorrect data is repaired when detected
@ -1909,26 +1908,17 @@ def valid_item(obj):
raise raise
i += 1 i += 1
if archive is None: sort_by = sort_by.split(',')
sort_by = sort_by.split(',') if any((first, last, glob)):
if any((first, last, glob)): archive_infos = self.manifest.archives.list(sort_by=sort_by, glob=glob, first=first, last=last)
archive_infos = self.manifest.archives.list(sort_by=sort_by, glob=glob, first=first, last=last) if glob and not archive_infos:
if glob and not archive_infos: logger.warning('--glob-archives %s does not match any archives', glob)
logger.warning('--glob-archives %s does not match any archives', glob) if first and len(archive_infos) < first:
if first and len(archive_infos) < first: logger.warning('--first %d archives: only found %d archives', first, len(archive_infos))
logger.warning('--first %d archives: only found %d archives', first, len(archive_infos)) if last and len(archive_infos) < last:
if last and len(archive_infos) < last: logger.warning('--last %d archives: only found %d archives', last, len(archive_infos))
logger.warning('--last %d archives: only found %d archives', last, len(archive_infos))
else:
archive_infos = self.manifest.archives.list(sort_by=sort_by)
else: else:
# we only want one specific archive archive_infos = self.manifest.archives.list(sort_by=sort_by)
try:
archive_infos = [self.manifest.archives[archive]]
except KeyError:
logger.error("Archive '%s' not found.", archive)
self.error_found = True
return
num_archives = len(archive_infos) num_archives = len(archive_infos)
pi = ProgressIndicatorPercent(total=num_archives, msg='Checking archives %3.1f%%', step=0.1, pi = ProgressIndicatorPercent(total=num_archives, msg='Checking archives %3.1f%%', step=0.1,

View file

@ -525,7 +525,8 @@ def do_check(self, args, repository):
return EXIT_ERROR return EXIT_ERROR
if args.repo_only and any( if args.repo_only and any(
(args.verify_data, args.first, args.last, args.prefix is not None, args.glob_archives)): (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 return EXIT_ERROR
if args.repair and args.max_duration: if args.repair and args.max_duration:
self.print_error("--repair does not allow --max-duration argument.") self.print_error("--repair does not allow --max-duration argument.")
@ -542,8 +543,7 @@ def do_check(self, args, repository):
return EXIT_WARNING return EXIT_WARNING
if args.prefix is not None: if args.prefix is not None:
args.glob_archives = args.prefix + '*' args.glob_archives = args.prefix + '*'
if not args.repo_only and not ArchiveChecker().check( if not args.repo_only and not ArchiveChecker().check(repository, repair=args.repair,
repository, repair=args.repair, archive=args.name,
first=args.first, last=args.last, sort_by=args.sort_by or 'ts', glob=args.glob_archives, 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): verify_data=args.verify_data, save_space=args.save_space):
return EXIT_WARNING return EXIT_WARNING
@ -3501,8 +3501,6 @@ def define_borg_mount(parser):
formatter_class=argparse.RawDescriptionHelpFormatter, formatter_class=argparse.RawDescriptionHelpFormatter,
help='verify repository') help='verify repository')
subparser.set_defaults(func=self.do_check) 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', subparser.add_argument('--repository-only', dest='repo_only', action='store_true',
help='only perform repository checks') help='only perform repository checks')
subparser.add_argument('--archives-only', dest='archives_only', action='store_true', subparser.add_argument('--archives-only', dest='archives_only', action='store_true',