From a6dc8c52d02954243c0e7793db8ab90fede82ec4 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Wed, 25 Dec 2024 22:55:42 +0100 Subject: [PATCH] check: more consistent messaging considering --repair, fixes #8533 --- src/borg/archive.py | 46 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/src/borg/archive.py b/src/borg/archive.py index 562528203d..617f0508f2 100644 --- a/src/borg/archive.py +++ b/src/borg/archive.py @@ -1868,6 +1868,8 @@ def valid_archive(obj): manifest.archives[name] = (chunk_id, archive.time) pi.finish() logger.info('Manifest rebuild complete.') + if not self.repair: + logger.warning('The rebuilt manifest will only be committed when using --repair!') return manifest def rebuild_refcounts(self, archive=None, first=0, last=0, sort_by='', glob=None): @@ -1918,7 +1920,11 @@ def replacement_chunk(size): chunks_healthy = item.chunks_healthy if has_chunks_healthy else chunks_current if has_chunks_healthy and len(chunks_current) != len(chunks_healthy): # should never happen, but there was issue #3218. - logger.warning(f'{archive_name}: {item.path}: Invalid chunks_healthy metadata removed!') + if self.repair: + msg = 'Invalid chunks_healthy metadata removed!' + else: + msg = 'Invalid chunks_healthy metadata would be removed with --repair!' + logger.warning(f'{archive_name}: {item.path}: {msg}') del item.chunks_healthy has_chunks_healthy = False chunks_healthy = chunks_current @@ -1927,9 +1933,12 @@ def replacement_chunk(size): if chunk_id not in self.chunks: # a chunk of the healthy list is missing if chunk_current == chunk_healthy: - logger.error('{}: {}: New missing file chunk detected (Byte {}-{}, Chunk {}). ' - 'Replacing with all-zero chunk.'.format( - archive_name, item.path, offset, offset + size, bin_to_hex(chunk_id))) + if self.repair: + msg = 'Replacing with all-zero chunk.' + else: + msg = 'Would replace it with all-zero chunk with --repair.' + logger.error(f'{archive_name}: {item.path}: New missing file chunk detected ' + f'(Byte {offset}-{offset+size}, Chunk {bin_to_hex(chunk_id)}). {msg}') self.error_found = chunks_replaced = True chunk_id, size, csize, cdata = replacement_chunk(size) add_reference(chunk_id, size, csize, cdata) @@ -1941,9 +1950,12 @@ def replacement_chunk(size): if chunk_id in self.chunks: add_reference(chunk_id, size, csize) else: - logger.warning('{}: {}: Missing all-zero replacement chunk detected (Byte {}-{}, Chunk {}). ' - 'Generating new replacement chunk.'.format( - archive_name, item.path, offset, offset + size, bin_to_hex(chunk_id))) + if self.repair: + msg = 'Generating new replacement chunk.' + else: + msg = 'Would generate new replacement chunk with --repair.' + logger.warning(f'{archive_name}: {item.path}: Missing all-zero replacement chunk detected ' + f'(Byte {offset}-{offset+size}, Chunk {bin_to_hex(chunk_id)}). {msg}') self.error_found = chunks_replaced = True chunk_id, size, csize, cdata = replacement_chunk(size) add_reference(chunk_id, size, csize, cdata) @@ -1952,8 +1964,12 @@ def replacement_chunk(size): # normal case, all fine. add_reference(chunk_id, size, csize) else: - logger.info('{}: {}: Healed previously missing file chunk! (Byte {}-{}, Chunk {}).'.format( - archive_name, item.path, offset, offset + size, bin_to_hex(chunk_id))) + if self.repair: + msg = 'Healed previously missing file chunk!' + else: + msg = 'Missing file chunk would be healed with --repair!' + logger.info(f'{archive_name}: {item.path}: {msg} ' + f'(Byte {offset}-{offset+size}, Chunk {bin_to_hex(chunk_id)})') add_reference(chunk_id, size, csize) mark_as_possibly_superseded(chunk_current[0]) # maybe orphaned the all-zero replacement chunk chunk_list.append([chunk_id, size, csize]) # list-typed element as chunks_healthy is list-of-lists @@ -1962,7 +1978,11 @@ def replacement_chunk(size): # if this is first repair, remember the correct chunk IDs, so we can maybe heal the file later item.chunks_healthy = item.chunks if has_chunks_healthy and chunk_list == chunks_healthy: - logger.info(f'{archive_name}: {item.path}: Completely healed previously damaged file!') + if self.repair: + msg = 'Completely healed previously damaged file!' + else: + msg = 'Would completely heal damaged file with --repair!' + logger.info(f'{archive_name}: {item.path}: {msg}') del item.chunks_healthy item.chunks = chunk_list if 'size' in item: @@ -2095,7 +2115,11 @@ def valid_item(obj): # when upgrading to borg 1.2.5, users are expected to TAM-authenticate all archives they # trust, so there shouldn't be any without TAM. logger.error('Archive TAM authentication issue for archive %s: %s', info.name, integrity_error) - logger.error('This archive will be *removed* from the manifest! It will be deleted.') + if self.repair: + msg = 'This archive will be *removed* from the manifest! It will be deleted.' + else: + msg = 'This archive would be *removed* / *deleted* when using --repair!' + logger.error(msg) self.error_found = True del self.manifest.archives[info.name] continue