dorfteich/deploy/backup/restore.sh
Claude Fable 5 8dbff86537
All checks were successful
CI / Lint, typecheck, test (push) Successful in 3m9s
CI / Build container images (push) Has been skipped
CD / Build and push images (push) Successful in 3m47s
CD / Deploy to Test (push) Successful in 8s
CD / Smoke tests against Test (push) Successful in 1m10s
CD / Promote to Int (push) Successful in 9s
CI / Auth e2e pack (push) Successful in 5m25s
CI / Import/export fidelity gate (push) Successful in 45s
Add backup sidecar: nightly dump, volume archive, prune, status, restore (#83)
New apps/backup service (ADR 0015): nightly pg_dump -Fc plus one tar of the
uploads/plugins volumes as a consistent restore set on a new backups volume,
retention prune that never removes the newest complete set, atomic
status.json for the readiness/admin consumers (#85/#86), and a failure mail
sent directly via nodemailer (the api may be the broken part) with de/en
texts in the shared mails catalog. BACKUP_RUN_ONCE=1 gives the on-demand
path; deploy/backup/restore.sh automates the documented restore runbook.
The pure secret-store helpers moved to @dorfteich/shared so the sidecar
resolves the wizard-written SMTP relay exactly like the api.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EwZ4jR4KFAPvpjWevfUGX1
2026-07-11 17:29:15 +02:00

41 lines
1.4 KiB
Bash
Executable File

#!/usr/bin/env sh
# Restore a nightly backup set (ADR 0015, operations.md §Backup & restore).
#
# Run from the stage directory (where docker-compose.yml and .env live):
# deploy/backup/restore.sh <backup-id> # e.g. 20260711-030000
#
# Steps (the documented runbook, automated): stop the app services (the db
# stays up — pg_restore needs it), replay the dump and the uploads/plugins
# archive through the backup sidecar image, start the stack, check /readyz.
set -eu
if [ $# -ne 1 ]; then
echo "usage: $0 <backup-id> (list sets: docker compose exec backup ls /backups)" >&2
exit 2
fi
backup_id="$1"
echo "Stopping app services (db keeps running) ..."
docker compose stop web api collab
echo "Restoring set ${backup_id} ..."
docker compose run --rm --no-deps backup node dist/restore.js "${backup_id}"
echo "Starting the stack ..."
docker compose up -d
api_port="$(docker compose port api 3000 2>/dev/null | head -n1)"
if [ -n "${api_port}" ]; then
echo "Waiting for readiness on ${api_port} ..."
for _ in $(seq 1 30); do
if curl -sf "http://${api_port}/api/v1/readyz" >/dev/null 2>&1; then
echo "Restore complete — /readyz is green. Spot-check a page and a file."
exit 0
fi
sleep 2
done
echo "Restore applied, but /readyz did not turn green within 60 s — check 'docker compose logs api'." >&2
exit 1
fi
echo "Restore applied. Verify /readyz through your reverse proxy."