Backups
TheTerms stores all data in PostgreSQL. Redis is used for caching only — it can be rebuilt from PostgreSQL data and does not need to be backed up separately.
PostgreSQL Backup
Section titled “PostgreSQL Backup”Manual backup with pg_dump
Section titled “Manual backup with pg_dump”docker compose exec postgres pg_dump -U postgres theterms > backup-$(date +%Y%m%d-%H%M%S).sqlThis creates a plain SQL dump in your current directory.
Restore from backup
Section titled “Restore from backup”docker compose exec -T postgres psql -U postgres theterms < backup-2026-01-01-120000.sqlAutomated daily backups with cron
Section titled “Automated daily backups with cron”Create /usr/local/bin/theterms-backup.sh:
#!/bin/bashBACKUP_DIR="/opt/theterms-backups"COMPOSE_DIR="/opt/theterms" # path to your cloned repo
mkdir -p "$BACKUP_DIR"
docker compose -f "$COMPOSE_DIR/docker-compose.yml" exec -T postgres \ pg_dump -U postgres theterms \ | gzip > "$BACKUP_DIR/theterms-$(date +%Y%m%d-%H%M%S).sql.gz"
# Keep only the last 30 days of backupsfind "$BACKUP_DIR" -name "*.sql.gz" -mtime +30 -deleteMake it executable and add a cron job:
chmod +x /usr/local/bin/theterms-backup.shcrontab -eAdd this line to run daily at 2 AM:
0 2 * * * /usr/local/bin/theterms-backup.sh >> /var/log/theterms-backup.log 2>&1Docker Volume Backup
Section titled “Docker Volume Backup”As an alternative or supplement, back up the Docker volume directly:
docker run --rm \ -v theterms_postgres_data:/data \ -v $(pwd):/backup \ alpine tar czf /backup/postgres-volume-$(date +%Y%m%d).tar.gz -C /data .Redis is configured with --appendonly yes (AOF persistence). Data is written to the redis_data Docker volume. Since Redis only caches session data that can be reconstructed, you do not need to back up Redis.
If you stop and restart Redis, sessions will be invalidated and users will need to log in again.
Recommended Schedule
Section titled “Recommended Schedule”| What | Frequency | Retention |
|---|---|---|
| PostgreSQL dump | Daily | 30 days |
| Docker volume backup | Weekly | 4 weeks |
| Off-site copy | Daily | 7 days minimum |
Store backups off-site (S3, Backblaze B2, or another server) for disaster recovery.