Most VPS backup plans fail the same way: something was set up once, nobody checked it, and the first real test is the day it is needed. This guide builds a backup you can trust on Ubuntu 24.04 or Debian 12:

  • restic for encrypted, deduplicated, compressed snapshots,
  • an S3-compatible bucket as the off-server destination,
  • a cron job with locking, retention and integrity checks,
  • and a restore test, which is the part that turns a backup into a backup.

Why restic

  • Everything is encrypted on the client before it leaves the server. The storage side only sees opaque blobs.
  • Deduplication: daily snapshots of a mostly unchanged server cost little extra space.
  • Any S3-compatible storage works, as do SFTP servers and a local disk.
  • Restores are a single command, and you can mount snapshots to browse them.

1. Install

apt update && apt install -y restic restic version 

Ubuntu 24.04 ships restic 0.16 and Debian 12 ships 0.14; both support compression (repository format v2) and everything below.

2. Prepare the bucket

At your object storage, create:

  1. a dedicated bucket for backups (for example vps-backups),
  2. an access key limited to that bucket only. If the server is ever compromised, the attacker gets access to this bucket and nothing else.

If your storage supports object versioning or object lock, turning it on protects older backups even if someone deletes files with that key.

3. Credentials and repository password

Keep all secrets in one root-only file:

umask 077 openssl rand -base64 32 > /root/.restic-password cat > /root/.restic.env <<'EOF' export RESTIC_REPOSITORY="s3:https://s3.example-storage.com/vps-backups/web1" export RESTIC_PASSWORD_FILE="/root/.restic-password" export AWS_ACCESS_KEY_ID="your-key-id" export AWS_SECRET_ACCESS_KEY="your-secret-key" EOF chmod 600 /root/.restic.env /root/.restic-password 
  • Replace the endpoint with your storage's S3 endpoint. The path after the bucket (web1) lets several servers share one bucket in separate repositories.
  • Some storage needs a region too: add export AWS_DEFAULT_REGION="...".

Copy the repository password somewhere off this server now (a password manager is ideal). Without it, the backups cannot be decrypted by anyone, including you. Losing the server and the password means losing the backups.

Initialise the repository:

source /root/.restic.env restic init 

4. Decide what to back up

Back up data and configuration, not the operating system. A typical list:

Path Why
/etc All service configuration
/home, /root Users' files, scripts, SSH keys
/var/www, /srv, /opt Sites and applications (whichever exist)
/var/backups/db Database dumps (see below)
/var/spool/cron Users' crontabs

Never back up live database files (/var/lib/mysql, /var/lib/postgresql) as plain files; a copy taken while the database writes can be unusable. Dump first, then back up the dump.

5. The backup script

cat > /usr/local/sbin/restic-backup.sh <<'EOF' #!/usr/bin/env bash set -euo pipefail source /root/.restic.env # 1. database dumps (keep the lines you need) install -d -m 700 /var/backups/db # mysqldump --single-transaction --all-databases > /var/backups/db/mysql.sql # sudo -u postgres pg_dumpall > /var/backups/db/postgres.sql # 2. snapshot restic backup \ --exclude-caches \ --exclude '/home/*/.cache' \ --tag daily \ /etc /home /root /var/www /var/backups/db # 3. retention restic forget --prune \ --keep-daily 7 --keep-weekly 4 --keep-monthly 6 # 4. integrity: on Sundays, read back 5% of the stored data if [ "$(date +%u)" = "7" ]; then restic check --read-data-subset=5% fi echo "backup ok $(date -Is)" EOF chmod 700 /usr/local/sbin/restic-backup.sh 

Edit the path list to match folders that exist on your server; restic stops with an error on a path that does not exist, which is what you want (a typo should not silently skip data).

Notes:

  • --exclude-caches skips folders marked with a standard CACHEDIR.TAG file.
  • forget --prune removes snapshots outside the policy and frees their space.
  • check --read-data-subset=5% downloads and verifies a different random 5% each week, so over time the whole repository gets read back.

Run it once by hand and watch the output:

/usr/local/sbin/restic-backup.sh source /root/.restic.env && restic snapshots 

6. Schedule it with cron

cat > /etc/cron.d/restic-backup <<'EOF' SHELL=/bin/bash PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin 17 3 * * * root flock -n /run/restic-backup.lock /usr/local/sbin/restic-backup.sh >> /var/log/restic-backup.log 2>&1 EOF 
  • flock -n makes sure a slow run is never overlapped by the next one.
  • Pick an odd minute; many servers run jobs at exactly 03:00.
  • Rotate the log by adding /var/log/restic-backup.log to a file in /etc/logrotate.d/ (weekly, rotate 8, compress).

To get told when backups stop, have the script ping a heartbeat monitor (for example a self-hosted Uptime Kuma push monitor) as its last line. A missing ping then raises the alarm, which catches failures that never produce an error at all.

7. The restore test

Do this today, then once a month or after every big change.

source /root/.restic.env restic snapshots # restore one folder from the latest snapshot into a scratch directory restic restore latest --target /tmp/restore-test --include /etc/ssh # compare with the live copy diff -r /etc/ssh /tmp/restore-test/etc/ssh && echo "identical" # what changed between the two most recent snapshots? restic diff $(restic snapshots --json | python3 -c 'import json,sys; s=json.load(sys.stdin); print(s[-2]["short_id"], s[-1]["short_id"])') rm -rf /tmp/restore-test 

For a full drill, spin up a fresh, cheap server, install restic, copy over /root/.restic.env and the password, and restore everything there. Time it. That number is your real recovery time, and doing it once exposes what you forgot (a crontab, a TLS key, a .env file outside the backed-up paths).

To browse snapshots like a file system (needs apt install fuse3):

mkdir -p /mnt/restic && restic mount /mnt/restic 

Common mistakes

Mistake Fix
Repository password only on the server Keep a copy in a password manager
Root key for the whole storage account on the server Bucket-scoped key
Backing up live database files Dump first
Never restoring Monthly restore test, heartbeat monitoring
Backup in the same place as the server Different storage, ideally a different location

Provider snapshots vs restic

Host-level backups and snapshots are a good complement: they bring back the whole server quickly after a bad upgrade. They do not replace an independent, encrypted copy that you control in a separate place.

I work with PhantomVPS, so as an example: our Instant VPS plans include a Server tools box where you can add automatic daily and weekly backups (priced per plan, shown on the service page) and keep up to 3 snapshots, for example before a risky change. Use them for fast rollback, and restic for the off-server copy you can restore anywhere. The restic setup above works on any Ubuntu or Debian server.