Automated Backups with Restic: Set and Forget
Restic is an open-source backup tool that's fast, encrypted, and supports every cloud storage provider. Here's how to set it up.
What Is Restic?
Restic is a modern backup program that's fast, secure, and efficient. It encrypts all backups, deduplicates data automatically, and supports dozens of storage backends.
Why Restic?
Encryption
All backups are encrypted by default with AES-256. Even if someone accesses your backup storage, they can't read the data.
Deduplication
Restic only stores new or changed data. If you backup 10 GB daily but only 100 MB changes, each backup adds only 100 MB to storage.
Multiple Backends
Store backups on:
Snapshots
Each backup creates a snapshot. Browse any snapshot to find files as they were at that point in time.
Setting Up Restic for Self-Hosted Apps
Initialize a Repository
restic init --repo s3:s3.amazonaws.com/my-backups
Backup a Directory
restic backup /path/to/data --repo s3:s3.amazonaws.com/my-backups
Backup a Database
pg_dump mydb | restic backup --stdin --stdin-filename db.sql --repo s3:...
Schedule with Cron
Run backups automatically:
0 3 * * * restic backup /data --repo s3:...
Prune Old Snapshots
Keep the last 7 daily, 4 weekly, and 12 monthly snapshots:
restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 12 --prune
Restore from Backup
List Snapshots
restic snapshots --repo s3:...
Restore Everything
restic restore latest --target /restore --repo s3:...
Restore Specific Files
restic restore latest --target /restore --include /path/to/file --repo s3:...
Cost
Restic itself is free. Storage costs depend on your backend:
For most self-hosted setups, backups cost $1-5/month.