bundlewrap/bundles/backup-client/files/check_backup_last_run
Franziska Kunsmann 0f425036b2
All checks were successful
kunsi/bundlewrap/pipeline/head This commit looks good
bundles/backup-client: fix newlines
2021-08-04 15:55:14 +02:00

42 lines
956 B
Python

#!/usr/bin/env python3
from os.path import getmtime, isfile
from sys import exit
from time import time
statusfile = '/var/tmp/backup.monitoring'
if not isfile(statusfile):
print('Status file not found')
exit(3)
mtime = getmtime(statusfile)
now = time()
if now-mtime > 60*60*24*2:
print('Status file is older than 2 days!')
exit(3)
with open(statusfile, 'r') as f:
status = f.read().splitlines()
exitcode = status[0].strip()
if exitcode == 'ok':
print('OK')
exit(0)
elif exitcode == 'rsync_error':
print('rsync produced some errors, exit codes were:')
for line in status[1:]:
print(line)
exit(2)
elif exitcode == 'hook':
print('run-parts /etc/backup-pre-hook.d failed with exit code {}'.format(status[1]))
exit(2)
elif exitcode == 'abort_no_key':
print('no ssh key found in /etc/backup.priv!')
exit(1)
else:
# garbage in file
for line in status:
print(line)
exit(3)