bundles/backup-client: rework backup generation
All checks were successful
kunsi/bundlewrap/pipeline/head This commit looks good

This commit is contained in:
Franzi 2022-01-07 08:29:34 +01:00
parent 4e5cb69d1c
commit 14e4415e5f
Signed by: kunsi
GPG key ID: 12E3D2136B818350
6 changed files with 159 additions and 107 deletions

View file

@ -1,42 +1,28 @@
#!/usr/bin/env python3
#!/bin/bash
from os.path import getmtime, isfile
from sys import exit
from time import time
statusfile="/var/tmp/backup.monitoring"
statusfile = '/var/tmp/backup.monitoring'
if not isfile(statusfile):
print('Status file not found')
exit(3)
if [[ ! -r "$statusfile" ]]
then
echo "cannot read $statusfile"
exit 3
fi
mtime = getmtime(statusfile)
now = time()
. "$statusfile"
if now-mtime > 60*60*24*2:
print('Status file is older than 2 days!')
exit(3)
if [[ -z "$msg" ]] || [[ -z "$status" ]] || [[ -z "$timestamp" ]]
then
echo "status file is corrupt, cannot read status"
exit 3
fi
with open(statusfile, 'r') as f:
status = f.read().splitlines()
two_days_ago=$(($(date +%s) - 86400*2))
exitcode = status[0].strip()
if [[ $timestamp -lt $two_days_ago ]]
then
echo "last saved status is older than two days"
exit 2
fi
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)
echo "$msg"
exit "$status"