mirror of
https://github.com/borgbackup/borg.git
synced 2024-12-24 08:45:13 +00:00
add --prefix to check to check only some specific archives, fixes #206
This commit is contained in:
parent
c4610c1edf
commit
aa97724c0c
3 changed files with 12 additions and 6 deletions
|
@ -661,9 +661,9 @@ def __init__(self):
|
|||
self.error_found = False
|
||||
self.possibly_superseded = set()
|
||||
|
||||
def check(self, repository, repair=False, archive=None, last=None, save_space=False):
|
||||
def check(self, repository, repair=False, archive=None, last=None, prefix=None, save_space=False):
|
||||
logger.info('Starting archive consistency check...')
|
||||
self.check_all = archive is None and last is None
|
||||
self.check_all = archive is None and last is None and prefix is None
|
||||
self.repair = repair
|
||||
self.repository = repository
|
||||
self.init_chunks()
|
||||
|
@ -674,7 +674,7 @@ def check(self, repository, repair=False, archive=None, last=None, save_space=Fa
|
|||
self.manifest = self.rebuild_manifest()
|
||||
else:
|
||||
self.manifest, _ = Manifest.load(repository, key=self.key)
|
||||
self.rebuild_refcounts(archive=archive, last=last)
|
||||
self.rebuild_refcounts(archive=archive, last=last, prefix=prefix)
|
||||
self.orphan_chunks_check()
|
||||
self.finish(save_space=save_space)
|
||||
if self.error_found:
|
||||
|
@ -730,7 +730,7 @@ def rebuild_manifest(self):
|
|||
logger.info('Manifest rebuild complete.')
|
||||
return manifest
|
||||
|
||||
def rebuild_refcounts(self, archive=None, last=None):
|
||||
def rebuild_refcounts(self, archive=None, last=None, prefix=None):
|
||||
"""Rebuild object reference counts by walking the metadata
|
||||
|
||||
Missing and/or incorrect data is repaired when detected
|
||||
|
@ -830,7 +830,9 @@ def report(msg, chunk_id, chunk_no):
|
|||
# we need last N or all archives
|
||||
archive_items = sorted(self.manifest.archives.items(), reverse=True,
|
||||
key=lambda name_info: name_info[1][b'time'])
|
||||
num_archives = len(self.manifest.archives)
|
||||
if prefix is not None:
|
||||
archive_items = [item for item in archive_items if item[0].startswith(prefix)]
|
||||
num_archives = len(archive_items)
|
||||
end = None if last is None else min(num_archives, last)
|
||||
else:
|
||||
# we only want one specific archive
|
||||
|
|
|
@ -109,7 +109,7 @@ def do_check(self, args):
|
|||
return EXIT_WARNING
|
||||
if not args.repo_only and not ArchiveChecker().check(
|
||||
repository, repair=args.repair, archive=args.repository.archive,
|
||||
last=args.last, save_space=args.save_space):
|
||||
last=args.last, prefix=args.prefix, save_space=args.save_space):
|
||||
return EXIT_WARNING
|
||||
return EXIT_SUCCESS
|
||||
|
||||
|
@ -769,6 +769,8 @@ def build_parser(self, args=None, prog=None):
|
|||
subparser.add_argument('--last', dest='last',
|
||||
type=int, default=None, metavar='N',
|
||||
help='only check last N archives (Default: all)')
|
||||
subparser.add_argument('-p', '--prefix', dest='prefix', type=str,
|
||||
help='only consider archive names starting with this prefix')
|
||||
|
||||
change_passphrase_epilog = textwrap.dedent("""
|
||||
The key files used for repository encryption are optionally passphrase
|
||||
|
|
|
@ -949,6 +949,8 @@ def test_check_usage(self):
|
|||
output = self.cmd('check', '-v', '--archives-only', self.repository_location, exit_code=0)
|
||||
self.assert_not_in('Starting repository check', output)
|
||||
self.assert_in('Starting archive consistency check', output)
|
||||
output = self.cmd('check', '-v', '--archives-only', '--prefix=archive2', self.repository_location, exit_code=0)
|
||||
self.assert_not_in('archive1', output)
|
||||
|
||||
def test_missing_file_chunk(self):
|
||||
archive, repository = self.open_archive('archive1')
|
||||
|
|
Loading…
Reference in a new issue