Backup & Restore
CleverThis's persistent state lives in two places: the PostgreSQL database (all application data) and the Redis store (transient session and rate limit data). Redis data does not need to be backed up — it is ephemeral. Only the PostgreSQL database requires backup.
What's in the database
The PostgreSQL database contains:
- User accounts and sessions
- Workspaces, namespaces, API keys
- Actor YAML definitions and deployments
- Usage records and billing history
- Invite codes and audit log
Creating a backup
Docker Compose
# Dump to a gzipped SQL file
docker compose exec postgres pg_dump \
-U cleverthis cleverthis | gzip > backup-$(date +%Y%m%d-%H%M%S).sql.gz
Store the backup file in a separate location (S3, a different server, etc.).
External PostgreSQL (RDS, Cloud SQL)
Use your provider's managed backup feature. For RDS, enable automated backups with a 7-day retention period. For Cloud SQL, enable point-in-time recovery.
For manual dumps:
pg_dump -h your-rds-host -U cleverthis cleverthis | gzip > backup-$(date +%Y%m%d).sql.gz
Restoring from backup
# Stop the API server to prevent writes during restore
docker compose stop api
# Drop and recreate the database
docker compose exec postgres psql -U cleverthis -c "DROP DATABASE cleverthis;"
docker compose exec postgres psql -U cleverthis -c "CREATE DATABASE cleverthis;"
# Restore
gunzip -c backup-20260721-120000.sql.gz | docker compose exec -T postgres psql -U cleverthis cleverthis
# Run migrations to ensure schema is up to date
docker compose start api
docker compose exec api alembic upgrade head
Backup schedule
For production deployments, automate daily backups with retention:
# Add to crontab (runs at 2am daily, retains 30 days)
0 2 * * * docker compose -f /opt/cleverthis/docker-compose.yml exec -T postgres pg_dump -U cleverthis cleverthis | gzip > /backups/cleverthis-$(date +\%Y\%m\%d).sql.gz && find /backups -name 'cleverthis-*.sql.gz' -mtime +30 -delete
Coming soon
A built-in backup job container (cronjob that dumps to S3 with configurable retention) is being added to the Docker Compose stack.