mirror of
https://github.com/borgbackup/borg.git
synced 2024-12-25 09:19:31 +00:00
check: Make sure all non-critical output is sent to stdout
This commit is contained in:
parent
a68e48bc30
commit
477e1a39dd
2 changed files with 12 additions and 12 deletions
|
@ -73,7 +73,11 @@ def do_check(self, args):
|
||||||
Type "Yes I am sure" if you understand this and want to continue.\n""")
|
Type "Yes I am sure" if you understand this and want to continue.\n""")
|
||||||
if input('Do you want to continue? ') == 'Yes I am sure':
|
if input('Do you want to continue? ') == 'Yes I am sure':
|
||||||
break
|
break
|
||||||
if args.phase in ('all', 'repository') and not repository.check(repair=args.repair):
|
if args.phase in ('all', 'repository'):
|
||||||
|
print('Starting repository check...')
|
||||||
|
if repository.check(repair=args.repair):
|
||||||
|
print('Repository check complete, no problems found.')
|
||||||
|
else:
|
||||||
return 1
|
return 1
|
||||||
if args.phase in ('all', 'archive') and not ArchiveChecker().check(repository, repair=args.repair):
|
if args.phase in ('all', 'archive') and not ArchiveChecker().check(repository, repair=args.repair):
|
||||||
return 1
|
return 1
|
||||||
|
|
|
@ -240,15 +240,13 @@ def check(self, repair=False):
|
||||||
the index is consistent with the data stored in the segments.
|
the index is consistent with the data stored in the segments.
|
||||||
"""
|
"""
|
||||||
error_found = False
|
error_found = False
|
||||||
def report_progress(msg, error=False):
|
def report_error(msg):
|
||||||
nonlocal error_found
|
nonlocal error_found
|
||||||
if error:
|
error_found = True
|
||||||
error_found = True
|
|
||||||
print(msg, file=sys.stderr)
|
print(msg, file=sys.stderr)
|
||||||
sys.stderr.flush()
|
sys.stderr.flush()
|
||||||
|
|
||||||
assert not self._active_txn
|
assert not self._active_txn
|
||||||
report_progress('Starting repository check...')
|
|
||||||
try:
|
try:
|
||||||
transaction_id = self.get_transaction_id()
|
transaction_id = self.get_transaction_id()
|
||||||
current_index = self.get_read_only_index(transaction_id)
|
current_index = self.get_read_only_index(transaction_id)
|
||||||
|
@ -267,7 +265,7 @@ def report_progress(msg, error=False):
|
||||||
try:
|
try:
|
||||||
objects = list(self.io.iter_objects(segment))
|
objects = list(self.io.iter_objects(segment))
|
||||||
except (IntegrityError, struct.error):
|
except (IntegrityError, struct.error):
|
||||||
report_progress('Error reading segment {}'.format(segment), error=True)
|
report_error('Error reading segment {}'.format(segment))
|
||||||
objects = []
|
objects = []
|
||||||
if repair:
|
if repair:
|
||||||
self.io.recover_segment(segment, filename)
|
self.io.recover_segment(segment, filename)
|
||||||
|
@ -294,22 +292,20 @@ def report_progress(msg, error=False):
|
||||||
elif tag == TAG_COMMIT:
|
elif tag == TAG_COMMIT:
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
report_progress('Unexpected tag {} in segment {}'.format(tag, segment), error=True)
|
report_error('Unexpected tag {} in segment {}'.format(tag, segment))
|
||||||
# We might need to add a commit tag if no committed segment is found
|
# We might need to add a commit tag if no committed segment is found
|
||||||
if repair and segments_transaction_id is None:
|
if repair and segments_transaction_id is None:
|
||||||
report_progress('Adding commit tag to segment {}'.format(transaction_id))
|
report_error('Adding commit tag to segment {}'.format(transaction_id))
|
||||||
self.io.segment = transaction_id + 1
|
self.io.segment = transaction_id + 1
|
||||||
self.io.write_commit()
|
self.io.write_commit()
|
||||||
self.io.close_segment()
|
self.io.close_segment()
|
||||||
if current_index and not repair:
|
if current_index and not repair:
|
||||||
if len(current_index) != len(self.index):
|
if len(current_index) != len(self.index):
|
||||||
report_progress('Index object count mismatch. {} != {}'.format(len(current_index), len(self.index)), error=True)
|
report_error('Index object count mismatch. {} != {}'.format(len(current_index), len(self.index)))
|
||||||
elif current_index:
|
elif current_index:
|
||||||
for key, value in self.index.iteritems():
|
for key, value in self.index.iteritems():
|
||||||
if current_index.get(key, (-1, -1)) != value:
|
if current_index.get(key, (-1, -1)) != value:
|
||||||
report_progress('Index mismatch for key {}. {} != {}'.format(key, value, current_index.get(key, (-1, -1))), error=True)
|
report_error('Index mismatch for key {}. {} != {}'.format(key, value, current_index.get(key, (-1, -1))))
|
||||||
if not error_found:
|
|
||||||
report_progress('Repository check complete, no problems found.')
|
|
||||||
if repair:
|
if repair:
|
||||||
self.compact_segments()
|
self.compact_segments()
|
||||||
self.write_index()
|
self.write_index()
|
||||||
|
|
Loading…
Reference in a new issue