#!/usr/bin/env bash # pre-backup hook for esh-ml1 — deployed to /etc/restic/pre-backup.sh (root, 0755). # # Takes an online-consistent copy of augaman's face gallery with augaman's own # backup CLI (SQLite backup API, integrity_check, atomic rename, mode 0600) into # /var/lib/restic/stage/augaman/gallery.db, which restic then snapshots. # # FAIL-CLOSED. Any failure exits non-zero, which makes resticprofile abort the # run: no snapshot, no last-success stamp, and the fleet freshness check alerts. # That includes the augaman container being stopped. A gallery that is not being # backed up must be loud, not a quietly stale file in every snapshot. set -euo pipefail STAGE_FILE=/var/lib/restic/stage/augaman/gallery.db MAX_AGE_S=300 if ! out=$(docker exec augaman python -m augaman.gallery.backup \ --db /data/gallery.db --dest /backup/gallery.db 2>&1); then echo "pre-backup: augaman gallery backup FAILED: ${out}" >&2 exit 1 fi echo "pre-backup: augaman gallery backup: ${out}" # The CLI said it succeeded; confirm the file restic is about to read is the # one it just wrote (non-empty, and written within the last few minutes). if [ ! -s "$STAGE_FILE" ]; then echo "pre-backup: ${STAGE_FILE} is missing or empty after a successful CLI run" >&2 exit 1 fi age=$(( $(date +%s) - $(stat -c %Y "$STAGE_FILE") )) if [ "$age" -gt "$MAX_AGE_S" ]; then echo "pre-backup: ${STAGE_FILE} is ${age}s old; the CLI did not refresh it" >&2 exit 1 fi