Backups and restore
Automated backups of PostgreSQL and SeaweedFS with restic, and how to run a restore drill.
Cluster provides backup and restore scripts in scripts/backup/ that back up both the PostgreSQL database and the SeaweedFS object storage bucket to an encrypted off-server restic repository.
What is backed up
- PostgreSQL database: dumped with
pg_dump -FcasPOSTGRES_USERfrom thepostgrescontainer. - Object storage bucket: synced with
rclonefrom a container sharing thestoragenetwork. - Encrypted off-server archive: both are uploaded together using
restic backupwith retention of 7 daily, 4 weekly, and 6 monthly snapshots.
Never dump the database with the application role or with --enable-row-security: that produces an empty dump of all organization tables. Always keep a copy of your .env file in a password manager outside the server—without AUTH_SECRET_KEY, users cannot recover their 2FA secrets.
One-time setup
- Install
docker,flock,curl, andresticon the server. - Initialize an off-server
resticrepository (restic init) and store its password outside the server as well. - Create
/etc/cluster-backup.env(mode600) with your repository target (RESTIC_REPOSITORY), password file (RESTIC_PASSWORD_FILE), working directory (BACKUP_DIR, default/var/backups/cluster),STORAGE_BUCKETmatching.env, and optionally BACKUP_PING_URL for dead-man's-switch alerts.
Scheduling
Run the backup daily and verify backup age hourly via cron:
0 3 * * * cd <cluster-dir> && set -a && . /etc/cluster-backup.env && set +a && scripts/backup/backup.sh >> /var/log/cluster-backup.log 2>&1
17 * * * * cd <cluster-dir> && set -a && . /etc/cluster-backup.env && set +a && scripts/backup/check-backup-age.sh || echo "backup overdue on $(hostname)"
Once a month, verify repository integrity with restic check --read-data-subset=5%.
Restore drill
Run a full restore drill on a separate clean machine before inviting users:
- Prepare a clean machine with Docker,
restic, the matching release tag, your.env, and/etc/cluster-backup.env. - Start only the database and storage services:
docker compose build migrate && docker compose up -d --wait postgres storage. - Run
scripts/backup/restore.sh(orrestore.sh <snapshot-id>). It restores the database asPOSTGRES_USER, recreates the application and system roles, runsmigrate, and copies the bucket back. - Run
docker compose up -d. Wait untildocker compose psreports all serviceshealthy. - Sign in, open a KNOW page with an image, play and seek a GROW video lesson, and verify a certificate at
/verify/<code>.