backup-patternslisted
Install: claude install-skill ku5ic/dotfiles
# Backup Patterns
Review checklist and the choices that are expensive to get wrong. Flag tables for `pg_dump`, `rsync`, and `restic` are in their man pages.
## 3-2-1
Three copies, two media, one offsite. A backup that lives only on the same server as the data is not a backup.
## Choices that matter
- **`pg_dump -F c`** (custom) or **`-F d`** (directory) for anything over a few hundred MB. Only these support `-j` parallel restore; `-F p` plain SQL is the slowest both ways.
- **`pg_dumpall`** when you need roles and tablespaces, not just one database's contents.
- **Pipe rather than stage**: `pg_dump -F c mydb | restic -r <repo> backup --stdin --stdin-filename mydb.dump` avoids a plaintext temp file entirely.
- **`rsync --delete`** mirrors exactly - it deletes destination files missing from the source. Dry-run with `-n` before the first real run.
- **restic retention** is `forget --keep-daily/--keep-weekly/--keep-monthly --prune`. Without it, storage grows unboundedly. `--dry-run` first.
## Restore testing
A backup never tested is not a backup. On a schedule:
1. Restore to a separate location (`/tmp/restore`, a staging server).
2. Verify integrity - row counts, application startup, spot checks.
3. Record the restore duration, so the RTO is known before an incident rather than during one.
---
## Anti-patterns
**failure: backup stored only on the same server as the data**
A hardware failure, ransomware infection, or accidental `rm -rf` destroys both. The offsite copy i