#!/bin/sh # Hourly demo reset — restore DB from snapshot, purge uploads, bounce backend. set -e SNAPSHOT="${DEMO_SNAPSHOT_PATH:-/snapshot/demo_snapshot.sql.gz}" UPLOADS_DIR="${UPLOADS_DIR:-/uploads}" DB_URL="${DATABASE_URL}" BACKEND="${BACKEND_URL:-http://backend:8000}" echo "[$(date -u +%Y-%m-%dT%H:%M:%SZ)] Starting demo reset" # 1. Restore database from snapshot if [ ! -f "$SNAPSHOT" ]; then echo "ERROR: Snapshot not found at $SNAPSHOT — skipping reset" exit 1 fi gunzip -c "$SNAPSHOT" | psql --single-transaction -v ON_ERROR_STOP=1 "$DB_URL" echo " DB restored from snapshot" # 2. Purge uploaded files (attachments added by demo users) find "$UPLOADS_DIR" -type f -not -name ".gitkeep" -delete 2>/dev/null || true echo " Uploads purged" echo "[$(date -u +%Y-%m-%dT%H:%M:%SZ)] Demo reset complete"