Guides ยท Oct 5, 2026
Automated Encrypted VPS Backups with restic (Step by Step)
Back up a Linux VPS with restic: install, create an encrypted repository, back up files and database dumps, prune old snapshots and test restores.
A good backup strategy has one rule: the backup must exist somewhere other than the machine you are backing up. Provider backups (TidalVPS includes daily backups) are a great first layer, but you also want your own copy of the data that matters, under your control, that you can restore on any server. restic is a fast, encrypted backup tool that makes this simple. This guide sets it up on an Ubuntu or Debian VPS.
What to back up
- Your application data: uploads, world files,
/var/lib/docker/volumesfor Docker volumes, or/opt/yourapp. - Configuration:
/etc(nginx, ssh, systemd units), your crontab and.envfiles. - Database dumps instead of live database files.
You do not need to back up the operating system or packages. Those can be reinstalled in minutes, so keep a short note of what you installed.
1. Install restic
sudo apt update
sudo apt install -y restic
restic version
sudo restic self-update # optional: newer than the distro package
2. Choose where backups go
restic can write to many places. Pick one that is off this server:
- An S3-compatible object storage bucket (many providers offer one).
- Another server over SFTP, for example a second small cheap VPS or a storage box.
- Backblaze B2 and similar services through restic's built-in backends.
The examples below use SFTP. Set up key-based SSH access from your server to the backup target first (see securing SSH for key basics). Never put the repository only on the same disk you are backing up.
3. Create the encrypted repository
sudo mkdir -p /root/.config/restic
sudo sh -c 'umask 077; openssl rand -base64 32 > /root/.config/restic/password'
sudo restic -r sftp:backup@BACKUP_HOST:/srv/restic/myserver --password-file /root/.config/restic/password init
Copy that password file to a password manager or another safe place now. Backups are encrypted with it, and if you lose the password, the backups cannot be recovered by anyone. Having it only on the server you are backing up defeats the purpose.
4. A first manual backup
Put your settings in an environment file so that you do not repeat them:
sudo nano /root/.config/restic/env
export RESTIC_REPOSITORY="sftp:backup@BACKUP_HOST:/srv/restic/myserver"
export RESTIC_PASSWORD_FILE="/root/.config/restic/password"
sudo chmod 600 /root/.config/restic/env
sudo -i
source /root/.config/restic/env
restic backup /etc /opt /home --exclude-caches
restic snapshots
The first run uploads everything; later runs only send changed data, deduplicated and encrypted before leaving the server.
5. Dump databases before backing up
Copying live database files can capture them mid-write. Dump them to a file first:
mkdir -p /var/backups/db
mysqldump --all-databases --single-transaction > /var/backups/db/mysql.sql
sudo -u postgres pg_dumpall > /var/backups/db/postgres.sql
Include /var/backups/db in the restic backup. For SQLite, use sqlite3 app.db ".backup /var/backups/db/app.db".
6. Put it in a script
sudo nano /usr/local/bin/backup.sh
#!/bin/bash
set -euo pipefail
source /root/.config/restic/env
mkdir -p /var/backups/db
# mysqldump --all-databases --single-transaction > /var/backups/db/mysql.sql
restic backup /etc /opt /home /var/backups/db --exclude-caches
restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 6 --prune
restic check --read-data-subset=5%
sudo chmod 700 /usr/local/bin/backup.sh
The forget --prune line applies a retention policy: seven daily, four weekly and six monthly snapshots in this example. The final line verifies a random 5 percent of the stored data on every run, so corruption gets noticed.
7. Schedule it with a systemd timer
sudo nano /etc/systemd/system/backup.service
[Unit]
Description=restic backup
[Service]
Type=oneshot
ExecStart=/usr/local/bin/backup.sh
sudo nano /etc/systemd/system/backup.timer
[Unit]
Description=Nightly restic backup
[Timer]
OnCalendar=*-*-* 03:30:00
Persistent=true
RandomizedDelaySec=15m
[Install]
WantedBy=timers.target
sudo systemctl daemon-reload
sudo systemctl enable --now backup.timer
systemctl list-timers backup.timer
sudo systemctl start backup.service
journalctl -u backup.service -n 30
Running the service once by hand confirms it works before you rely on it. Persistent=true runs a missed backup after the server was off.
8. Test a restore (the step everyone skips)
A backup you have never restored is a hope, not a backup. Restore to a temporary folder:
source /root/.config/restic/env
restic snapshots
restic restore latest --target /tmp/restore-test --include /etc/nginx
ls /tmp/restore-test
You can also browse a snapshot with restic mount /mnt/restic (needs FUSE) or restore a single file with --include. Practise a full restore onto a spare server once. It builds confidence and shows you the steps you would need in a real emergency.
9. Get alerted when backups fail
A silent failure is the worst kind. Use OnFailure= in the service to trigger a notification, or call a free "dead man's switch" monitor URL at the end of the script with curl -fsS URL so that you are alerted when a backup does not check in. Uptime Kuma supports push monitors for exactly this.
Good habits
- Keep at least one copy somewhere your server credentials cannot delete. If an attacker gets into the server, they should not be able to wipe your backups too.
- Back up before risky changes, such as the Ubuntu upgrade.
- Document how to rebuild: which packages, which config files, where the password is.
Frequently asked questions
Do I still need my own backups if my VPS provider makes backups?
Provider backups are a good first layer. A separate copy that you control, stored elsewhere, protects you from account problems, mistakes and provider-wide issues.
Is restic encryption secure?
Repositories are encrypted and authenticated with your password, so the storage location cannot read your data. Keep the password safe, because it cannot be recovered.
How much space will backups use?
restic deduplicates data, so after the first full backup only changes are stored. Usage depends on how much of your data changes and on your retention policy.
How often should I back up?
Daily is a good default. Back up more often if your data changes quickly and losing a day would hurt.
Related guides
- Upgrade Ubuntu 24.04 to 26.04 LTS on a VPS (Safe Step-by-Step)
- How to Self-Host n8n on a VPS with Docker and HTTPS
- How to Install WordPress on an Ubuntu VPS (Nginx, PHP, MariaDB)
Need a server for this?
Every TidalVPS VPS comes with full root access, unmetered traffic, daily backups and DDoS protection.