backup: freshness check — alert when last backup is older than 26h (Tanda B, point 4)
ci / lint-test-leaks (pull_request) Canceled after 0s
ci / lint-test-leaks (pull_request) Canceled after 0s
/usr/local/bin/cayce-check-backup-freshness (from deploy/backup/check-freshness.sh): exits 1 if the newest /var/backups/cayce/YYYY-MM-DD/ dir has mtime older than 26h, or if no backups exist while the age recipient IS configured (backups expected). Info-exit-0 when backups have never been configured. Not attached to a timer (only cayce-backup.timer was authorized); documented for manual or cron use. Verified: fresh dir => OK 0h exit 0; dir with 2-day mtime => ALERT 48h exit 1; no-dir + recipient => ALERT; no-dir + no-recipient => INFO.
This commit is contained in:
Executable
+33
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env bash
|
||||
# check-backup-freshness — alert if the newest backup is older than 26h.
|
||||
#
|
||||
# Exit 0 = fresh (or no backups ever made and NONE expected yet)
|
||||
# Exit 1 = stale: last backup dir older than MAX_HOURS, or no dir at all
|
||||
# while the age recipient is configured (backups should exist).
|
||||
#
|
||||
# Wire it anywhere you like (cron, another timer, or run manually from the
|
||||
# Mac after the daily pull). Not attached to any timer by itself — the only
|
||||
# authorized timer in Tanda B is cayce-backup.timer.
|
||||
set -euo pipefail
|
||||
|
||||
BACKUP_ROOT="/var/backups/cayce"
|
||||
MAX_HOURS=26
|
||||
RECIPIENT_FILE="/etc/cayce-backup/age-recipient.pub"
|
||||
|
||||
newest="$(find "$BACKUP_ROOT" -mindepth 1 -maxdepth 1 -type d -name "2*-*-*" 2>/dev/null | sort | tail -1 || true)"
|
||||
|
||||
if [[ -z "$newest" ]]; then
|
||||
if [[ -f "$RECIPIENT_FILE" ]]; then
|
||||
echo "ALERT: no backups exist although the age recipient is configured" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "INFO: no backups yet (age recipient not configured) — nothing to alert"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
hours=$(( ( $(date +%s) - $(stat -c %Y "$newest") ) / 3600 ))
|
||||
if (( hours > MAX_HOURS )); then
|
||||
echo "ALERT: last backup ($newest) is ${hours}h old (max ${MAX_HOURS}h)" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "OK: last backup ($newest) is ${hours}h old"
|
||||
Reference in New Issue
Block a user