#!/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 # 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 (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."