Backing up to Cloud Storage with Restic

Backups are boring until you lose data. Then, they are the most exciting thing in the world. Restic is a modern backup program that is fast, secure, and efficient. It dedupes data automatically, encrypts specifically, and supports almost every storage backend imaginable.

Restic Backup Workflow

Why Restic?

Step 1: Installation

# On Debian/Ubuntu
apt-get install restic

# On macOS
brew install restic

Step 2: Initialize Repository

Restic works with "repositories". This can be a local folder, SFTP server, or S3 bucket. Let's use an S3-compatible bucket (like AWS S3, MinIO, or Wasabi).

Export your credentials (avoid putting them in history by using a file or env var):

export AWS_ACCESS_KEY_ID="your-key"
export AWS_SECRET_ACCESS_KEY="your-secret"
export RESTIC_PASSWORD="strong-repo-password"
export RESTIC_REPOSITORY="s3:s3.amazonaws.com/my-backup-bucket"

# Initialize
restic init

Step 3: Backing Up

Running a backup is as simple as pointing restic to a directory:

restic backup /var/www /etc/nginx /home/user/data

Step 4: Automation

Don't rely on manual backups. Create a simple cron job or systemd timer.

# /etc/cron.daily/restic-backup
#!/bin/bash
source /root/.restic-env
restic backup /data --exclude-file=/root/.backup-exclude
restic forget --keep-last 7 --keep-daily 7 --keep-weekly 4 --keep-monthly 6 --prune

The forget command is crucial—it cleans up old snapshots according to your policy (e.g., keep last 7 days), and prune actually removes the unreferenced data from the storage to save money.

📡 Enjoyed this deep dive? Follow via Atom/RSS Feed
← Back to Blog