backup-patterns
Skill2 starsChanged 8 days agoMITView on GitHub
Backup patterns for Linux servers and applications covering the 3-2-1 rule, rsync file backups, PostgreSQL dumps with pg_dump, encrypted backups with restic, retention policies, and restore testing. Use whenever the project contains shell scripts using pg_dump, rsync, or restic, a Brewfile or requirements file with restic or pgbackup tooling, cron job definitions for backups, or backup-related systemd units, OR the user asks about backups, disaster recovery, data retention, pg_dump, rsync, or restic, even if "backup" is not mentioned by name.
- Deletes or force-pushes
In this repository37 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- templates/CLAUDE.mdCLAUDE.md
- auditSkill
- bash-patternsSkill
- depsSkill
- django-patternsSkill
- docker-patternsSkill
- drf-patternsSkill
- engineering-fundamentalsSkill
- fastapi-patternsSkill
- git-patternsSkill
- go-patternsSkill
- graphql-patternsSkill
- investigateSkill
- javascript-patternsSkill
- logging-patternsSkill
- referenceSkill
- metaSkill
- monitoring-patternsSkill
- next-app-router-patternsSkill
- nuxt-patternsSkill
- opentofu-patternsSkill
- prSkill
- python-patternsSkill
- react-patternsSkill
- report-formatSkill
- security-patternsSkill
- slop-patternsSkill
- storybook-patternsSkill
- tailwind-patternsSkill
- test-patternsSkill
- typescript-patternsSkill
- unslopSkill
- vps-provisioningSkill
- vue-patternsSkill
- wcag-auditSkill
- writeSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 25
pg_dumpall: when you need roles and tablespaces, not just one database's contents. - Distinctive: line 35
Verify integrity: row counts, application startup, spot checks.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
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-jparallel restore;-F pplain SQL is the slowest both ways.pg_dumpallwhen you need roles and tablespaces, not just one database's contents.- Stream rather than stage:
restic -r <repo> backup --stdin-filename mydb.dump --stdin-from-command -- pg_dump -F c mydbavoids a plaintext temp file, and restic cancels the backup ifpg_dumpexits non-zero. A plainpg_dump | restic backup --stdinpipe cannot detect a truncated dump. rsync --deletemirrors exactly: it deletes destination files missing from the source. Dry-run with-nbefore the first real run.- restic retention is
forget --keep-daily/--keep-weekly/--keep-monthly --prune. Without it, storage grows unboundedly.--dry-runfirst.
Restore testing
A backup never tested is not a backup. On a schedule:
- Restore to a separate location (
/tmp/restore, a staging server). - Verify integrity: row counts, application startup, spot checks.
- 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 in 3-2-1 exists for exactly this case.
failure: backup never tested with a restore A corrupted or incomplete backup discovered during an incident is worse than no backup, because it delays the decision to use other recovery options.
warning: plain SQL format for large databases
-F p is the slowest to dump and restore and cannot use -j parallel workers. Use -F c or -F d.
warning: pg_dump password in a shell script
PGPASSWORD=secret pg_dump ... leaks the password into process listings. Use ~/.pgpass or a PGSERVICE entry in pg_service.conf.
warning: restic password in the crontab or alongside the repo restic encryption is strong enough that a lost password means permanent data loss, and a password stored next to the data defeats the encryption. Keep it in a password manager or secret manager, and source it from a protected env file in cron, never inline.
info: no retention policy on backups
Without forget/prune, backup storage grows unboundedly. Define and automate retention from day one.
References
- https://restic.readthedocs.io/en/latest/
- https://www.postgresql.org/docs/current/app-pgdump.html
- https://www.postgresql.org/docs/current/app-pgrestore.html
Verify restic flags against the version you have installed; restic self-update keeps the binary current.
Version notes
Checked: 2026-09-26 against https://restic.readthedocs.io/en/stable/040_backup.html, https://github.com/restic/restic/releases, https://www.postgresql.org/support/versioning/
- restic 0.19.1 (2026-07-05): docs warn
--stdin"cannot detect if data read from stdin is complete"; streaming example switched to--stdin-from-command. PostgreSQL 18.6 current, 14 oldest supported.
Legacy (restic without --stdin-from-command)
The earlier example piped pg_dump -F c mydb | restic backup --stdin --stdin-filename mydb.dump. Only use it on a restic build that lacks --stdin-from-command, and add set -o pipefail plus a post-backup size or pg_restore --list check, since restic records whatever arrived on stdin.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

