Offsite backups to S3, Dropbox and other cloud storage
Your backups are only offsite when they live with another company, on hardware that has nothing to do with your server. You probably have such a place already: an S3-compatible bucket at a cloud provider, or a Dropbox, Google Drive or OneDrive account. This guide sends a dedicated server's nightly backup there, encrypted before it leaves the machine, and shows how to get it back on a clean machine when the server is gone.
It uses two programs from Ubuntu 24.04 LTS: restic 0.16.4 for the backup itself and, for the cloud drives, rclone 1.60.1. Every command was checked against the documentation of those versions. Placeholders are written in CAPITALS, such as BUCKET or ACCESS_KEY_ID, and each one is explained where it first appears. Why you need an offsite copy at all, the 3-2-1 rule, database dumps and retention are in our server backup strategy guide; this guide picks up from there.
What offsite has to mean
A copy on a second disk in the same server, or on a second server in the same rack, is a good copy, but it is not offsite. Three conditions make a copy offsite in the sense that matters on a bad day.
Another provider
The copy sits with a different company, in a different building, under a different account. A problem with your server, your rack or your hosting account cannot reach it.
Encrypted before it leaves
The storage provider only ever receives ciphertext. restic encrypts every file on your server, and without the repository password the copy is unreadable, to the provider and to anyone who gets into your account.
Restorable without the server
Everything a restore needs, the repository password and the storage credentials, is also kept somewhere that is not the server. Otherwise the copy dies with the machine it was meant to replace.
The rest of the reasoning, which data to back up, how to dump a database first and how long to keep snapshots, is in our server backup strategy guide. Follow that one for the copy on a second server, and this one for the copy with another provider. The two use the same tool and can run side by side.
restic: install it and create the password
restic is the one backup tool in this guide. It encrypts on your server, deduplicates so that an unchanged file costs nothing after its first backup, and talks to S3-compatible storage directly. For cloud drives it hands the transfer to rclone. Run the commands from here on as root: type sudo -i first.
Install restic and check the version. On Ubuntu 24.04 this prints restic 0.16.4.
apt-get update
apt-get install -y restic
restic version
Generate the repository password and store it in a file only root can read. Copy it into your password manager straight away: without it nobody can restore, not even you.
umask 077
mkdir -p /etc/restic
head -c 30 /dev/urandom | base64 > /etc/restic/offsite.password
cat /etc/restic/offsite.password
Create the excludes file, which keeps caches and temporary files out of the backup. Adjust it to your server.
cat > /etc/restic/excludes.txt <<'EXCL'
/var/cache
/var/tmp
/tmp
/var/lib/docker/overlay2
/home/*/.cache
EXCL
Route A: prepare an S3-compatible bucket
Any storage that speaks the S3 API works with restic's built-in s3 backend: AWS S3 itself, and S3-compatible services such as Backblaze B2, Cloudflare R2, Wasabi, Scaleway and OVHcloud. Prepare the bucket in your provider's web interface first, because restic creates a bucket without any of the protection below if you let it.
-
Create a bucket away from your server
Pick a region of your provider that is not the city your server is in. Name the bucket; that name is BUCKET in the commands below.
-
Switch on versioning
With versioning, deleting a file only hides it behind a delete marker and the earlier version stays. Where you want object lock as well, check whether your provider only allows it when the bucket is created; the table further down says which do.
-
Add a lifecycle rule for old versions
Let the provider delete a version permanently some days after it was replaced or deleted, for example 30. That number is how long you have to notice an attack and undo it. Without the rule, old versions are kept and billed for ever.
-
Create a key for this bucket only
Give the key access to this one bucket, with permission to read, write, list and delete files by name, but not to delete versions and not to change the bucket's settings. The next section shows the policy on AWS.
-
Write down four values
The endpoint (ENDPOINT, a hostname such as s3.eu-central-1.amazonaws.com), the region (REGION), the access key ID (ACCESS_KEY_ID) and the secret key (SECRET_ACCESS_KEY). Store them in your password manager next to the repository password.
Route A: connect restic to the bucket
restic reads the location and the credentials from environment variables. Put them in one file that only root can read, load it, and create the repository.
On AWS, attach a policy like this one to the IAM user whose key the server gets. It is the policy from restic's own AWS example. It allows s3:DeleteObject, which on a versioned bucket only adds a delete marker, and leaves out s3:DeleteObjectVersion, so the key cannot remove a version. Replace BUCKET twice.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": ["s3:ListBucket", "s3:GetBucketLocation"],
"Resource": "arn:aws:s3:::BUCKET"
},
{
"Effect": "Allow",
"Action": ["s3:GetObject", "s3:PutObject", "s3:DeleteObject"],
"Resource": "arn:aws:s3:::BUCKET/*"
}
]
}
Write the settings file. SERVER_NAME is a folder inside the bucket, such as web01, so several servers can share one bucket with a repository each.
cat > /etc/restic/offsite.env <<'ENVFILE'
export RESTIC_REPOSITORY="s3:https://ENDPOINT/BUCKET/SERVER_NAME"
export RESTIC_PASSWORD_FILE="/etc/restic/offsite.password"
export AWS_ACCESS_KEY_ID="ACCESS_KEY_ID"
export AWS_SECRET_ACCESS_KEY="SECRET_ACCESS_KEY"
export AWS_DEFAULT_REGION="REGION"
ENVFILE
chmod 600 /etc/restic/offsite.env
Load the settings, create the repository once, take the first backup and list it. Replace the four paths with the ones that hold your data; the first run uploads everything and can take hours, the next ones only what changed.
source /etc/restic/offsite.env
restic init
restic backup /etc /srv /home /var/www \
--exclude-file=/etc/restic/excludes.txt \
--tag offsite
restic snapshots
restic 0.16.4 addresses every endpoint other than AWS and Google with the bucket in the path, as https://ENDPOINT/BUCKET. If a provider accepts only the bucket as part of the hostname and restic init fails, add -o s3.bucket-lookup=dns to each restic command.
What differs per S3 provider
The commands stay the same everywhere; the endpoint, the region and the way you restrict a key differ. This is what each provider's own documentation says, as read on 27 November 2026. Check it again when you set up, because providers change their offer.
| Provider | Endpoint and region | Versioning and object lock | Restricting the key |
|---|---|---|---|
| AWS S3 | s3.REGION.amazonaws.com, for example s3.eu-central-1.amazonaws.com with region eu-central-1 | Both. Object lock needs versioning, can be switched on later and never off again | An IAM policy with s3:DeleteObject but without s3:DeleteObjectVersion, as above |
| Backblaze B2 | s3.REGION.backblazeb2.com, the region shown next to your bucket, such as eu-central-003. The master key does not work with the S3 API | Every bucket is versioned. Object lock can be switched on at or after creation, and not off again | An application key for one bucket with writeFiles and without deleteFiles. restic's documentation recommends B2's S3 API over its native backend |
| Cloudflare R2 | ACCOUNT_ID.r2.cloudflarestorage.com. For the EU jurisdiction, put .eu before .r2. Region auto | No S3 versioning or object lock. R2 has its own bucket locks per prefix | No token level that writes without deleting is documented |
| Wasabi | Per region, for example s3.eu-central-1.wasabisys.com in Amsterdam | Both. Object lock only when the bucket is created | Its policies tell s3:DeleteObject and s3:DeleteObjectVersion apart |
| Scaleway | s3.nl-ams.scw.cloud with region nl-ams, also fr-par, pl-waw and it-mil | Both. Object lock at or after creation, then permanent | A bucket policy for an IAM application that allows s3:DeleteObject and not s3:DeleteObjectVersion |
| OVHcloud | s3.REGION.io.cloud.ovh.net, for example region de for Frankfurt | Object lock only when the bucket is created, with versioning | No separate permission to delete versions is documented, so rely on object lock |
On Backblaze B2 the lifecycle rule from the previous section is the preset "Keep prior versions for this number of days". restic's documentation says the same thing from its side: through the S3 API restic only hides files it no longer needs, so set a lifecycle rule that eventually deletes hidden files.
Route B: Dropbox through rclone
A cloud drive does not speak S3, so restic uses rclone to reach it: restic starts rclone in the background and sends every file through it. You authorise rclone once against your Dropbox account and restic does the rest. The server has no browser, so the sign-in happens on your own computer and you paste the result into the server.
Install rclone on the server and check the version. On Ubuntu 24.04 this prints rclone v1.60.1.
apt-get install -y rclone
rclone version
Start the configuration as root. Answer n for a new remote, name it dropbox, choose dropbox as the storage type, leave the app key and the app secret empty and say no to the advanced configuration. When rclone asks "Use auto config?", answer n, because the server has no browser. rclone then prints a command to run on a machine that has one.
rclone config
On your own computer, install rclone from rclone.org and run the command the server printed. rclone's documentation recommends the same version on both machines. Your browser opens, you sign in to Dropbox and allow access, and the terminal prints the result to paste.
rclone authorize "dropbox"
Paste the result at the server's prompt, confirm the remote with y and leave the configuration with q. Then check that the server can reach your Dropbox and create the folder for the repository.
rclone lsd dropbox:
rclone mkdir dropbox:restic
Write the settings file for the rclone route. The repository is rclone:REMOTE:PATH, here the remote dropbox and the folder restic/SERVER_NAME. RCLONE_CONFIG tells rclone where root's configuration is, also when systemd starts the job.
cat > /etc/restic/offsite.env <<'ENVFILE'
export RESTIC_REPOSITORY="rclone:dropbox:restic/SERVER_NAME"
export RESTIC_PASSWORD_FILE="/etc/restic/offsite.password"
export RCLONE_CONFIG="/root/.config/rclone/rclone.conf"
ENVFILE
chmod 600 /etc/restic/offsite.env
From here it is the same as route A: load the settings, create the repository, back up, list.
source /etc/restic/offsite.env
restic init
restic backup /etc /srv /home /var/www \
--exclude-file=/etc/restic/excludes.txt \
--tag offsite
restic snapshots
rclone's configuration file now holds a token that gives full access to your Dropbox. It lives in /root/.config/rclone/rclone.conf, readable by root only. rclone can encrypt the file with a password (option s in rclone config), but a job that runs at night then needs that password on the server as well, so it protects against a copied file, not against someone who is root on the machine.
Google Drive and OneDrive: what differs
Google Drive works the same way with storage type drive and rclone authorize "drive". Create your own OAuth client ID in a Google Cloud project and enter it when rclone asks: rclone's documentation says its shared client ID is being retired and stops working during 2026. Set the app's publishing status to production, because Google issues refresh tokens that expire after 7 days to an app that is still in testing, and your backups would stop a week later. The scope drive.file limits rclone to the files it created itself. Google documents a limit of 750 GB uploaded per user per day, which matters for the first backup of a large server.
OneDrive works with storage type onedrive and rclone authorize "onedrive"; during the configuration you choose between OneDrive Personal, OneDrive for Business and a SharePoint library. rclone's documentation says that from 1 April 2027 OneDrive for Business and SharePoint need rclone 1.76 or later, so Ubuntu's 1.60.1 will stop working with them. For those, install the current rclone with the script from rclone.org/install ("sudo -v ; curl https://rclone.org/install.sh | sudo bash"). OneDrive Personal is not affected.
The limits of a drive as a backup target
A drive is made for people syncing documents, not for a server writing thousands of files a night. It works, but know where it falls short before you depend on it.
Rate limits
Drives slow down programs that send many requests. rclone waits and retries when Dropbox answers "too_many_requests", so the job finishes, but a first backup of hundreds of gigabytes can take days.
The token can delete
The token on the server can read, overwrite and delete everything in the account, not only the backup folder. There is no drive equivalent of a key without delete permission.
Sync clients
Do not let a desktop sync app on a laptop sync the restic folder. A sync client that deletes, renames or makes conflict copies damages the repository. Exclude the folder from selective sync.
Account quota
The backup shares the account's storage with everything else in it. On Google Drive the trash counts toward the quota, on OneDrive the recycle bin does, so space freed by a prune returns only once those are emptied.
Protecting the backups from the server itself
The server that makes the backups holds the credentials to the storage. If an attacker becomes root on it, they hold them too, and ransomware will try to delete the backups before it encrypts the server. So the question for each kind of storage is precise: what can someone do with the credentials that are on the server, and what stops them.
One answer does not work with restic 0.16.4: a key that cannot delete anything. Every restic run writes a lock file into the repository and removes it again when it finishes, so the server's key has to be able to delete files by name. The working answer on S3 storage is versioning with a key that may delete files by name but not versions.
| Storage | What the server's credentials can do | What protects you |
|---|---|---|
| S3 with versioning, key without version delete | Hide files behind delete markers and upload new versions | Earlier versions stay until your lifecycle rule removes them. That is your window to notice and restore |
| S3 with object lock on top | The same, but no version can be removed before its retention date | In compliance mode nobody can remove a locked version early, not even you. You pay for it until the date passes |
| S3 without versioning, such as Cloudflare R2 | Delete the whole repository for good, because restic only works with a key that may delete | Nothing at the provider. Keep a second copy that this server holds no credentials for |
| Dropbox | Delete and overwrite everything in the account | Deleted files and earlier versions can be restored for 30 days on Basic, Plus and Family, longer on the other plans |
| Google Drive | Delete files permanently, past the trash | Little. The trash keeps files for 30 days, but the API can delete without it |
| OneDrive | Delete files into the recycle bin, and permanently with a recent rclone | The recycle bin, 30 days on a personal account and 93 days on work or school accounts unless changed. Not reliable against an attacker |
| restic rest-server with --append-only | Add snapshots, but not delete or overwrite any | The server itself, run on a machine you control, as our backup strategy guide describes |
Recovering from an attack on versioned storage means removing the delete markers or copying the earlier versions back before the lifecycle rule removes them, with your provider's web interface or S3 tools. Then run restic check on the repository from a clean machine before you trust it again. On a drive, the history is a safety net for mistakes and for an attacker in a hurry, not a wall. If the server must not be able to destroy its last good copy, use S3 storage with versioning or object lock, or a rest-server in append-only mode.
Scheduling: one script and a systemd timer
One script does the nightly work: back up, apply the retention policy, and tell a monitor that it finished. A systemd timer runs it, which logs every run in the journal and catches up after the machine was off. If the server runs a database, put the dump step from our server backup strategy guide at the top of the script, so the dump lands in a folder restic saves.
The script. YOUR_CHECK_UUID is the check you create at a healthchecks-style monitor; with set -euo pipefail a failed step stops the script before the ping, so silence means trouble.
#!/usr/bin/env bash
set -euo pipefail
source /etc/restic/offsite.env
PING_URL="https://hc-ping.com/YOUR_CHECK_UUID"
restic backup /etc /srv /home /var/www \
--exclude-file=/etc/restic/excludes.txt \
--tag offsite
restic forget --prune \
--keep-daily 7 --keep-weekly 4 --keep-monthly 6
curl -fsS -m 10 --retry 3 "$PING_URL" > /dev/null
The service. HOME is set so that restic finds its cache under /root, and the job runs at low priority so the server stays responsive.
[Unit]
Description=Offsite restic backup
After=network-online.target
Wants=network-online.target
[Service]
Type=oneshot
Environment=HOME=/root
ExecStart=/usr/local/sbin/offsite-backup.sh
Nice=10
IOSchedulingClass=idle
The timer: every night at 03:15, with a random delay of up to 30 minutes, and a catch-up run when the machine was off at that time.
[Unit]
Description=Run the offsite backup every night
[Timer]
OnCalendar=*-*-* 03:15:00
RandomizedDelaySec=30m
Persistent=true
[Install]
WantedBy=timers.target
Make the script executable, enable the timer, run the job once by hand and read its log.
chmod 700 /usr/local/sbin/offsite-backup.sh
systemctl daemon-reload
systemctl enable --now offsite-backup.timer
systemctl list-timers offsite-backup.timer
systemctl start offsite-backup.service
journalctl -u offsite-backup.service --no-pager
Retention, and who may prune
restic forget removes snapshots outside the policy, here 7 daily, 4 weekly and 6 monthly, and --prune then deletes the data that no snapshot uses any more. restic's documentation is clear that forget and prune need read, write and delete access to the repository. That is the conflict with the previous section: the credential that may prune is the credential an attacker wants.
On S3 storage with versioning the conflict resolves itself. The server's key deletes by name, so a prune on the server only adds delete markers, and your lifecycle rule frees the space some days later. The cost of that safety is storage: everything prune removes is still billed until the rule deletes it, and with object lock until its retention date.
Where the server's credential can delete for good anyway, on a drive or on storage without versioning, it makes no difference to an attacker where prune runs. There the protection is a second copy elsewhere: for example a machine of your own that holds the only credentials for a second repository and copies the snapshots into it with restic copy. If you give the server a weaker credential somewhere and run forget and prune from another machine, take the server's forget out of the script and use --keep-within for the policy, which restic's documentation recommends for append-only repositories because faked snapshots cannot push real ones out.
Restore: prove it on a clean machine
A backup you have never restored is a hope. Prove this one once now and again every quarter, on a machine that is not the server: a spare server or a virtual machine on your own computer, running Ubuntu 24.04. Assume the server is gone. Everything you type comes from your password manager, not from the server.
That is the test of the third condition from the start of this guide. If the repository password or the storage credentials exist only on the server, the drill fails here, and it is far better to find that out now.
On the clean machine, become root and install restic, and rclone as well for route B.
sudo -i
apt-get update
apt-get install -y restic rclone
umask 077
mkdir -p /etc/restic
Paste the repository password from your password manager, press Enter and then Ctrl-D.
cat > /etc/restic/offsite.password
Recreate the settings file exactly as on the server, with the values from your password manager; the route A version is shown. For route B, write the rclone version instead and authorise rclone on this machine again with rclone config and rclone authorize, as before: a new token works just as well as the old one.
cat > /etc/restic/offsite.env <<'ENVFILE'
export RESTIC_REPOSITORY="s3:https://ENDPOINT/BUCKET/SERVER_NAME"
export RESTIC_PASSWORD_FILE="/etc/restic/offsite.password"
export AWS_ACCESS_KEY_ID="ACCESS_KEY_ID"
export AWS_SECRET_ACCESS_KEY="SECRET_ACCESS_KEY"
export AWS_DEFAULT_REGION="REGION"
ENVFILE
List the snapshots, restore the newest one of the old server into an empty folder, and read a random 5% of the stored data back to check it. ORIGINAL_HOSTNAME is the old server's hostname, as the snapshots list shows it in the Host column.
source /etc/restic/offsite.env
restic snapshots
restic restore latest --host ORIGINAL_HOSTNAME --target /srv/restore-drill
restic check --read-data-subset=5%
ls /srv/restore-drill
The restored files sit under /srv/restore-drill with their original paths, such as /srv/restore-drill/etc. Go one step further than the files: load a database dump, start the application and see it answer. Then write down how long the whole drill took. That number is your real recovery time, and the download from the provider is usually most of it.
What it costs: the shape of the bill
Prices change, so this section gives the shape of each bill and leaves the amounts to the providers' price pages. Four things decide what you pay: storage per gigabyte per month, egress, which is reading data back out and is mostly a restore, a minimum storage duration that bills a deleted file as if it stayed, and fees per request. restic deduplicates and compresses, so the stored amount is roughly your data once plus what changes each day, plus the old versions your lifecycle rule keeps.
A drive bills differently: a fixed subscription for a quota, with no egress or request fees, so the limit is the quota and the rate limits rather than the price. The table shows the S3 providers as their own pages describe them on 27 November 2026, for the standard storage class.
| Provider | Egress | Minimum storage duration | Requests and minimums |
|---|---|---|---|
| AWS S3 | Per GB, the first 100 GB a month free across AWS | None for Standard, 30 to 180 days for the infrequent and Glacier classes | Charged per request, DELETE free. No minimum charge |
| Backblaze B2 | Free up to three times the average stored amount, then per GB | None | Most calls free. The first 10 GB of storage free |
| Cloudflare R2 | No egress fees | None for Standard, 30 days for Infrequent Access | Class A and B operations charged beyond a free monthly allowance |
| Wasabi | Free up to the stored amount each month | 90 days on pay as you go | No request fees. At least 1 TB billed |
| OVHcloud | Not charged | One hour for Standard, 30 days for Infrequent Access | API calls not charged |
Two habits keep the bill predictable. Restores and restic check --read-data download data, so test with a subset as above and save the full read for when you need it. And pick the lifecycle window knowingly: on a provider with a 90-day minimum duration, a 30-day window is still billed for 90.
Which storage for which job
There is no single best place. Match the storage to what you need from it.
| Need | S3, versioned or locked | S3, no versioning | Cloud drive |
|---|---|---|---|
| Survives a compromised server | Yes, within your window | No | Partly, through the account's history |
| Large data sets, terabytes | Yes | Yes | Slow first upload, quota bound |
| Fast, cheap full restores | Depends on the egress price | Depends on the egress price | No egress fees, but rate limited |
| Uses an account you already have | If you have one | If you have one | Usually |
| Credentials scoped to one bucket | Yes | Yes | Not by default, the token reaches the whole account |
| Small server, a few hundred GB | Good fit | Fine, with a second copy | Good fit |
The short version
Install restic, keep its password and your storage credentials in a password manager, and send a nightly encrypted backup to a provider that is not your hosting provider. On S3 storage, switch on versioning, add a lifecycle rule and give the server a key that cannot delete versions. On a drive, accept that the token can delete and keep a second copy if that matters. Run it from a systemd timer with a monitor ping, and restore it on a clean machine before you need to.
Frequently asked questions
Can the storage provider read my backups?
No. restic encrypts every file on your server before it is uploaded, and the provider only stores ciphertext. Without the repository password nobody can read the data, which is also why losing that password means losing the backups.
Do I still need the backup on a second server?
It is the faster restore. A second server in the same network brings data back quickly, while the offsite copy covers the day when the network, the building or your account is the problem. Our server backup strategy guide sets up the first, this guide the second, and both can run with the same restic.
Can I back up to Dropbox without giving the server access to all my files?
Not with rclone's default setup: the token reaches the whole account. You can register your own Dropbox app limited to an app folder and enter its key and secret in rclone config, or use a separate Dropbox account for backups. On Google Drive, the scope drive.file limits rclone to the files it created.
Why not install the Dropbox or OneDrive sync app and back up into its folder?
Because a sync app is the wrong tool for a repository. It copies deletions and conflicts in both directions, keeps a full local copy on the server's own disks, and adds a second program between restic and the storage. restic with rclone writes to the storage directly and reports an error when something goes wrong.
How long does the first backup take?
As long as uploading all your data once takes, at the speed of your server's connection and of the provider. After that only the changes go out, usually minutes. On a drive, rate limits and a daily upload limit such as Google's 750 GB can stretch the first run over several days; let it finish before you rely on it.
What happens when the restic password is lost?
The backups cannot be restored by anyone. There is no recovery path, by design. Keep the password in your password manager and, for a company, a printed copy in a safe, and check during each restore drill that the copy you keep still works.
