Add healthcheck

This commit is contained in:
Andras Schmelczer 2025-04-12 12:27:38 +01:00
parent 2f5d9b3ee2
commit 7d51230630
5 changed files with 34 additions and 3 deletions

View file

@ -3,7 +3,7 @@
KEEP_DAILY=${KEEP_DAILY:-6}
KEEP_WEEKLY=${KEEP_WEEKLY:-3}
KEEP_MONTHLY=${KEEP_MONTHLY:-48}
KEEP_YEARLY=${KEEP_YEARLY:-0}
KEEP_YEARLY=${KEEP_YEARLY:-10}
echo "Starting backup script at `date`"
@ -49,3 +49,4 @@ borg compact --threshold=5 --cleanup-commits --verbose --progress
btrfs subvolume delete /snapshot/source
echo "Finished backup script at `date`"
date > /backup_completion_time.log # this used by the healtcheck

17
src/healthcheck.sh Executable file
View file

@ -0,0 +1,17 @@
#! /bin/sh
set -e
if [ -f /backup_completion_time.log ]; then
current_time=$(date +%s)
backup_time=$(date --file /backup_completion_time.log +%s)
age_in_seconds=$((current_time - backup_time))
if [ ${age_in_seconds} -lt ${MAX_BACKUP_AGE_SECONDS} ]; then
echo "Backup completed within the last ${MAX_BACKUP_AGE_SECONDS} seconds. Healthcheck passed."
exit 0
fi
fi
echo "Backup not completed within the last ${MAX_BACKUP_AGE_SECONDS} seconds. Healthcheck failed."
exit 1