1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2025-03-04 18:48:43 +00:00

Merge pull request #6723 from KN4CK3R/forwardport-6722

Forwardport: borg debug dump-repo-objs --ghost (#6722)
This commit is contained in:
TW 2022-05-28 13:37:56 +02:00 committed by GitHub
commit e8046bc761
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 6 deletions

View file

@ -2290,7 +2290,7 @@ class Archiver:
key = key_factory(repository, cdata)
break
i = 0
for id, cdata, tag, segment, offset in repository.scan_low_level():
for id, cdata, tag, segment, offset in repository.scan_low_level(segment=args.segment, offset=args.offset):
if tag == TAG_PUT:
decrypt_dump(i, id, cdata, tag='put', segment=segment, offset=offset)
elif tag == TAG_DELETE:
@ -3917,6 +3917,10 @@ class Archiver:
help='repository to dump')
subparser.add_argument('--ghost', dest='ghost', action='store_true',
help='dump all segment file contents, including deleted/uncommitted objects and commits.')
subparser.add_argument('--segment', metavar='SEG', dest='segment', default=None, type=positive_int_validator,
help='used together with --ghost: limit processing to given segment.')
subparser.add_argument('--offset', metavar='OFFS', dest='offset', default=None, type=positive_int_validator,
help='used together with --ghost: limit processing to given offset.')
debug_search_repo_objs_epilog = process_epilog("""
This command searches raw (but decrypted and decompressed) repo objects for a specific bytes sequence.

View file

@ -1102,7 +1102,7 @@ class Repository:
logger.info('Finished %s repository check, no problems found.', mode)
return not error_found or repair
def scan_low_level(self):
def scan_low_level(self, segment=None, offset=None):
"""Very low level scan over all segment file entries.
It does NOT care about what's committed and what not.
@ -1111,13 +1111,21 @@ class Repository:
This is intended as a last-resort way to get access to all repo contents of damaged repos,
when there is uncommitted, but valuable data in there...
When segment or segment+offset is given, limit processing to this location only.
"""
for segment, filename in self.io.segment_iterator():
for current_segment, filename in self.io.segment_iterator(segment=segment):
if segment is not None and current_segment > segment:
break
try:
for tag, key, offset, data in self.io.iter_objects(segment, include_data=True):
yield key, data, tag, segment, offset
for tag, key, current_offset, data in self.io.iter_objects(segment=current_segment,
offset=offset or 0, include_data=True):
if offset is not None and current_offset > offset:
break
yield key, data, tag, current_segment, current_offset
except IntegrityError as err:
logger.error('Segment %d (%s) has IntegrityError(s) [%s] - skipping.' % (segment, filename, str(err)))
logger.error('Segment %d (%s) has IntegrityError(s) [%s] - skipping.' % (
current_segment, filename, str(err)))
def _rollback(self, *, cleanup):
"""