This tutorial sets up a daily VPS backup with restic 0.20.0, encrypted and incremental, sent to a second VPS running rest-server 0.15.0 in append-only mode. In that mode the application VPS can write new snapshots but cannot delete old ones. If someone breaks into the application server, or ransomware runs there as root, the backup history on the other side stays intact. Everything was tested on 29 November 2026 on two clean Ubuntu 24.04.5 LTS machines, including restoring a PostgreSQL database.
Why an append-only server
The most common VPS backup uses a credential stored on the server itself. Whoever breaks in and gets root gets the same credential and can wipe the backups before destroying the data.
rest-server is the restic project's official HTTP server. With the --append-only flag it accepts new files in the repository and refuses to delete or overwrite existing ones. Pruning old snapshots then happens only on the backup VPS, which keeps no credential on the application VPS.
The layout:
-
Application VPS (
203.0.113.10in the examples): dumps the database, runsrestic backupevery day at 03:15 and checks the repository. -
Backup VPS (
203.0.113.20): runs rest-server with TLS, a bcrypt password and--append-only, accepts port 8000 only from the application's IP and runs the weekly cleanup.
Replace the 203.0.113.x documentation addresses with your servers' public IPs.
Versions, and why not the apt package
| Component | Version used | Source |
|---|---|---|
| restic | 0.20.0 (19 Nov 2026) | restic releases |
| rest-server | 0.15.0 (23 Nov 2026) | rest-server releases |
| Example PostgreSQL | postgres:17.7 |
Docker Hub |
| OS | Ubuntu 24.04.5 LTS, amd64 |
Ubuntu 24.04's apt installs restic 0.16.4. Version 0.20.0 fixes two security issues in restore: --ownership-by-name could hand files to root when a user name did not exist on the target (#22178), and a symlink sharing a name with a directory could write outside the restore folder (#22180). That is why this guide installs the official binary and checks its SHA256.
What you need
- Two Linux VPS with Ubuntu 24.04 and root or
sudoaccess. The backup one needs disk for the snapshots; the application one is the server you already have. -
openssh-serverandufwon both, which ship with the standard Ubuntu Server image. - Docker on the application VPS, only if you follow the containerised PostgreSQL example.
Disk on the backup VPS. restic deduplicates and compresses. In the test, the snapshot (mostly
/etc, plus the dump) took 493 KiB, a 2.57x compression ratio. That holds for that content; measure yours after the first week withrestic stats.
1. Install rest-server on the backup VPS
Download the release binary, check the published hash and install it in /usr/local/bin:
cd /tmp
V=0.15.0
curl -fsSLO https://github.com/restic/rest-server/releases/download/v${V}/rest-server_${V}_linux_amd64.tar.gz
curl -fsSLO https://github.com/restic/rest-server/releases/download/v${V}/SHA256SUMS
sha256sum --ignore-missing -c SHA256SUMS
tar xzf rest-server_${V}_linux_amd64.tar.gz
sudo install -m 0755 rest-server_${V}_linux_amd64/rest-server /usr/local/bin/
rest-server --version
sha256sum must print rest-server_0.15.0_linux_amd64.tar.gz: OK. If it prints anything else, stop and download again.
Create a system user with no shell, the repository folder and the config folder:
sudo apt-get install -y apache2-utils
sudo useradd --system --home-dir /srv/restic --shell /usr/sbin/nologin restic
sudo install -d -o restic -g restic -m 0700 /srv/restic
sudo install -d -o root -g restic -m 0750 /etc/rest-server
TLS certificate
The HTTP password and the data cross the internet, so the connection needs TLS. A self-signed certificate is enough, because restic on the application VPS will trust exactly this certificate and no other. The subjectAltName must contain the IP the client will use:
BKP_IP=203.0.113.20
sudo openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:prime256v1 -days 3650 -nodes \
-keyout /etc/rest-server/key.pem -out /etc/rest-server/cert.pem \
-subj "/CN=backup-vps" -addext "subjectAltName=IP:${BKP_IP}"
sudo chown root:restic /etc/rest-server/key.pem /etc/rest-server/cert.pem
sudo chmod 0640 /etc/rest-server/key.pem
sudo chmod 0644 /etc/rest-server/cert.pem
If you reach the backup VPS by name, such as backup.example.com, use subjectAltName=DNS:backup.example.com instead.
HTTP user and password
Generate a long password for the app1 user and store its bcrypt hash:
openssl rand -hex 24
sudo htpasswd -B -c /etc/rest-server/htpasswd app1
sudo chown root:restic /etc/rest-server/htpasswd
sudo chmod 0640 /etc/rest-server/htpasswd
htpasswd asks for the password twice: paste the one openssl generated and keep it, because it goes to the application VPS. With --private-repos, the app1 user can only see the /app1/ repository. For a second server, add another user (without -c, which recreates the file).
systemd units
Both units follow the official rest-server example: systemd opens port 8000 through the socket and hands the connection to a sandboxed process with no network of its own and no write access outside /srv/restic.
```ini /etc/systemd/system/rest-server.socket
[Socket]
ListenStream=8000
[Install]
WantedBy=sockets.target
```ini /etc/systemd/system/rest-server.service
[Unit]
Description=restic REST server (append-only)
After=network.target
Requires=rest-server.socket
After=rest-server.socket
[Service]
Type=simple
User=restic
Group=restic
ExecStart=/usr/local/bin/rest-server --path /srv/restic --append-only --private-repos --htpasswd-file /etc/rest-server/htpasswd --tls --tls-cert /etc/rest-server/cert.pem --tls-key /etc/rest-server/key.pem
Restart=always
RestartSec=5
ReadWritePaths=/srv/restic
UMask=077
CapabilityBoundingSet=
LockPersonality=true
MemoryDenyWriteExecute=true
NoNewPrivileges=yes
PrivateNetwork=yes
PrivateTmp=yes
PrivateDevices=true
PrivateUsers=true
ProtectSystem=strict
ProtectHome=yes
ProtectClock=true
ProtectControlGroups=true
ProtectKernelLogs=true
ProtectKernelModules=true
ProtectKernelTunables=true
ProtectProc=invisible
ProtectHostname=true
RemoveIPC=true
RestrictNamespaces=true
RestrictAddressFamilies=none
RestrictSUIDSGID=true
RestrictRealtime=true
SystemCallArchitectures=native
SystemCallFilter=@system-service
[Install]
WantedBy=multi-user.target
Enable the socket and send a request without a password:
sudo systemctl daemon-reload
sudo systemctl enable --now rest-server.socket
curl -s -o /dev/null -w '%{http_code}\n' --cacert /etc/rest-server/cert.pem https://203.0.113.20:8000/app1/config
The expected answer is 401: the server is up and refused the request without a password. With -u app1:PASSWORD it becomes 404 while the repository does not exist yet.
Firewall
Port 8000 only needs to accept the application VPS. Allow SSH before enabling ufw so you do not lock yourself out:
sudo ufw allow OpenSSH
sudo ufw allow from 203.0.113.10 to any port 8000 proto tcp
sudo ufw enable
2. Install restic on the application VPS
cd /tmp
V=0.20.0
curl -fsSLO https://github.com/restic/restic/releases/download/v${V}/restic_${V}_linux_amd64.bz2
curl -fsSLO https://github.com/restic/restic/releases/download/v${V}/SHA256SUMS
sha256sum --ignore-missing -c SHA256SUMS
bunzip2 restic_${V}_linux_amd64.bz2
sudo install -m 0755 restic_${V}_linux_amd64 /usr/local/bin/restic
restic version
sha256sum should print restic_0.20.0_linux_amd64.bz2: OK, and restic version should print restic 0.20.0.
Bring only the backup VPS's public certificate to this server, for example with scp root@203.0.113.20:/etc/rest-server/cert.pem .. The key.pem key never leaves the backup VPS. Then create the config folder and the repository password:
sudo install -d -m 0700 /etc/restic
sudo install -m 0644 cert.pem /etc/restic/backup-cert.pem
sudo sh -c 'openssl rand -base64 48 > /etc/restic/password'
sudo chmod 0600 /etc/restic/password
Keep the repository password outside both servers. The contents of
/etc/restic/passwordare the encryption key. Without them no backup comes back, even with full access to the backup VPS. Copy them to your password manager now.
Create the environment file with 0600 permissions (sudo nano /etc/restic/env, then sudo chmod 0600 /etc/restic/env):
```ini /etc/restic/env
RESTIC_REPOSITORY=rest:https://203.0.113.20:8000/app1/
RESTIC_REST_USERNAME=app1
RESTIC_REST_PASSWORD=paste-the-htpasswd-http-password
RESTIC_PASSWORD_FILE=/etc/restic/password
RESTIC_CACERT=/etc/restic/backup-cert.pem
RESTIC_CACHE_DIR=/var/cache/restic
`RESTIC_REST_USERNAME` and `RESTIC_REST_PASSWORD` keep the HTTP password out of the URL, as described in the [restic documentation](https://restic.readthedocs.io/en/stable/030_preparing_a_new_repo.html#rest-server). `RESTIC_CACERT` makes restic accept only that certificate. The two passwords are different: the HTTP one authorises uploads to rest-server, and the repository one encrypts the data.
Initialise the repository as root:
```bash
sudo -i
set -a; . /etc/restic/env; set +a
restic init
The output starts with created restic repository ... at rest:https://203.0.113.20:8000/app1/.
3. Backup script with a database dump
Copying PostgreSQL's data folder while the database runs does not give you a reliable copy. The script runs pg_dump in custom format before the snapshot, and restic takes the dump along with everything else. The example assumes a containerised database in the db service of /opt/app/docker-compose.yml, with user and database app. Swap in your own database (for MySQL, mysqldump) or delete that block if the server has no database.
```bash /usr/local/sbin/restic-backup
!/usr/bin/env bash
set -Eeuo pipefail
umask 077
1. Consistent PostgreSQL dump before copying the files
install -d -m 0700 /var/backups/db
docker compose -f /opt/app/docker-compose.yml exec -T db \
pg_dump -U app -Fc app > /var/backups/db/app.dump.tmp
mv /var/backups/db/app.dump.tmp /var/backups/db/app.dump
2. Incremental, encrypted snapshot
restic backup \
--files-from /etc/restic/include.txt \
--exclude-file /etc/restic/exclude.txt \
--exclude-caches \
--one-file-system \
--tag diario
3. Check the repository structure
restic check
`umask 077` makes the dump readable by root only. `set -Eeuo pipefail` stops the script if the dump fails, so a backup never goes out with an empty dump unnoticed.
The paths live in two files:
```text /etc/restic/include.txt
/etc
/home
/root
/opt
/var/backups/db
```text /etc/restic/exclude.txt
/root/.cache
/home//.cache
/opt/*/node_modules
The list leaves out `/var/lib/docker`. Container volumes change while they run, and what you need back from there is the database, which is already in the dump. Config files and `docker-compose.yml` under `/opt` are in the snapshot.
Install the script:
```bash
sudo install -m 0700 restic-backup /usr/local/sbin/restic-backup
4. Schedule it with systemd
```ini /etc/systemd/system/restic-backup.service
[Unit]
Description=Backup da VPS com restic
Wants=network-online.target
After=network-online.target docker.service
[Service]
Type=oneshot
EnvironmentFile=/etc/restic/env
ExecStart=/usr/local/sbin/restic-backup
Nice=10
IOSchedulingClass=idle
```ini /etc/systemd/system/restic-backup.timer
[Unit]
Description=Backup diário da VPS com restic
[Timer]
OnCalendar=*-*-* 03:15:00
RandomizedDelaySec=30min
Persistent=true
[Install]
WantedBy=timers.target
RandomizedDelaySec spreads the start over up to 30 minutes, useful when several servers send to the same destination. Persistent=true runs a missed backup if the VPS was off at 03:15. The Description lines are free text.
Run the first backup by hand and only then enable the timer:
sudo systemctl daemon-reload
sudo systemctl start restic-backup.service
sudo journalctl -u restic-backup.service -n 30 --no-pager
sudo systemctl enable --now restic-backup.timer
sudo systemctl list-timers restic-backup.timer
In the test, the first backup read everything:
Files: 575 new, 0 changed, 0 unmodified
Added to the repository: 1.217 MiB (520.283 KiB stored)
snapshot 06929e98 saved
The second one, after inserting a row in the database, sent only the difference:
Files: 0 new, 1 changed, 574 unmodified
Added to the repository: 74.208 KiB (15.321 KiB stored)
5. Prove the application VPS cannot delete anything
Test append-only before trusting it. On the application VPS, as root with the environment loaded, try to delete a snapshot:
restic forget --keep-last 1 --prune
restic builds the list of what it would remove and fails when it tries to delete:
Remove(<snapshot/06929e98fa>) failed: unexpected HTTP response (403): 403 Forbidden
failed to remove one or more snapshots
The command exits with code 3 and both snapshots are still there. That 403 is the expected behaviour, and it is what protects the history.
6. Test the restore
A backup that was never restored is an assumption. The test below pulls the dump from the latest snapshot and restores it into an empty PostgreSQL, without touching production:
restic snapshots
restic restore latest --target /tmp/restore-test --include /var/backups/db --include /etc/hostname
docker run -d --name restore-db -e POSTGRES_PASSWORD=teste postgres:17.7
sleep 10
docker exec -i restore-db pg_restore -U postgres -d postgres --create --no-owner < /tmp/restore-test/var/backups/db/app.dump
docker exec restore-db psql -U postgres -d app -c 'select * from pedidos'
docker rm -f restore-db
In the test, the select returned the three rows written before the backup. Point the query at one of your own tables. Afterwards delete /tmp/restore-test, which holds real data.
The script's restic check verifies the repository structure. Once a month, also ask it to actually read part of the data:
restic check --read-data-subset=10%
The expected output ends with no errors were found.
7. Weekly cleanup on the backup VPS
Corrected on 1 December 2026. The first version of this step used
--keep-daily 7 --keep-weekly 4 --keep-monthly 6, which a compromised server can game. If you already set up the cleanup, replace theforgetExecStartline with the one in the unit below and runsudo systemctl daemon-reload.
With append-only, snapshots pile up until someone deletes the old ones, and that someone has to be the backup VPS. Install the same restic 0.20.0 there, using the commands from step 2, and create the folder with the repository password:
sudo install -d -o root -g restic -m 0750 /etc/restic-prune
sudo install -o root -g restic -m 0640 /dev/null /etc/restic-prune/app1.password
sudo nano /etc/restic-prune/app1.password
Paste the same contents as /etc/restic/password on the application VPS and save.
This is a deliberate trade-off. The backup VPS now holds the repository password and can read the backups. In exchange, the application VPS, the more exposed one, cannot destroy them. Treat the backup VPS as a sensitive server: key-only SSH, no other public service, and access only for whoever runs the backups.
The units run as the restic user, directly on the repository folder, without going through rest-server:
```ini /etc/systemd/system/restic-prune.service
[Unit]
Description=Limpeza dos snapshots antigos do repositório app1
[Service]
Type=oneshot
User=restic
Group=restic
Environment=RESTIC_REPOSITORY=/srv/restic/app1
Environment=RESTIC_PASSWORD_FILE=/etc/restic-prune/app1.password
Environment=RESTIC_CACHE_DIR=/var/cache/restic-prune
CacheDirectory=restic-prune
ExecStart=/usr/local/bin/restic forget --keep-within 90d --prune
ExecStart=/usr/local/bin/restic check
Nice=10
IOSchedulingClass=idle
```ini /etc/systemd/system/restic-prune.timer
[Unit]
Description=Limpeza semanal do repositório restic
[Timer]
OnCalendar=Sun *-*-* 05:00:00
RandomizedDelaySec=30min
Persistent=true
[Install]
WantedBy=timers.target
--keep-within 90d keeps every snapshot from the 90 days before the most recent one. The count starts from the latest snapshot, not from the clock. With one backup a day that is about 90 snapshots, and deduplication means each one only takes up what changed.
Rules that keep one snapshot per period don't hold up on an append-only repository, as the restic documentation explains. The application VPS has the repository password, so whoever breaks into it can write fake snapshots with any date (restic backup --time), each slightly newer than the real one from the same day, week or month. The weekly cleanup then keeps the fakes and deletes the real ones.
In a test with restic 0.20.0, with 71 days of real backups and one fake per day, five minutes newer, on the same host and path, --keep-daily 7 --keep-weekly 4 --keep-monthly 6 would delete 70 of the 71 real snapshots. The --keep-within-daily 7d --keep-within-weekly 1m --keep-within-monthly 6m variants pick one snapshot per period as well, and would also delete 70 of the 71. With --keep-within 90d, all 142 snapshots would stay, and the fakes show up in the list next to the real ones instead of replacing them. A fake dated 400 days in the future didn't move the window either: restic ignores future dates in this calculation and never deletes those snapshots.
Enable and run the cleanup once:
sudo systemctl daemon-reload
sudo systemctl start restic-prune.service
sudo journalctl -u restic-prune.service -n 40 --no-pager
sudo systemctl enable --now restic-prune.timer
To query the repository as the restic user, which has no shell, use runuser:
sudo runuser -u restic -- env RESTIC_PASSWORD_FILE=/etc/restic-prune/app1.password restic -r /srv/restic/app1 snapshots
In the test, a forget --keep-last 1 --prune run this way removed the snapshot the application VPS had failed to delete, and the application's next backup was saved normally.
The --keep-within window is also your deadline to spot an intrusion: if the application VPS is compromised, the last backup from before the intrusion leaves the repository 90 days later. In the snapshot list, two snapshots on the same day or a time you don't recognise are worth investigating. For more history or more time to notice, widen the window instead of going back to per-period rules: --keep-within 6m keeps six months (restic accepts y, m, d and h, but not w).
Keeping an eye on it
Three commands show whether backups are running:
sudo systemctl list-timers 'restic-*'
sudo journalctl -u restic-backup.service --since yesterday --no-pager
sudo systemctl --failed
If rest-server is down or the dump fails, restic-backup.service ends in error and shows up in systemctl --failed. Check it weekly or wire it into your monitoring.
Common problems
-
401 Unauthorizedonrestic init:RESTIC_REST_PASSWORDdoes not match the password stored inhtpasswd, or the user in the URL (/app1/) differs fromRESTIC_REST_USERNAME. With--private-repos, the two must match. -
Certificate error (
x509): the IP or name inRESTIC_REPOSITORYis not in the certificate'ssubjectAltName, orRESTIC_CACERTpoints to another file. Generate the certificate again with the right address and copycert.pemover again. -
Timeout on port 8000: the ufw rule on the backup VPS allows a different IP. Check with
sudo ufw statusand remember the source is the application VPS's public IP. -
The service fails at
pg_dump: the service name, user or database in the script do not match yourdocker-compose.yml. Run the dump command alone to see the error.
Next steps
- If the server runs n8n, Automatic n8n backups shows what to export from n8n and how to restore workflows and credentials. Its files can go into the restic include list.
- If the application VPS also runs containers, read The Docker port stays open with ufw, because Docker publishes ports around ufw's rules.
- To split application and backup across two machines, see the Linux VPS and Docker VPS plans. The plans do not include managed backups, and this is how you get your own.
Originally published at https://nuvits.net/en/blog/vps-backup-restic

Top comments (2)
The test in step 5 is the part I would steal first: running forget --prune from the application server and watching it fail with a 403, both snapshots still there. That is the only proof append-only actually works — a flag in a config file is not proof. I run the same kind of check on my own setup, because the backup that matters is the one the compromised machine cannot delete. And naming the trade-off openly — the backup VPS holding the repository password so it can prune — is honest and worth repeating.
Rereading the cleanup step after your comment, I found a gap in it. The weekly job ran
forget --keep-daily 7 --keep-weekly 4 --keep-monthly 6, and restic's docs warn that this kind of policy is unsafe on an append-only repo: restic.readthedocs.io/en/stable/06...A compromised client still can't delete anything, but it can add empty snapshots with a fake
--time, each a bit newer than the real one in its day or week. The next scheduledforgetkeeps the fakes and removes the real snapshots. For append-only repos the docs recommend--keep-within, which keeps every snapshot in the window, fakes included, so the extras show up instead of replacing the history. I've updated that step to use--keep-within 90d.