Barazo Docker Compose templates for self-hosting
barazo.forum
1# Backup & Restore
2
3How to back up and restore your Barazo forum data.
4
5## What Gets Backed Up
6
7| Data | Backed up | Priority |
8|------|-----------|----------|
9| PostgreSQL (topics, replies, users, settings) | Yes | Critical |
10| Valkey (cache, sessions) | No | Low -- regenerated automatically |
11| Caddy (SSL certificates) | No | Medium -- re-obtained automatically by Let's Encrypt |
12| Tap (firehose cursor) | No | Low -- re-syncs from the relay |
13| Plugins | No | Medium -- reinstallable from npm |
14
15The backup script creates a PostgreSQL dump. This contains all forum data (topics, replies, users, categories, settings, moderation logs).
16
17## Creating Backups
18
19### Manual Backup
20
21```bash
22# Unencrypted (keep on server only)
23./scripts/backup.sh
24
25# Encrypted (safe to store off-server)
26./scripts/backup.sh --encrypt
27```
28
29Backups are saved to `./backups/` with filenames like `barazo-backup-20260214-020000.sql.gz`.
30
31### Automated Backups
32
33Add a cron job for daily backups:
34
35```bash
36crontab -e
37```
38
39```
40# Daily at 2 AM, encrypted
410 2 * * * cd /path/to/barazo-deploy && ./scripts/backup.sh --encrypt >> /var/log/barazo-backup.log 2>&1
42```
43
44### Backup Encryption
45
46Backups contain user content and potentially PII. Encrypt before storing off-server.
47
48**Setup age encryption:**
49
50```bash
51# Generate a keypair (do this once)
52age-keygen -o barazo-backup-key.txt
53
54# The public key is printed to the terminal -- add it to .env
55# BACKUP_PUBLIC_KEY="age1..."
56
57# Store the private key file securely (NOT on the same server)
58# You need this to decrypt backups
59```
60
61**Install age:**
62
63```bash
64# Ubuntu/Debian
65sudo apt install age
66
67# macOS
68brew install age
69```
70
71### Backup Retention
72
73By default, backups older than 7 days are automatically deleted. Change this with `BACKUP_RETAIN_DAYS` in `.env`:
74
75```bash
76BACKUP_RETAIN_DAYS=30 # Keep 30 days
77BACKUP_RETAIN_DAYS=0 # Never delete (manage manually)
78```
79
80## Restoring from Backup
81
82### Standard Restore
83
84```bash
85./scripts/restore.sh backups/barazo-backup-20260214-020000.sql.gz
86```
87
88### Encrypted Backup Restore
89
90```bash
91BACKUP_PRIVATE_KEY_FILE=/path/to/barazo-backup-key.txt \
92 ./scripts/restore.sh backups/barazo-backup-20260214-020000.sql.gz.age
93```
94
95### What the Restore Script Does
96
971. Stops the API and Web services (prevents writes during restore)
982. Drops and recreates the database
993. Restores the SQL dump
1004. Restarts the API and Web services
1015. Verifies the database has tables
102
103### After Restoring
104
105**GDPR compliance:** If the backup is older than the most recent data, you must re-apply deletions that occurred after the backup date. Check the `deletion_log` table for events after the backup timestamp.
106
107## Disaster Recovery
108
109If your server is completely lost:
110
1111. **Provision a new server** (same OS, Docker installed)
1122. **Clone the deploy repo** and copy your `.env` file
1133. **Start services:** `docker compose up -d`
1144. **Restore the database** from your most recent backup
1155. **Run the smoke test** to verify: `./scripts/smoke-test.sh https://your-domain.com`
116
117Caddy will automatically obtain a new SSL certificate. The Tap service will re-sync from the relay. Valkey cache will rebuild as users access the forum.
118
119## Verifying Backups
120
121Periodically verify that your backups are valid:
122
123```bash
124# List backup files
125ls -lh backups/
126
127# Test a backup by restoring to a separate database
128docker compose exec postgres psql -U barazo -d postgres \
129 -c "CREATE DATABASE barazo_test;"
130gunzip -c backups/barazo-backup-LATEST.sql.gz \
131 | docker compose exec -T postgres psql -U barazo -d barazo_test -q
132docker compose exec postgres psql -U barazo -d barazo_test \
133 -c "SELECT count(*) FROM information_schema.tables WHERE table_schema = 'public';"
134docker compose exec postgres psql -U barazo -d postgres \
135 -c "DROP DATABASE barazo_test;"
136```