# How do I back up with restic to S3?

> Back up a Linux server with restic to an S3-compatible bucket in 7 steps: init, backup, schedule, restore test, prune. From the restic manual.

- URL: https://privates3.com/guides/how-to-back-up-with-restic-to-s3/
- Last updated: 2026-11-17
- Publisher: PrivateS3 (https://privates3.com)

**Quick answer — How do I back up with restic to S3?**

Export the bucket's access key, secret key and region, point `RESTIC_REPOSITORY` at `s3:https://endpoint/bucket`, run `restic init`, then `restic backup` on a schedule. Test a restore and prune old snapshots. On a **PrivateS3** bucket the whole setup takes 7 steps, and storage costs $2.23/TB-month on 12 months.

**In brief**

- **You need**: restic installed, a bucket with its key pair, and a password you will never lose.
- **Time**: about 15 minutes, plus the first upload.
- **Result**: encrypted, deduplicated snapshots every night, kept 7 days, 5 weeks and 12 months.
- **Values**: the endpoint and region are shown with the keys in the client area; examples use `https://s3.privates3.com` and `eu-central-1`.

## Which restic commands does this guide use?

*The restic commands in this guide, what each does, and when to run it*

| Command | What it does | When |
| --- | --- | --- |
| `restic init` | Creates the encrypted repository in the bucket | Once |
| `restic backup` | Uploads changed data as a new snapshot | Every night |
| `restic snapshots` | Lists snapshots | After each change of setup |
| `restic restore` | Writes a snapshot back to disk | Once a month as a test |
| `restic forget --prune` | Drops old snapshots and frees space | Weekly |
| `restic check` | Verifies the repository's structure | After each prune |

## Step 1–2: how do you store the keys and password safely?

**Put them in a root-only file, then load it before each restic command.** The restic manual, read on 17 November 2026, takes S3 keys from `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`, the region from `AWS_DEFAULT_REGION`, and the server from a repository URL of the form `s3:https://server:port/bucket_name`.

The repository password goes in a second file. Restic's manual is blunt: losing it means the data is lost for good. Copy it to a password manager now. The keys come from the client area once the bucket is ready; the [access keys help page](https://privates3.com/help/get-your-access-keys/ "How do I get my PrivateS3 access keys?") shows where.

*/root/.restic-env (chmod 600)*

```bash
export AWS_ACCESS_KEY_ID=ACCESS_KEY
export AWS_SECRET_ACCESS_KEY=SECRET_KEY
export AWS_DEFAULT_REGION=eu-central-1
export RESTIC_REPOSITORY=s3:https://s3.privates3.com/BUCKET/restic
export RESTIC_PASSWORD_FILE=/root/.restic-password
```

## Step 3–4: how do you create the repository and run the first backup?

**Load the file, run `restic init` once, then `restic backup` with the folders to save.** Init writes the repository's encrypted config and keys into the bucket. The first backup uploads everything; later runs send only changed chunks.

Dump databases first so the backup holds a consistent copy, and exclude caches with an exclude file.

*Create the repository and back up*

```bash
. /root/.restic-env
restic init

mysqldump --all-databases > /root/db-dumps/all.sql
restic backup /etc /var/www /root/db-dumps --exclude-file=/root/.restic-excludes
restic snapshots
```

## Step 5: how do you run the backup every night?

**With a cron job that loads the file, backs up, then prunes once a week.** Write a small script and call it from root's crontab. The forget policy below follows the example in restic's manual on removing snapshots: daily, weekly and monthly snapshots kept for set counts.

*/root/restic-nightly.sh and the crontab line*

```bash
#!/bin/sh
set -e
. /root/.restic-env
restic backup /etc /var/www /root/db-dumps --exclude-file=/root/.restic-excludes
if [ "$(date +%u)" = 7 ]; then
  restic forget --keep-daily 7 --keep-weekly 5 --keep-monthly 12 --prune
  restic check
fi

# crontab -e (root)
30 2 * * * /root/restic-nightly.sh >> /var/log/restic.log 2>&1
```

## Step 6: how do you test a restore?

**Restore the latest snapshot into a scratch folder and compare a few files.** The restic manual shows `restic restore` with a snapshot ID or `latest` and a `--target` folder; `--include` limits the restore to one path. A backup never restored is a guess, so repeat this every month.

*Restore test*

```bash
. /root/.restic-env
restic restore latest --target /tmp/restore --include /etc/nginx
diff -r /etc/nginx /tmp/restore/etc/nginx && echo restore-ok
```

## Step 7: how do you protect the backups from deletion?

**Turn on bucket versioning, or ask for Object Lock, so a compromised server cannot erase history.** Restic's design document says it does not protect against deletion at the storage location. At PrivateS3, versioning is self-service: S3 versioning can be turned on per bucket from any S3 client; old versions count toward the quota. Locking is not: Object Lock (immutable backups) is set on a new bucket on request through a support ticket.

Versioning keeps deleted pack files as old versions, which also count toward the quota. The [versioning guide](https://privates3.com/guides/how-to-turn-on-s3-versioning/ "How do I turn on S3 versioning?") covers the command and a cleanup rule. According to PrivateS3's survey of 17 November 2026, Wasabi bills deleted data until day 90 and Storj until day 30; PrivateS3 has no minimum storage duration, so the weekly prune frees quota at once.

## restic to S3: common questions

### Restic says the repository already exists. What now?

The bucket path already holds a repository. Use a new folder in `RESTIC_REPOSITORY`, or run backups against the existing one with its password.

### Do I need path-style access?

Only if requests fail with DNS errors. Add `-o s3.bucket-lookup=path`, documented in the restic manual.

### Can two servers share one repository?

Yes. Restic deduplicates across hosts and tags each snapshot with its host name; prune from one server only.

### What if the bucket fills up?

The upload fails with a quota error and nothing is billed. Prune, or move to a bigger plan.

### How do I mount snapshots to browse them?

`restic mount /mnt/restic` exposes snapshots as folders on Linux and macOS, per the restic manual.

**Verdict**

- **Seven steps give a server encrypted nightly backups** on an S3-compatible bucket, with pruning and a monthly restore test.
- **On PrivateS3** that costs $2.23/TB-month on 12 months, with no fee when restic prunes or restores. See [restic storage on PrivateS3](https://privates3.com/restic-backup-storage/ "Where should I store restic backups?").

## Sources

1. [Preparing a new repository (Amazon S3)](https://restic.readthedocs.io/en/stable/030_preparing_a_new_repo.html) — restic documentation (read 17 November 2026)
2. [Restoring from backup](https://restic.readthedocs.io/en/stable/050_restore.html) — restic documentation (read 17 November 2026)
3. [Removing backup snapshots](https://restic.readthedocs.io/en/stable/060_forget.html) — restic documentation (read 17 November 2026)
4. [References: design](https://restic.readthedocs.io/en/stable/100_references.html) — restic documentation (read 17 November 2026)

**A bucket for restic: 1 TB for 12 months, $26.77** Keys within 24 hours, no fee to prune or restore, paid in crypto. [Get a restic bucket](https://privates3.com/app/checkout/?plan=s3-1t-12m&product=storage&from=how-to-back-up-with-restic-to-s3&lang=en)

---

PrivateS3: PrivateS3 sells S3-compatible object storage billed per terabyte for backups and files (restic, rclone, Veeam, Cyberduck, Nextcloud), meant to be encrypted on the customer's side before upload. A terabyte costs $5.40 a month or $26.77 for 12 months, 10% under the lowest comparable offer read on 17 November 2026, with no API or egress fees up to 3 times the stored size, paid in crypto with no ID document.
