Add final runtime and disk usage summary to mail reports

This commit is contained in:
admin committed 2026-09-25 13:35:01 +02:00
1 parent a5a7e38853
commit be48ee85ef
13 files changed
+142 -9

No files matched your search

+5 -7
View File
@@ -16,6 +16,7 @@ import socket
import subprocess
import sys
import time
from usage import human, summary
def allocated(path):
@@ -45,13 +46,6 @@ def snapshot(output, staging, archives):
Path(output).write_text(json.dumps(data), encoding='utf-8')
def human(value):
for unit in ('B', 'KiB', 'MiB', 'GiB', 'TiB'):
if value < 1024 or unit == 'TiB':
return f'{value:.1f} {unit}'
value /= 1024
def deliver(args):
fqdn = socket.getfqdn()
host = args.hostname or fqdn
@@ -91,6 +85,8 @@ def deliver(args):
else:
body.append('Archive total: '+human(sum(sizes['archives'].values())))
body.extend(['', f'Log-Auszug (letzte {args.tail_lines} Zeilen)', '-----------------', tail])
body.extend(summary(time.time() - args.started, args.workdir, args.archive_dir,
args.staging_root, args.restore_root, args.log_dir))
message = EmailMessage(policy=SMTP)
# EmailMessage rejects CR/LF in headers and encodes non-ASCII safely.
sender = args.sender or f'app-backup@{fqdn}'
@@ -117,6 +113,8 @@ def main():
snap.add_argument(name)
mail = commands.add_parser('deliver')
mail.add_argument('--hostname', default='')
for name in ('staging-root', 'restore-root', 'log-dir'):
mail.add_argument('--'+name, required=True)
for name in ('sizes', 'log', 'output', 'to', 'sender', 'subject-prefix', 'run', 'phase',
'upload-status', 'config', 'workdir', 'archive-dir', 'compression', 'remote', 'sendmail'):
mail.add_argument('--'+name, required=True)