mirror of https://github.com/borgbackup/borg.git
borg check: give a named single archive to it, fixes #139
This commit is contained in:
parent
35b0f38f5c
commit
03f39c2663
|
@ -609,7 +609,7 @@ class ArchiveChecker:
|
|||
self.error_found = False
|
||||
self.possibly_superseded = set()
|
||||
|
||||
def check(self, repository, repair=False, last=None):
|
||||
def check(self, repository, repair=False, archive=None, last=None):
|
||||
self.report_progress('Starting archive consistency check...')
|
||||
self.repair = repair
|
||||
self.repository = repository
|
||||
|
@ -619,8 +619,8 @@ class ArchiveChecker:
|
|||
self.manifest = self.rebuild_manifest()
|
||||
else:
|
||||
self.manifest, _ = Manifest.load(repository, key=self.key)
|
||||
self.rebuild_refcounts(last=last)
|
||||
if last is None:
|
||||
self.rebuild_refcounts(archive=archive, last=last)
|
||||
if last is None and archive is None:
|
||||
self.verify_chunks()
|
||||
else:
|
||||
self.report_progress('Orphaned objects check skipped (needs all archives checked)')
|
||||
|
@ -680,7 +680,7 @@ class ArchiveChecker:
|
|||
self.report_progress('Manifest rebuild complete', error=True)
|
||||
return manifest
|
||||
|
||||
def rebuild_refcounts(self, last=None):
|
||||
def rebuild_refcounts(self, archive=None, last=None):
|
||||
"""Rebuild object reference counts by walking the metadata
|
||||
|
||||
Missing and/or incorrect data is repaired when detected
|
||||
|
@ -762,10 +762,17 @@ class ArchiveChecker:
|
|||
yield item
|
||||
|
||||
repository = cache_if_remote(self.repository)
|
||||
num_archives = len(self.manifest.archives)
|
||||
archive_items = sorted(self.manifest.archives.items(), reverse=True,
|
||||
key=lambda name_info: name_info[1][b'time'])
|
||||
end = None if last is None else min(num_archives, last)
|
||||
if archive is None:
|
||||
# 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)
|
||||
end = None if last is None else min(num_archives, last)
|
||||
else:
|
||||
# we only want one specific archive
|
||||
archive_items = [item for item in self.manifest.archives.items() if item[0] == archive]
|
||||
num_archives = 1
|
||||
end = 1
|
||||
for i, (name, info) in enumerate(archive_items[:end]):
|
||||
self.report_progress('Analyzing archive {} ({}/{})'.format(name, num_archives - i, num_archives))
|
||||
archive_id = info[b'id']
|
||||
|
|
|
@ -85,8 +85,9 @@ Type "Yes I am sure" if you understand this and want to continue.\n""")
|
|||
print('Repository check complete, no problems found.')
|
||||
else:
|
||||
return 1
|
||||
if not args.repo_only and not ArchiveChecker().check(repository, repair=args.repair, last=args.last):
|
||||
return 1
|
||||
if not args.repo_only and not ArchiveChecker().check(
|
||||
repository, repair=args.repair, archive=args.repository.archive, last=args.last):
|
||||
return 1
|
||||
return 0
|
||||
|
||||
def do_change_passphrase(self, args):
|
||||
|
@ -554,6 +555,8 @@ Type "Yes I am sure" if you understand this and want to continue.\n""")
|
|||
and other types of damage. After that the consistency and correctness of the archive
|
||||
metadata is verified.
|
||||
|
||||
By giving an archive name, you can specifically check that archive.
|
||||
|
||||
The archive metadata checks can be time consuming and requires access to the key
|
||||
file and/or passphrase if encryption is enabled. These checks can be skipped using
|
||||
the --repository-only option.
|
||||
|
@ -563,9 +566,9 @@ Type "Yes I am sure" if you understand this and want to continue.\n""")
|
|||
epilog=check_epilog,
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter)
|
||||
subparser.set_defaults(func=self.do_check)
|
||||
subparser.add_argument('repository', metavar='REPOSITORY',
|
||||
type=location_validator(archive=False),
|
||||
help='repository to check consistency of')
|
||||
subparser.add_argument('repository', metavar='REPOSITORY_OR_ARCHIVE',
|
||||
type=location_validator(),
|
||||
help='repository or archive to check consistency of')
|
||||
subparser.add_argument('--repository-only', dest='repo_only', action='store_true',
|
||||
default=False,
|
||||
help='only perform repository checks')
|
||||
|
|
Loading…
Reference in New Issue