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:
parent
b14bf8110f
commit
c36c75db59
2 changed files with 17 additions and 29 deletions
|
@ -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,
|
||||
|
|
|
@ -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',
|
||||
|
|
Loading…
Reference in a new issue