Backups are one of those things you don't think about until you need them—and by then, it's too late. Restic is a modern, fast, and secure backup program that's easy to use. Let's set it up.
Why Restic?
- Fast and efficient deduplication
- Encrypted backups
- Easy to use
- Supports many backends (local, S3, B2, etc.)
Installing Restic
sudo apt install restic
# or download from https://github.com/restic/restic/releases
Setting Up a Repository
Local Backup Location
mkdir -p /backups
restic init --repo /backups
Set a password when prompted.
S3-Compatible Storage
export AWS_ACCESS_KEY_ID=your_key
export AWS_SECRET_ACCESS_KEY=your_secret
restic -r s3:https://s3.amazonaws.com/bucket-name init
Running Backups
restic -r /backups backup /home
restic -r /backups backup /etc
restic -r /backups backup /var/www
Automating Backups
#!/bin/bash
export RESTIC_PASSWORD=your_password
restic -r /backups backup /home /etc /var/www --exclude-caches
restic -r /backups forget --keep-daily 7 --keep-weekly 4 --keep-monthly 6
chmod +x /usr/local/bin/backup.sh
# Add to crontab
crontab -e
0 2 * * * /usr/local/bin/backup.sh
Restoring Backups
restic -r /backups snapshots
restic -r /backups restore latest --target /restore
Never lose your data again!