Restic + S3: Encrypted Backups Your Provider Can't Read

Restic + S3: Encrypted Backups Your Provider Can't Read

Every few months, a storage provider updates its privacy policy and users start asking what the company can see. This week it was Backblaze's turn to reassure customers after a policy change caused concern. Backblaze says it doesn't sell personal information. Still, "what does my provider do with my data?" is a question you shouldn't have to depend on.

The better setup is one where the answer doesn't matter: your backups are encrypted on your server before they leave it, and the storage provider only ever holds data it can't read. Here's how to do that with restic and an S3 bucket, in about twenty minutes.

Why restic

restic is an open-source backup tool with one property that makes it perfect for this: it always encrypts. There's no "encryption off" mode. Every repository is protected by a password, data is encrypted and authenticated before it's uploaded, and the storage backend sees only opaque chunks.

It also deduplicates, so the second backup of a 50 GB server only uploads what changed, and it speaks S3 natively. The current release is v0.20.0, from November 19.

Pick Your Bucket

Any S3-compatible storage works. Two options on Elestio:

Option Good for Cost
Elestio Object Storage Most people: a managed bucket in minutes, in Europe, the US or Asia $0.02 per GB per month, no fees for data going out
Your own Garage or RustFS instance Teams that want the storage server itself under their control From $16/month for the VM, plus disk

The "no fees for data going out" part matters more for backups than for anything else. Egress is what you pay on the worst day: when you restore everything after a disaster. With Elestio Object Storage, that restore costs nothing extra.

To create a bucket, open Object Storage in the Elestio dashboard, pick a region and a name, and copy the access key and secret. The secret is shown once, so store it right away.

Step 1: Set Up the Repository

Install restic from your distribution's packages or the release page, then put the settings in a root-only environment file:

# /root/.restic.env  (chmod 600)
export AWS_ACCESS_KEY_ID="your-access-key"
export AWS_SECRET_ACCESS_KEY="your-secret-key"
export AWS_DEFAULT_REGION="auto"
export RESTIC_REPOSITORY="s3:https://storage.elestio.com/your-bucket-name"
export RESTIC_PASSWORD_FILE="/root/.restic-password"

Generate a strong repository password and initialize:

openssl rand -base64 32 > /root/.restic-password
chmod 600 /root/.restic-password /root/.restic.env
source /root/.restic.env
restic init

Stop and copy that password somewhere safe now, outside this server: a password manager or a sealed envelope. Without it, your backups can't be decrypted by anyone, including you. That's the whole point, and also the one way to lose everything.

For Garage or RustFS, use your instance's S3 endpoint in RESTIC_REPOSITORY and its region (Garage's default is garage).

Step 2: Back Up the Right Things

Copying a live database's files rarely gives you a backup you can restore. Dump databases first, then back up the dump alongside your files:

#!/bin/sh
# /usr/local/bin/backup.sh
set -e
. /root/.restic.env

mkdir -p /var/backups/db
docker exec my-postgres pg_dumpall -U postgres > /var/backups/db/postgres.sql

restic backup /opt/app /var/backups/db \
  --exclude-caches --tag nightly

restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 12 --prune

Replace my-postgres with your database container's name. The forget line keeps a week of dailies, a month of weeklies and a year of monthlies, and deletes the rest.

Schedule it with cron, using flock so two runs never overlap:

15 3 * * * flock -n /tmp/backup.lock /usr/local/bin/backup.sh >> /var/log/backup.log 2>&1

Step 3: Prove You Can Restore

A backup you've never restored is a hope, not a backup. Two habits:

# Weekly: verify a random 5% of the stored data
restic check --read-data-subset=5%

# Monthly: restore the latest snapshot somewhere harmless
restic restore latest --target /tmp/restore-test

Open a few restored files and load the database dump into a test container. That's the test that counts.

What the Provider Can Still See

Honesty check: encryption hides contents, not everything. The storage provider still sees how much you store, when you upload, and from which IP address. It can't see file names, file contents or your directory structure. For most threat models, that's exactly the line you want.

Running It on Elestio

If you're backing up Elestio services, you already have automated backups included. Adding restic to an Elestio Object Storage bucket gives you a second, independent copy that's encrypted with a key only you hold, which is the classic "3-2-1" rule in practice. At $0.02 per GB per month, 100 GB of encrypted backups costs about $2 a month in storage, plus requests.

Troubleshooting

Fatal: unable to open config file or 403 Forbidden. The keys, bucket name or endpoint are wrong. Check that RESTIC_REPOSITORY uses the full bucket name, including the suffix Elestio adds.

Region errors. Set AWS_DEFAULT_REGION=auto for Elestio Object Storage, or your Garage or RustFS instance's own region.

wrong password or no key found. The password file doesn't match the repository. There's no reset: find the original password.

The first backup is slow, later ones are fast. That's deduplication. Only changed data is uploaded after the first run.

The repository is locked. A previous run was interrupted. Make sure no backup is running, then run restic unlock.

Thanks for reading ❤️ See you in the next one 👋