restic is a free, open-source backup program. One command copies your folders into a repository, encrypted on your machine with a password only you know, and every later backup sends only what changed. Cloudflare R2 is Cloudflare's object storage: it speaks the same S3 API as Amazon S3 and charges nothing for downloads, which is what a restore is. Backrest is a free web interface for restic: it schedules the backups, applies the retention policy, sends alerts and restores files from the browser.
This guide sets the three up for production on one server: a token that can reach one bucket only, restic installed from its signed release, the keys in files only you can read, a backup and a tested restore, an integrity check, a retention policy, then Backrest in Docker with a daily plan and alerts on your phone. Tested on 26 November 2026 on an Ubuntu 26.04.1 laptop with restic 0.20.0 and Backrest 1.14.1, against an R2 bucket of NexaForge, our test Cloudflare account, within R2's free monthly allowance. Every command below ran there, and every screenshot shows its real output.
Quick answer: restic backups to Cloudflare R2
In plain words: restic needs three things to back up to R2: the bucket's S3 address, a key pair that can write to that bucket, and a password that encrypts the repository. Keep the three in files only your user can read, then:
- In the Cloudflare dashboard, create an R2 bucket and an Account API token with Object Read & Write on that bucket only.
- Install restic 0.20.0 from its GitHub release and check the signature (Ubuntu 26.04's package is 0.18.1).
- Put the keys and the repository address in an env file with mode 600, and a random password in its own file.
- Run
restic initonce, thenrestic backupfor each backup. - Restore to a new folder and compare it with the original. Until a restore has worked, you do not know that the backup works.
- Run
restic check --read-data-subsetevery month. - Apply a retention policy with
restic forget --prune. - For schedules, alerts and restores in a browser, run Backrest in Docker on the same repository.

What Cloudflare R2 costs for restic backups in 2026
R2 bills storage and requests, never downloads. These are Cloudflare's published prices, checked on 26 November 2026:
| Free each month | Standard storage | Infrequent Access | |
|---|---|---|---|
| Storage | 10 GB-month | $0.015 per GB-month | $0.01 per GB-month |
| Class A operations (writes and lists) | 1 million | $4.50 per million | $9.00 per million |
| Class B operations (reads) | 10 million | $0.36 per million | $0.90 per million |
| Data retrieval | None | None | $0.01 per GB |
| Downloads (egress) | Free | Free | Free |
| Minimum storage duration | None | None | 30 days |
The free allowance only applies to Standard storage. Keep a restic repository there: restic reads its index and data files during check, prune and restore, and Infrequent Access charges for every GB read, plus 30 days of storage for files that prune deletes sooner. In this test, 107 MiB of website files took 42 MiB in the bucket, far inside the free 10 GB-month. At 100 GB of backups, storage costs about $1.35 a month (90 GB above the free part, at $0.015).
Step 1: an R2 bucket and a token for that bucket only
In the Cloudflare dashboard, open Storage & databases > R2 Object Storage and select Create bucket. The name is permanent. Leave the location on Automatic and the storage class on Standard, then select Create bucket.

Now create the key pair restic will use. In R2 Object Storage, select Manage API tokens, then Create Account API token. An account token belongs to the Cloudflare account, not to a person, so it keeps working if the person who made it leaves. Give it the permission Object Read & Write (read, write and list objects, nothing else) and, under Specify bucket(s), choose Apply to specific buckets only with your backup bucket. The Admin permissions cover every bucket of the account, and Admin Read & Write can also delete buckets: a stolen key would reach all of them.
If your server has a fixed public IP address, add it under Client IP Address Filtering, so the token works from that address only. TTL Forever suits a server that backs up every night; replace the token when someone who had a copy leaves.

The next page shows the credentials once. restic needs three of them: the Access Key ID, the Secret Access Key and the S3 endpoint, https://<ACCOUNT_ID>.r2.cloudflarestorage.com. Copy them into a password manager now: Cloudflare does not show the secret again.

Step 2: install restic 0.20.0 and check its signature
Ubuntu 26.04 offers restic 0.18.1, two releases behind. restic's own release is one static file per platform, signed by the project's maintainer. Download the file, the checksum list and its signature, import the key from restic.net and verify:
apt-cache policy restic | head -3
curl -sLO https://github.com/restic/restic/releases/download/v0.20.0/restic_0.20.0_linux_amd64.bz2
curl -sLO https://github.com/restic/restic/releases/download/v0.20.0/SHA256SUMS
curl -sLO https://github.com/restic/restic/releases/download/v0.20.0/SHA256SUMS.asc
curl -s https://restic.net/gpg-key-alex.asc | gpg --import
gpg --verify SHA256SUMS.asc SHA256SUMS
What counts is "Good signature" and the key fingerprint, CF8F 18F2 8445 7597 3F79 D4E1 91A6 868B D3F7 A907: compare it with the one on restic's installation page. The warning below it only says that you have not certified this key yourself in GPG. The key file holds two keys of the same maintainer; the release is signed by 91A6868BD3F7A907. Then check the file's checksum, unpack it and install it:
sha256sum --ignore-missing -c SHA256SUMS
bunzip2 restic_0.20.0_linux_amd64.bz2
sudo install -m 755 restic_0.20.0_linux_amd64 /usr/local/bin/restic
restic version
sudo restic self-update
--ignore-missing checks only the file you downloaded, not every platform in the list. restic self-update replaces the binary with the newest release after checking its GPG signature itself; it needs sudo because the binary sits in /usr/local/bin. Here it found nothing newer.
Step 3: the keys, the password and the repository
restic reads its settings from environment variables. Keep them in a file, not in a script or your shell history. Create ~/.config/restic/r2.env with your editor, with your own keys, account ID and bucket:
AWS_ACCESS_KEY_ID=<Access Key ID>
AWS_SECRET_ACCESS_KEY=<Secret Access Key>
RESTIC_REPOSITORY=s3:https://<ACCOUNT_ID>.r2.cloudflarestorage.com/nexaforge-backups
RESTIC_PASSWORD_FILE=/home/dev/.config/restic/passwordRESTIC_REPOSITORY is s3: followed by the endpoint and the bucket name. RESTIC_PASSWORD_FILE points to the repository password: restic encrypts every file, folder name and snapshot with it, on your machine, before anything leaves. Lock both files to your user, create a random password and the repository:
chmod 700 ~/.config/restic
openssl rand -base64 32 > ~/.config/restic/password
chmod 600 ~/.config/restic/password ~/.config/restic/r2.env
ls -l ~/.config/restic
cut -d= -f1 ~/.config/restic/r2.env
set -a; . ~/.config/restic/r2.env; set +a
restic init
ls -l and cut -d= -f1 check the files without printing a secret. set -a; . ~/.config/restic/r2.env; set +a exports every line of the file to the commands that follow; run it again in each new shell before a restic command, as the next steps assume. restic init writes the repository's configuration and encrypted key into the bucket. Read its warning twice: without the password, nobody can read the backups, you included. Keep a copy of the password in a password manager or on paper, away from this server.
Step 4: the first backup, then the second
The test site is a typical small website: a 64 MB database dump, 5 MB of pages and 41 MB of uploaded media. Back it up with a tag, so you can filter snapshots later:
du -sh ~/site/*
restic backup ~/site --tag site
restic read 309 files (107.286 MiB) and added 106.105 MiB of new data, which took 42.037 MiB in the bucket after compression: the SQL dump shrinks a lot, the media files hardly at all. The run took 10 seconds and saved snapshot a75ac3c8. Now change one line of the database dump and back up again, as the nightly job would:
echo 'INSERT INTO log VALUES (2000001);' >> ~/site/db/site.sql
restic backup ~/site --tag site
restic snapshots
restic found 1 changed file and 308 unmodified ones. Of the 64 MB dump, it sent only the changed chunks: 326.320 KiB of new data, 7.028 KiB once compressed. That is deduplication: each snapshot is a full backup you can restore on its own, but it costs only the changes. restic snapshots lists both.
Step 5: restore everything, then one file
Restore to a new folder, never over the live site, and compare:
restic restore latest --target ~/restore
diff -r --no-dereference ~/site ~/restore/home/dev/site && echo identical
restic restore latest --target ~/restore-one --include /home/dev/site/db/site.sql
ls -l ~/restore-one/home/dev/site/db/
The restore rebuilt 607 files and folders (107.286 MiB) in 4 seconds, and diff found no difference. restic keeps the full original path under the target, here ~/restore/home/dev/site. --no-dereference makes diff compare links as links: without it, diff reports an error for each link that points to a missing file. For a single file, add --include with its full path: the 64 MB dump came back alone in one second.
Step 6: check the repository and part of the data
restic check
restic check --read-data-subset=25%
restic check verifies the structure: the index, the snapshots, and that every piece they need exists. --read-data-subset=25% also downloads a random quarter of the data files and verifies their content, which catches silent corruption. On R2 the download is free; only the read requests count, and 10 million of them a month are free. Each run picks another random part, so monthly checks cover more and more of the repository.
Step 7: keep 7 daily, 4 weekly and 6 monthly snapshots
restic forget removes snapshots according to a policy, and --prune deletes the data that no snapshot uses anymore. Try a policy with --dry-run first:
restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 6 --dry-run
The policy keeps one snapshot per day for 7 days, one per week for 4 weeks and one per month for 6 months: at most 17 snapshots and about half a year of history. On the first day it removes nothing, and the output says why: when there are fewer snapshots than the policy asks for, restic also keeps the oldest one, marked oldest daily, weekly and monthly snapshot.
To see prune at work, this test kept only the last snapshot. Do not run --keep-last 1 on a real repository unless you mean it:
restic forget --keep-last 1 --prune
restic snapshots
forget removed a75ac3c8, then prune found 5 blobs (2.817 KiB) that only that snapshot used, repacked the pack files that held them and removed one old pack. Most of the first snapshot's data stayed, because c7145437 still uses it: 515 blobs, 42.021 MiB. Prune reads and rewrites data, so run it weekly or monthly, not after every backup.
Step 8: two errors you will meet
restic snapshots --password-file /tmp/wrong-password
RESTIC_REPOSITORY=${RESTIC_REPOSITORY%/*}/other-bucket restic snapshots
A wrong password gives Fatal: wrong password or no key found: check RESTIC_PASSWORD_FILE and the file it names. The second command swaps the bucket name for other-bucket for one run (${RESTIC_REPOSITORY%/*} is the address without its last part). With a token limited to one bucket, R2 answers Access Denied for any other name, even one that does not exist, so a typo in the bucket name looks like a permission problem. If you see Stat: Access Denied, compare the bucket in RESTIC_REPOSITORY with the token's bucket list.
Step 9: run Backrest with Docker Compose
Backrest runs restic for you: it schedules backups, applies the retention policy, runs check and prune, sends alerts and restores files from the browser. Its Docker image includes restic (0.19.1 in Backrest 1.14.1), so the server needs only Docker with the Compose plugin; Install Docker Compose on Ubuntu covers that. This compose file follows the one in Backrest's README, with a pinned version, the port bound to the machine itself and the data mounted read-only:
services:
backrest:
image: ghcr.io/garethgeorge/backrest:v1.14.1
container_name: backrest
hostname: backrest
restart: unless-stopped
env_file: backrest.env
environment:
- BACKREST_DATA=/data
- BACKREST_CONFIG=/config/config.json
- XDG_CACHE_HOME=/cache
- TMPDIR=/tmp
- TZ=America/New_York
volumes:
- ./data:/data
- ./config:/config
- ./cache:/cache
- ./tmp:/tmp
- ../site:/userdata/site:ro
ports:
- "127.0.0.1:9898:9898"The keys stay in a separate file, backrest.env, next to it: the same values as in step 3, and the repository password itself, the content of ~/.config/restic/password:
R2_ACCOUNT_ID=<ACCOUNT_ID>
R2_ACCESS_KEY_ID=<Access Key ID>
R2_SECRET_ACCESS_KEY=<Secret Access Key>
RESTIC_REPO_PASSWORD=<the repository password>Check the names, lock the file and start Backrest:
cat compose.yaml
cut -d= -f1 backrest.env
chmod 600 backrest.env && stat -c "%a %n" backrest.env
docker compose up -d
docker compose ps
TZ sets the clock Backrest's schedules follow: put your own time zone. /data, /config and /cache keep Backrest's state on the host, so it survives an update. ../site:/userdata/site:ro is the folder to back up, read-only inside the container: Backrest can read it, never change it. 127.0.0.1:9898 keeps the web interface off the network; reach it through an SSH tunnel, or put it behind Cloudflare Access with a hostname of its own.
Step 10: first start, instance ID and login
Open http://127.0.0.1:9898. Backrest first asks for an instance ID: it names this installation in the snapshots' tags (created-by:web-01 here) and cannot be changed later, so use the server's name. On our first start, Disable Authentication was switched on, which means no login at all. Switch it off, add a user with a long password, then Save changes.

Backrest keeps the password as a bcrypt hash in config/config.json, a file it creates with mode 600.
Step 11: add the R2 repository without pasting the keys
Select Add Repo. Backrest expands ${NAME} references from its own environment, so the keys stay in backrest.env and Backrest's configuration only holds their names. Enter these values, with your bucket name, in Repository URI and Env Vars:
s3:https://${R2_ACCOUNT_ID}.r2.cloudflarestorage.com/nexaforge-backups
AWS_ACCESS_KEY_ID=${R2_ACCESS_KEY_ID}
AWS_SECRET_ACCESS_KEY=${R2_SECRET_ACCESS_KEY}
RESTIC_PASSWORD=${RESTIC_REPO_PASSWORD}
In Scheduling, keep the prune policy monthly with Max Unused After Prune at 10, and set the check policy to read 10% of the data, also monthly:


Test Configuration answered "Connected successfully to s3:https://${R2_ACCOUNT_ID}.r2.cloudflarestorage.com/nexaforge-backups and found an existing repo": Backrest found the repository that restic init created in step 3. Select Submit, open the repository and select Index Snapshots to list the snapshots made from the command line:

Backrest's config.json now holds ${R2_SECRET_ACCESS_KEY}, not the key: we searched the file for each secret value and found none.
Step 12: a daily plan with retention and alerts
Select Add Plan. A plan says what to back up, where and when:


Pick a quiet hour. If the site has a database, back up a dump of it, like site.sql in this test, not the database's live files, and make the dump before 02:30.

Backrest applies this policy with restic forget after each backup; the repository's monthly prune then deletes the data.
Under Advanced, add a hook of type Shoutrrr for alerts. This one posts to ntfy, a free push service with Android and iOS apps: subscribe to your topic in the app, and Backrest's messages reach your phone. On the public ntfy.sh server, anyone who knows a topic name can read it, so make the name long and random. The success message is useful too: a morning without it means the night's backup did not run.

Step 13: run the plan once
Open the plan and select Backup Now. The first run from Backrest added only 207.51 KiB, though the folder holds 107 MiB: it had the same content as the command line's snapshot, and restic stores each piece once, whatever host or path it comes from. A second run added 371 bytes:

ntfy received the message within seconds, here in the ntfy.sh web app:

The first run's alert did not arrive: the hook timed out. The cause and the fix are under Errors and fixes below.
Step 14: restore a file from Backrest
Open the snapshot in the plan's tree view, find the file in Snapshot Browser, open its menu and select Restore to path. The path is inside the container: /tmp is the ./tmp folder of the compose project on the host. Choose a folder that does not exist yet: Backrest overwrites files already at that path.


Then compare the restored file with the original:
docker compose exec backrest sha256sum /userdata/site/db/site.sql /tmp/restore/site.sql
Run the comparison inside the container, as above: on the host, the restored files belong to root, because Backrest runs restic as root.
Errors and fixes
| Error | Cause | Fix |
|---|---|---|
Fatal: wrong password or no key found | The password does not open this repository | Check RESTIC_PASSWORD_FILE, or RESTIC_REPO_PASSWORD in backrest.env |
Fatal: unable to open config file: Stat: Access Denied. | A wrong bucket name, or a token without this bucket | Compare RESTIC_REPOSITORY with the token's bucket list |
context deadline exceeded (Client.Timeout exceeded while awaiting headers) | The hook's HTTPS request leaves Docker in packets too big for the host's link | Lower the Docker network MTU (below) |
| Restore in Backrest does nothing | The button asks for a second click | Select it again when it reads Confirm Restore? |
diff reports No such file or directory for links | Links to missing files, which diff follows | Add --no-dereference |
Permission denied on restored files from the host | Backrest restores as root | Check them with docker compose exec backrest or sudo |
The ntfy alert times out from Docker: lower the MTU
Backrest's first alert failed with Post "https://ntfy.sh/<topic>": context deadline exceeded (Client.Timeout exceeded while awaiting headers). The test machine's link to the internet carries packets of at most 1,408 bytes, and Docker's bridge network uses 1,500: the large TLS packets from the container were lost on the way. VPN links, PPPoE connections and some cloud networks have the same limit. Give the compose network a smaller MTU in compose.override.yaml, next to compose.yaml, and recreate the container:
networks:
default:
driver_opts:
com.docker.network.driver.mtu: "1400"docker compose down
docker compose up -d
docker compose exec backrest cat /sys/class/net/eth0/mtu
Docker Compose reads compose.override.yaml on its own. After the change, the container's interface reported 1400 and the next alert arrived.
Production checklist
- The R2 token: an Account API token with Object Read & Write on one bucket, limited to the server's IP address when it is fixed.
- restic from the signed release, kept current with
sudo restic self-update; Backrest on a pinned version tag that you update on purpose. r2.env, the password file andbackrest.envin mode 600, never in a Git repository.- A copy of the repository password away from the server.
- A database dump before each backup, not the live database files.
- A check every month that reads part of the data (10% here), and a prune every month.
- A restore test every month: one file and a comparison, as in steps 5 and 14.
- Alerts on errors and on success; a missing success message is an alert too.
- Backrest's login on, its port on 127.0.0.1, and an SSH tunnel or Cloudflare Access to reach it.
- One more copy that the server's key cannot delete (see the last question below).
Frequently asked questions
Is restic free, and what does Cloudflare R2 cost for backups?
restic is free and open source, under the BSD 2-Clause license, and so is Backrest. You pay only for the storage: R2 gives 10 GB-month of Standard storage free each month, then charges $0.015 per GB-month, with no fee for downloads. 100 GB of backups costs about $1.35 a month in storage, plus requests, which nightly backups of a small site keep inside the free allowance.
Does restic encrypt the data before it reaches R2?
Yes. restic encrypts on your machine with AES-256 in counter mode and authenticates every piece with Poly1305-AES, with keys protected by your repository password. R2 only receives encrypted data, so neither Cloudflare nor anyone with the bucket keys can read your files without the password.
What is Backrest, and do I still need the restic command line?
Backrest is a web interface and scheduler for restic: it runs restic underneath and keeps its settings in config.json. The repository stays a normal restic repository: in this test, the command line listed Backrest's snapshots next to its own, as the first screenshot shows. Keep the command line for scripts and emergencies; the browser covers the daily work.
How do I restore a single file with restic?
Pass --include with the file's full path: restic restore latest --target ~/restore-one --include /home/dev/site/db/site.sql restored the 64 MB dump alone in one second in step 5. In Backrest, open the snapshot, find the file in Snapshot Browser and select Restore to path, as in step 14.
Can restic back up to R2 through rclone?
restic can use rclone as a backend (rclone:remote:path), which helps with storage that has no S3 API. R2 does not need it: restic's own S3 backend talks to R2 directly, as in this guide, with one program less to install and update.
What happens if I lose the repository password?
The backups are lost. restic cannot decrypt them without it, and there is no reset: R2 holds only encrypted data. A repository can have more than one password (restic key add), so you can keep a second one in a separate safe place.
Can an attacker on the server delete the backups?
Yes. The key on the server can write and delete objects in the bucket, so anyone who gets root on the server can delete the backups too. R2 bucket locks stop the deletion and overwriting of objects for a set period, but restic's prune then cannot remove locked data either, so test them on a separate bucket first. The simpler protection is a second copy that this server's key cannot reach.
Related guides
- Vaultwarden with Docker Compose: HTTPS, Admin Token, Backups and a Tested Restore (2026)
- Backblaze B2 vs Synology C2: A Comprehensive Comparison
- Install Immich with Docker Compose and Synology
- How to Install Paperless-ngx on Synology with Docker Compose (2026 Guide)
- Cloudflare Zero Trust 101: Put a Self-Hosted App Behind Access (Free Plan, 2026)
- Install Docker Compose on Ubuntu using Docker’s repository
- How to Install Uptime Kuma with Docker (2026 Step-by-Step Guide)
Sources
- restic docs: installation and signature check
- restic docs: preparing a new repository (S3-compatible storage)
- restic docs: backing up
- restic docs: working with repositories and checking integrity
- restic docs: restoring from backup
- restic docs: removing snapshots according to a policy
- restic docs: references (repository format and encryption)
- restic 0.20.0 release
- Backrest on GitHub (installation and Docker Compose)
- Backrest docs: getting started
- Backrest docs: hooks
- Cloudflare R2 docs: pricing
- Cloudflare R2 docs: authentication and API tokens
- Cloudflare R2 docs: bucket locks
- Shoutrrr docs: ntfy service
- Docker docs: bridge network driver options
Leave a comment
Your email address will not be published. Required fields are marked *
