Database backups
1. What? — Definition and context
Section titled “1. What? — Definition and context”Every night at 3 AM, a script backs up the four PostgreSQL databases of the infrastructure, the Odoo filestore, and the N8N encryption key to Google Drive. If anything fails, an alert fires immediately through the Notification Hub.
What is backed up
Section titled “What is backed up”| Data | Source | Typical size |
|---|---|---|
| N8N database | n8n-stack PostgreSQL | ~500 MB |
Odoo database (guig_db) | odoo-stack PostgreSQL | ~200 MB |
| TimeTrackr database | timetrackr-stack PostgreSQL | ~10 MB |
| Odoo filestore | /var/lib/odoo/filestore/ | ~1 GB |
| N8N key | N8N_ENCRYPTION_KEY | A few bytes |
2. Why? — Stakes and motivations
Section titled “2. Why? — Stakes and motivations”Problems solved
Section titled “Problems solved”| Problem | Without auto backup | With auto backup |
|---|---|---|
| Data loss | DB corruption = everything gone | Restore from GDrive |
| Forgotten backups | ”When was the last one?” | Daily 3 AM cron |
| No retention | Local disk fills up | Local rotation 7 d, GDrive 30 d |
| Silent failure | Backup fails, nobody knows | Instant Telegram alert |
3. How? — Technical implementation
Section titled “3. How? — Technical implementation”Architecture
Section titled “Architecture”The backup-databases.sh script
Section titled “The backup-databases.sh script”The script is triggered by crontab at 3 AM (0 3 * * *). It runs in order:
- PostgreSQL dump —
pg_dumpof every database viadocker exec - Compression — gzip of the dumps
- Filestore copy — tar archive of the Odoo filestore
- N8N key export — extracts
N8N_ENCRYPTION_KEYfrom environment variables - GDrive upload —
rclone copyto the remote folder - Local rotation — deletes files older than 7 days
- GDrive rotation — deletes files older than 30 days
If a step fails, the script keeps going and sends an error notification to the Notification Hub at the end.
Retention policy
Section titled “Retention policy”| Storage | Retention | Rotation |
|---|---|---|
Local (/backups/) | 7 days | Daily script |
| Google Drive | 30 days | rclone delete --min-age 30d |
Verification
Section titled “Verification”# View the latest local backupsls -lh /backups/
# View the logstail -20 /var/log/backup-databases.log
# Check the cron entrycrontab -l | grep backup4. What if? — Perspectives and limits
Section titled “4. What if? — Perspectives and limits”Current limits
Section titled “Current limits”| Limit | Impact | Mitigation |
|---|---|---|
| No restore test | Issues surface at the worst possible moment | Monthly test planned |
| GDrive single point | If GDrive is down, no remote backup | Add a second provider (S3) |
| No incremental backup | Full dump every night | Acceptable at current volumes |
Evolution scenarios
Section titled “Evolution scenarios”If data volume grows:
- Switch to incremental backups (PostgreSQL WAL archiving)
- Compress with zstd instead of gzip (faster, better ratio)
If fast restoration is required:
- Automated restore script
- Weekly automatic restore test in an ephemeral container
Related pages
Section titled “Related pages”Infrastructure
Section titled “Infrastructure”- VPS Architecture — Stacks overview
- N8N in queue mode — N8N database backed up
- Odoo 18 on Docker — Odoo database backed up
Workflows
Section titled “Workflows”- Notification Hub — Failure alerts
- N8N export to GitHub — Complementary workflow backup