From 1b6b0cfae608e7b2e2711a3d66ff7e18fabaf0f9 Mon Sep 17 00:00:00 2001 From: Marian Beermann Date: Thu, 28 Jul 2016 18:40:20 +0200 Subject: [PATCH 1/3] Fix borg-check --verify-data tripping over ObjectNotFounds --- src/borg/archive.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/borg/archive.py b/src/borg/archive.py index e45655153..f19ba9793 100644 --- a/src/borg/archive.py +++ b/src/borg/archive.py @@ -954,20 +954,25 @@ class ArchiveChecker: def verify_data(self): logger.info('Starting cryptographic data integrity verification...') - pi = ProgressIndicatorPercent(total=len(self.chunks), msg="Verifying data %6.2f%%", step=0.01, same_line=True) - count = errors = 0 + count = len(self.chunks) + errors = 0 + pi = ProgressIndicatorPercent(total=count, msg="Verifying data %6.2f%%", step=0.01, same_line=True) for chunk_id, (refcount, *_) in self.chunks.iteritems(): pi.show() - if not refcount: - continue - encrypted_data = self.repository.get(chunk_id) try: - _, data = self.key.decrypt(chunk_id, encrypted_data) + encrypted_data = self.repository.get(chunk_id) + except Repository.ObjectNotFound: + self.error_found = True + errors += 1 + logger.error('chunk %s not found', bin_to_hex(chunk_id)) + continue + try: + _chunk_id = None if chunk_id == Manifest.MANIFEST_ID else chunk_id + _, data = self.key.decrypt(_chunk_id, encrypted_data) except IntegrityError as integrity_error: self.error_found = True errors += 1 logger.error('chunk %s, integrity error: %s', bin_to_hex(chunk_id), integrity_error) - count += 1 pi.finish() log = logger.error if errors else logger.info log('Finished cryptographic data integrity verification, verified %d chunks with %d integrity errors.', count, errors) From d0ec7e76bb36ffd4fce005c144c2f2c4c4080e3b Mon Sep 17 00:00:00 2001 From: Marian Beermann Date: Thu, 28 Jul 2016 18:41:08 +0200 Subject: [PATCH 2/3] Fix borg-check --verify-data failing with rebuilt objects There are some instances where --repair would do something. In these instances --verify-data would fail if --repair was not given also, since the changes without --repair are only in the index, but not in the repository. --- src/borg/archive.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/borg/archive.py b/src/borg/archive.py index f19ba9793..0efb1a6a3 100644 --- a/src/borg/archive.py +++ b/src/borg/archive.py @@ -909,6 +909,8 @@ class ArchiveChecker: self.repository = repository self.init_chunks() self.key = self.identify_key(repository) + if verify_data: + self.verify_data() if Manifest.MANIFEST_ID not in self.chunks: logger.error("Repository manifest not found!") self.error_found = True @@ -916,8 +918,6 @@ class ArchiveChecker: else: self.manifest, _ = Manifest.load(repository, key=self.key) self.rebuild_refcounts(archive=archive, last=last, prefix=prefix) - if verify_data: - self.verify_data() self.orphan_chunks_check() self.finish(save_space=save_space) if self.error_found: From 0ae48dafbb5ea043317fe5c19c86f15f83e38d35 Mon Sep 17 00:00:00 2001 From: Marian Beermann Date: Thu, 28 Jul 2016 18:41:19 +0200 Subject: [PATCH 3/3] ObjectNotFound: give ID as hex-string --- src/borg/repository.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/borg/repository.py b/src/borg/repository.py index 00a9c4e10..c83edcec8 100644 --- a/src/borg/repository.py +++ b/src/borg/repository.py @@ -96,6 +96,11 @@ class Repository: class ObjectNotFound(ErrorWithTraceback): """Object with key {} not found in repository {}.""" + def __init__(self, id, repo): + if isinstance(id, bytes): + id = bin_to_hex(id) + super().__init__(id, repo) + def __init__(self, path, create=False, exclusive=False, lock_wait=None, lock=True, append_only=False): self.path = os.path.abspath(path) self._location = Location('file://%s' % self.path)