Backups with Restic on AWS: Setup, Restore, and Retention
Backing up is easy to put off until the one day you need it. This guide shows a simple, reliable way to push encrypted backups to AWS S3 with restic, how to restore files quickly, and how to keep retention predictable so storage and bills do not creep up. The approach works on a Raspberry Pi or a full server and needs no database or extra services.
Why restic on S3
- Encryption by default. Backups are encrypted client side with your password before they leave the machine.
- Incremental forever. Restic stores deduplicated snapshots so daily runs are fast.
- Portable. A few environment variables and a single binary are enough to use it anywhere.
- No vendor lock. You can point the same setup at any S3 compatible storage in the future.
Prerequisites
- An S3 bucket in your preferred region.
- An IAM user with access only to that bucket.
- The restic binary on your machine.
Install restic on Debian or Ubuntu:
|
|
Minimal IAM policy
Create an IAM user and attach a policy that limits access to the one bucket and its objects. Replace YOUR-BUCKET
and YOUR-REGION
.
|
|
Create access keys for that user and store them as secrets on the host.
Environment setup
Restic reads credentials and the repository from environment variables. Add these to /etc/restic.env
with root only permissions.
|
|
Paste:
|
|
Load the file when you run restic:
|
|
Tip: if you use a non AWS provider or a custom endpoint, change RESTIC_REPOSITORY
to s3:https://YOUR-ENDPOINT/YOUR-BUCKET
.
Initialize the repository
Run this once to create the repository structure in S3:
|
|
If it succeeds, the bucket now contains a config
object and the repo is ready.
First backup
Decide what to include and what to skip. Create exclude rules in /etc/restic-excludes.txt
:
*.tmp
*.cache
node_modules
venv
.DS_Store
lost+found
Run a test backup with verbose output:
|
|
You can back up any path: home directories, config folders, and data mounts. Use tags to mark the snapshot with a host or schedule.
List snapshots:
|
|
Verify integrity:
|
|
Schedule backups
Use a simple cron job, or systemd timers if you prefer.
Cron example (daily at 01:30):
|
|
Systemd timer (daily at 01:30):
Create /etc/systemd/system/restic-backup.service
:
|
|
Create /etc/systemd/system/restic-backup.timer
:
|
|
Enable:
|
|
Retention policy
Restic keeps everything until you tell it what to forget. A common policy is:
- keep the last 7 daily
- keep 4 weekly
- keep 12 monthly
Apply it with pruning to remove unused data:
|
|
Run this weekly from cron or add a second timer, for example every Sunday at 02:15:
|
|
You can keep different policies by tag. For example, weekly photos could use a longer window:
|
|
Check space usage before and after pruning:
|
|
Restoring data
List snapshots and pick the one you want:
|
|
Restore a single file or folder to a safe location:
|
|
Restore a full path from a specific snapshot ID:
|
|
Search within snapshots:
|
|
Diff two snapshots to see what changed:
|
|
When you finish a restore, move files back into place using rsync
so permissions and timestamps survive:
|
|
Cost control tips
- Lifecycle rules. In the S3 console, set a rule to transition old objects to Glacier Instant Retrieval after 30 days if restores are rare. Do not use Deep Archive unless you are comfortable with hours of retrieval delay.
- One bucket per policy. If different data sets need different lifecycle rules, use separate buckets.
- Forget first, then prune. The
forget --prune
combo reclaims space and keeps the repo tidy. - Avoid
latest
on critical restores. Name a snapshot ID to avoid surprises if a backup runs mid process.
Disaster recovery drill
Once a quarter, simulate a fresh machine:
|
|
Check that the data you expect is there. A five minute drill buys peace of mind.
Security notes
- The RESTIC_PASSWORD is the only way to decrypt. Store it in a password manager and print a sealed copy if needed.
- Restrict the IAM user to only your bucket. Avoid wildcards across accounts.
- Rotate access keys periodically and test after rotation.
- Use
restic key list
andrestic key add
if you need a second password for a trusted operator.
Quick commands recap
|
|
That is a full loop: encrypted backups to S3, simple restores, and a retention policy you can explain. It is small, dependable, and easy to move to another S3 compatible provider later if needed.
Thanks for reading. If you have a clean retention pattern for mixed daily and weekly jobs, share it so others can try it too.