Files
wizwar6e/deploy/wizwar-backup.sh
T
Eric WagonerandClaude Fable 5.1 636d97d5c1 The nightly rollup and backup say by their exit status whether they managed, and the deploy leaves the cron file off a host the hall schedules
On the shared host the hall's hall-nightly.sh (game-kit, gamehall/ops) runs
both scripts for every game and checks in with Sentry Crons once for all,
so this game's own check-in files are absent there and its exit status is
the word. A box of its own keeps its cron and check-ins as before.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-12 10:07:06 -04:00

51 lines
1.9 KiB
Bash
Executable File

#!/bin/bash
# Nightly wiz-war ledger backup to DigitalOcean Spaces.
# current/ - exact mirror of /var/lib/wizwar
# snapshots/ - one dated copy per day, pruned after 90 days
# Ledgers are append-only JSONL; the game server never needs stopping.
set -u
BUCKET="kestrel-wizwar-backups"
SRC="/var/lib/wizwar"
LOG="/var/log/wizwar/backup.log"
STAMP=$(date +%Y-%m-%d)
# Sentry Crons check-in: /root/.wizwar-sentry-cron holds the check-in URL
# (auto-creates the monitor on first ping). Absent file = no check-ins.
# On a host the hall shares, hall-nightly.sh runs this and checks in once
# for every game, so the file is absent and the exit status is the word.
CRON_URL=$(cat /root/.wizwar-sentry-cron 2>/dev/null || true)
# One check-in, when the run ends, carrying its duration: a start and a
# finish sent seconds apart can reach Sentry in either order, and a start
# that lands second is never closed. A run that never ends sends nothing,
# and Sentry marks the night missed.
START=$SECONDS
checkin() { [ -n "$CRON_URL" ] && curl -sf -o /dev/null "$CRON_URL?status=$1&duration=$((SECONDS - START))" || true; }
if grep -q CHANGE_ME /root/.config/rclone/rclone.conf; then
echo "$(date -Is) skipped: Spaces credentials not configured yet" >> "$LOG"
exit 1
fi
status=0
{
echo "=== $(date -Is) backup start"
if rclone sync "$SRC" "spaces:$BUCKET/wizwar/current" 2>&1 &&
rclone copy "$SRC" "spaces:$BUCKET/wizwar/snapshots/$STAMP" 2>&1; then
checkin ok
else
checkin error
status=1
fi
# Prune dated snapshots older than 90 days (by directory name).
CUTOFF=$(date -d "90 days ago" +%Y-%m-%d)
rclone lsf "spaces:$BUCKET/wizwar/snapshots/" --dirs-only 2>/dev/null | \
while read -r d; do
day="${d%/}"
if [[ "$day" < "$CUTOFF" ]]; then
echo "pruning snapshot $day"
rclone purge "spaces:$BUCKET/wizwar/snapshots/$day" 2>&1
fi
done
echo "=== $(date -Is) backup done"
} >> "$LOG"
exit $status