Browse Source

backup: track errors/warnings from borg; add prefix to them

This also ignores the "file changed while we backed it up" error, because
that isn't important enough to warrant sending an email.
master
Jim Paris 2 years ago
parent
commit
a18b9ed6d0
1 changed files with 23 additions and 3 deletions
  1. +23
    -3
      backup.py

+ 23
- 3
backup.py View File

@@ -304,6 +304,9 @@ def main(argv: list[str]):
if borg.stdin is None:
raise Exception("no pipe")

borg_saw_warnings = 0
borg_saw_errors = 0

# Use a thread to capture output
def reader_thread(fh):
last_progress = 0
@@ -313,7 +316,20 @@ def main(argv: list[str]):
if ((data['type'] == 'log_message' or
data['type'] == 'progress_message')
and 'message' in data):
line = (data['message'] + '\n').encode()

# Count warnings and errors, but ignore some.
changed_msg = "file changed while we backed it up"
if data['levelname'] == 'WARNING':
prefix = "warning: "
if changed_msg not in data['message']:
borg_saw_warnings += 1
elif data['levelname'] not in ('DEBUG', 'INFO'):
prefix = "error: "
borg_saw_errors += 1
else:
prefix = ""

line = (prefix + data['message'] + '\n').encode()
elif data['type'] == 'archive_progress':
now = time.time()
if now - last_progress > 10:
@@ -359,8 +375,12 @@ def main(argv: list[str]):
ret = borg.returncode
if ret < 0:
backup.log('E', f"borg exited with signal {-ret}")
elif ret != 0:
backup.log('E', f"borg exited with return code {ret}")
elif ret == 2 or borg_saw_errors:
backup.log('E', f"borg exited with errors (ret={ret})")
elif ret == 1 or borg_saw_warnings:
backup.log('W', f"borg exited with warnings (ret={ret})")
else:
backup.log('E', f"borg exited with unknown error code {ret}")

# See if we had any errors
warnings = sum(1 for (letter, msg) in backup.logs if letter == 'W')


Loading…
Cancel
Save