Skip to content

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.

Terminal window
docker compose exec postgres pg_dump -U postgres theterms > backup-$(date +%Y%m%d-%H%M%S).sql

This creates a plain SQL dump in your current directory.

Terminal window
docker compose exec -T postgres psql -U postgres theterms < backup-2026-01-01-120000.sql

Create /usr/local/bin/theterms-backup.sh:

#!/bin/bash
BACKUP_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 backups
find "$BACKUP_DIR" -name "*.sql.gz" -mtime +30 -delete

Make it executable and add a cron job:

Terminal window
chmod +x /usr/local/bin/theterms-backup.sh
crontab -e

Add this line to run daily at 2 AM:

0 2 * * * /usr/local/bin/theterms-backup.sh >> /var/log/theterms-backup.log 2>&1

As an alternative or supplement, back up the Docker volume directly:

Terminal window
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.

WhatFrequencyRetention
PostgreSQL dumpDaily30 days
Docker volume backupWeekly4 weeks
Off-site copyDaily7 days minimum

Store backups off-site (S3, Backblaze B2, or another server) for disaster recovery.