Compare commits

..

No commits in common. "a18b9ed6d0fa49039b95c851ef037baec74e2a79" and "ed1d79d4007f4c323a730671bddd4568f407c13a" have entirely different histories.

View File

@ -251,12 +251,11 @@ def main(argv: list[str]):
args = parser.parse_args()
config = Config(args.config)
backup = Backup(config, args.dry_run)
# Parse variables from vars.sh
hostname = os.uname().nodename
borg_sh = str(base / "borg.sh")
notify_sh = str(base / "notify.sh")
borg = str(base / "borg.sh")
notify = str(base / "notify.sh")
try:
with open(args.vars) as f:
for line in f:
@ -268,13 +267,14 @@ def main(argv: list[str]):
if var == "HOSTNAME":
hostname = value
if var == "BORG":
borg_sh = value
borg = value
if var == "BORG_DIR":
notify_sh = str(pathlib.Path(value) / "notify.sh")
notify = pathlib.Path(value) / "notify.sh"
except Exception as e:
backup.log('W', f"failed to parse variables from {args.vars}: {str(e)}")
self.log('W', f"failed to parse variables from {args.vars}: {str(e)}")
# Run backup
backup = Backup(config, args.dry_run)
captured_output: list[bytes] = []
if args.dry_run:
@ -285,7 +285,7 @@ def main(argv: list[str]):
backup.run(out)
sys.stdout.flush()
else:
borg = subprocess.Popen([borg_sh,
borg = subprocess.Popen([borg,
"create",
"--verbose",
"--progress",
@ -304,9 +304,6 @@ 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
@ -316,20 +313,7 @@ def main(argv: list[str]):
if ((data['type'] == 'log_message' or
data['type'] == 'progress_message')
and 'message' in data):
# 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()
line = (data['message'] + '\n').encode()
elif data['type'] == 'archive_progress':
now = time.time()
if now - last_progress > 10:
@ -375,12 +359,8 @@ def main(argv: list[str]):
ret = borg.returncode
if ret < 0:
backup.log('E', f"borg exited with signal {-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}")
elif ret != 0:
backup.log('E', f"borg exited with return code {ret}")
# See if we had any errors
warnings = sum(1 for (letter, msg) in backup.logs if letter == 'W')
@ -425,12 +405,12 @@ def main(argv: list[str]):
if errmsg and warnmsg:
summary = f"{errmsg}, {warnmsg}"
elif errors:
summary = errmsg or ""
summary = errmsg
else:
summary = warnmsg or ""
summary = warnmsg
# Call notify.sh
res = subprocess.run([notify_sh, summary, email], input=body_text)
res = subprocess.run([notify, summary, email], input=body_text)
if res.returncode != 0:
backup.log('E', f"failed to send notification")
errors += 1