Host snapshots from your VPS provider are convenient before a risky OS upgrade, but they are not a real backup strategy. If your account is locked, a billing error happens, or you accidentally delete a directory and only notice three weeks later, a single provider-side snapshot will not save you.

For a small Linux server, my preferred setup uses restic to push encrypted, deduplicated snapshots to an S3-compatible object storage bucket in a different region, driven by a nightly systemd timer. It takes about fifteen minutes to set up, costs pennies per month, and keeps your recovery plan completely independent of your hosting provider.

1. Dump databases before snapshotting files

Never back up live PostgreSQL or SQLite data directories by copying raw files while the database is writing. You can end up with a torn, unrecoverable database. Dump them cleanly first:

# PostgreSQL
pg_dump -U app --format=custom app > /var/backups/db/app.dump

# SQLite (safe even under WAL mode)
sqlite3 /opt/myapp/data/app.db ".backup /var/backups/db/app.db"

If Postgres runs inside Docker Compose, pipe the dump out through docker compose exec -T:

docker compose -f /opt/myapp/compose.yaml exec -T db \
  pg_dump -U app --format=custom app > /var/backups/db/app.dump

Keep only the most recent dump in /var/backups/db/ and let restic handle version history and deduplication across days. That keeps local disk usage flat even when you retain months of daily snapshots.

2. Initialize a restic repository

Install restic, store your repository credentials and encryption passphrase in a root-only environment file (chmod 600), and initialize the remote repository once:

sudo apt install -y restic
sudo mkdir -p /etc/restic /var/backups/db
sudo chmod 700 /etc/restic

Create /etc/restic/env:

RESTIC_REPOSITORY=s3:https://s3.example.com/my-vps-backups
RESTIC_PASSWORD=a-long-random-passphrase-stored-in-your-password-manager
AWS_ACCESS_KEY_ID=your-scoped-access-key
AWS_SECRET_ACCESS_KEY=your-scoped-secret-key

Save that RESTIC_PASSWORD in your password manager right away, along with a copy of the repository URL and access keys. Without the passphrase, encrypted snapshots are useless—which is the whole point of client-side encryption.

set -a; source /etc/restic/env; set +a
restic init

3. Wrap dump, backup, and retention in one script

Put the nightly workflow in /usr/local/sbin/vps-backup.sh and mark it executable (chmod 700). Notice that we also include /etc/nginx, /etc/caddy, /etc/systemd/system, and .env files so rebuilding the server from scratch does not mean hunting down old configuration tweaks:

#!/usr/bin/env bash
set -euo pipefail

set -a
source /etc/restic/env
set +a

sqlite3 /opt/myapp/data/app.db ".backup /var/backups/db/app.db"

restic backup \
  /var/backups/db \
  /etc/nginx \
  /etc/caddy \
  /etc/systemd/system \
  /opt/myapp/.env \
  --exclude-caches

restic forget \
  --keep-daily 7 \
  --keep-weekly 4 \
  --keep-monthly 6 \
  --prune

restic check --read-data-subset=5%

Run it manually once to confirm it finishes cleanly, then wire it to a daily systemd timer at 02:30 with RandomizedDelaySec=15m. Because restic logs to stdout, journalctl -u vps-backup.service gives you a full history of every snapshot size and duration. Pair it with a dead-man's-switch ping at the end of the script so you notice immediately if the timer ever stops running or fails silently.

4. Do a restore drill

An untested backup is just a hopeful script. Once a month—or at least after initial setup—restore the latest snapshot into a temporary directory on your laptop or a scratch VM and verify the database dump actually loads:

restic snapshots
restic restore latest --target /tmp/restore-test
sqlite3 /tmp/restore-test/var/backups/db/app.db "PRAGMA integrity_check;"
rm -rf /tmp/restore-test

For PostgreSQL custom dumps, test loading into a throwaway database with pg_restore --list or pg_restore -d testdb. Also scope your object-storage key to a single bucket and consider enabling object versioning or append-only credentials if you want protection against a compromised host deleting historical snapshots. Doing that five-minute restore check once a month gives you real confidence that recovery actually works when a disk dies.