1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2024-12-24 08:45:13 +00:00

check: Make sure all non-critical output is sent to stdout

This commit is contained in:
Jonas Borgström 2014-03-04 21:21:58 +01:00
parent a68e48bc30
commit 477e1a39dd
2 changed files with 12 additions and 12 deletions

View file

@ -73,7 +73,11 @@ def do_check(self, args):
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':
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
if args.phase in ('all', 'archive') and not ArchiveChecker().check(repository, repair=args.repair):
return 1

View file

@ -240,15 +240,13 @@ def check(self, repair=False):
the index is consistent with the data stored in the segments.
"""
error_found = False
def report_progress(msg, error=False):
def report_error(msg):
nonlocal error_found
if error:
error_found = True
error_found = True
print(msg, file=sys.stderr)
sys.stderr.flush()
assert not self._active_txn
report_progress('Starting repository check...')
try:
transaction_id = self.get_transaction_id()
current_index = self.get_read_only_index(transaction_id)
@ -267,7 +265,7 @@ def report_progress(msg, error=False):
try:
objects = list(self.io.iter_objects(segment))
except (IntegrityError, struct.error):
report_progress('Error reading segment {}'.format(segment), error=True)
report_error('Error reading segment {}'.format(segment))
objects = []
if repair:
self.io.recover_segment(segment, filename)
@ -294,22 +292,20 @@ def report_progress(msg, error=False):
elif tag == TAG_COMMIT:
continue
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
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.write_commit()
self.io.close_segment()
if current_index and not repair:
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:
for key, value in self.index.iteritems():
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)
if not error_found:
report_progress('Repository check complete, no problems found.')
report_error('Index mismatch for key {}. {} != {}'.format(key, value, current_index.get(key, (-1, -1))))
if repair:
self.compact_segments()
self.write_index()