From 3dcdf504983b22f383b1d28cdc606558809a3f6e Mon Sep 17 00:00:00 2001 From: Eric Wagoner Date: Mon, 17 Aug 2026 23:15:28 -0400 Subject: [PATCH] Nightly ledger backup to DO Spaces (deploy/wizwar-backup.sh) Installed on the droplet at /usr/local/bin/wizwar-backup.sh, cron 07:17 UTC daily: mirrors /var/lib/wizwar to spaces:kestrel-wizwar-backups/ wizwar/current and keeps 90 days of dated snapshots. Ledgers are append-only, so no service stop is needed. The script no-ops with a log line until Spaces credentials land in /root/.config/rclone/ rclone.conf. Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_0138A8CjeQRpvzKxuMfz1Bqc --- deploy/wizwar-backup.sh | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 deploy/wizwar-backup.sh diff --git a/deploy/wizwar-backup.sh b/deploy/wizwar-backup.sh new file mode 100755 index 0000000..9cf5caf --- /dev/null +++ b/deploy/wizwar-backup.sh @@ -0,0 +1,32 @@ +#!/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) + +if grep -q CHANGE_ME /root/.config/rclone/rclone.conf; then + echo "$(date -Is) skipped: Spaces credentials not configured yet" >> "$LOG" + exit 0 +fi + +{ + echo "=== $(date -Is) backup start" + rclone sync "$SRC" "spaces:$BUCKET/wizwar/current" 2>&1 + rclone copy "$SRC" "spaces:$BUCKET/wizwar/snapshots/$STAMP" 2>&1 + # 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"