The Short Answer
Every VPS dies eventually — a bad update, a hacked plugin, a deleted file, a provider outage. The question is never whether you will need a backup, only whether you have one that works. A solid VPS backup strategy has three layers: provider snapshots for fast whole-server restores, automated off-site file and database backups for protection against provider failure, and a restore test you actually perform. This guide sets up all three on Ubuntu 24.04, with scripts you can copy, schedule and forget — until the day they save your site.
The 3-2-1 Rule (and What It Means on a VPS)
Backup professionals follow the 3-2-1 rule: 3 copies of your data, on 2 different types of storage, with 1 copy off-site. On a VPS that translates to:
- The live data on the server itself (copy one).
- A provider snapshot — a whole-disk image stored by your provider (copy two, different storage).
- An off-site backup — files and databases copied to another server, an object-storage bucket, or your own computer (copy three, off-site).
A snapshot alone is not a backup strategy: it protects you from your own mistakes, but not from the provider having a bad day, your account being suspended, or a billing problem locking you out. An off-site backup alone is not a strategy either: restoring a whole server from files takes hours, while a snapshot restores in minutes. You need both, and this guide covers both.
Layer 1: Provider Snapshots
Every major VPS provider offers snapshots or automatic backups. They capture the entire disk at a point in time, and restoring one gives you back the whole server — operating system, configuration, applications, data — usually in a few minutes.
Typical offerings (checked 23 November 2026):
| Provider | Snapshot / backup option | Cost |
|---|---|---|
| DigitalOcean | Automated backups (weekly, kept 4 weeks) | 20% of the Droplet price |
| DigitalOcean | Manual snapshots | Charged per GB stored per month |
| Hostinger | Weekly backups | Included free on KVM VPS plans |
| Hetzner | Snapshots (manual, per server) | Small per-GB monthly fee |
| Vultr | Automatic backups | 20% of the instance price (plan-dependent) |
| Contabo | Snapshots via control panel | Available as an add-on |
Enable automatic backups in your provider’s panel the day you create the server — before you install anything important. Manual snapshots are useful before risky operations: take one before a major upgrade, a migration, or an experiment you might regret. Snapshots are the fastest recovery path for “the server is broken” scenarios, and they require zero maintenance once enabled.
One limitation to understand: snapshots live with your provider. If the provider’s storage has a catastrophic failure, or your account is compromised and the attacker deletes the snapshots, they are gone. That is what Layer 2 is for.
Layer 2: Automated Off-Site Backups with Restic
For off-site backups you want a tool that is encrypted, incremental (only changed data is copied after the first run), and able to write to cheap storage. Restic fits: it is a single binary, encrypts everything, deduplicates, and supports SFTP, S3-compatible storage, Backblaze B2, and local paths. It is in Ubuntu’s repositories.
Install Restic
sudo apt update
sudo apt install restic
Choose a destination
Good off-site destinations for a small VPS:
- Another cheap VPS or storage box (for example a Hetzner Storage Box or any second server) via SFTP.
- S3-compatible object storage — Backblaze B2, Wasabi, or Cloudflare R2 (R2 charges no egress fees, which matters at restore time).
- Your own computer or NAS, via SFTP, if it is reliably online.
For this guide we will use SFTP to a second server, since the setup is the same shape for any destination and SFTP needs no extra account. The same commands work with an S3 URL instead — only the repository address and environment variables change.
Initialise the repository
On the backup destination, create a directory for the backups. Then, on your VPS, initialise a restic repository over SFTP:
export RESTIC_REPOSITORY="sftp:backupuser@BACKUP_SERVER:/backups/myvps"
export RESTIC_PASSWORD="a-long-random-password-you-store-safely"
restic init
The restic password is the keys to the kingdom. Lose it and your backups are unreadable — there is no reset. Store it in a password manager, and also write it somewhere offline. Never put it in a script that is committed to a public repository.
Write the backup script
Create a script that dumps the databases, then backs up the files. Databases must be dumped to files first — copying a live MySQL data directory produces a corrupt backup.
sudo nano /usr/local/bin/vps-backup.sh
#!/bin/bash
set -e
# --- Configuration ---
export RESTIC_REPOSITORY="sftp:backupuser@BACKUP_SERVER:/backups/myvps"
export RESTIC_PASSWORD_FILE="/root/.restic-password"
DB_USER="root"
BACKUP_TMP="/var/backups/dbdump"
RETENTION_DAYS=30
mkdir -p "$BACKUP_TMP"
# --- Dump all MySQL databases ---
mysqldump -u "$DB_USER" --all-databases --single-transaction --quick \
| gzip > "$BACKUP_TMP/all-databases.sql.gz"
# --- Back up files ---
restic backup \
/var/www \
/etc/nginx /etc/apache2 \
/etc/letsencrypt \
/home \
"$BACKUP_TMP" \
--exclude /var/www/*/wp-content/cache \
--exclude '*.log' \
--tag auto
# --- Prune old snapshots ---
restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 3 --prune
A few notes on this script:
--single-transactiondumps InnoDB databases without locking tables, so your site stays responsive during the backup./etc/letsencryptis included so SSL certificates survive a restore (certificates are free to reissue, but restoring them avoids rate-limit and validation headaches).- The
--excludelines skip cache directories and logs, which are large and worthless to back up. restic forget --pruneenforces retention: 7 daily, 4 weekly and 3 monthly snapshots. Without pruning, backups grow forever.
Store the password in a root-only file instead of the script:
echo "a-long-random-password-you-store-safely" | sudo tee /root/.restic-password
sudo chmod 600 /root/.restic-password
Then make the script executable and run it once by hand to confirm it works:
sudo chmod +x /usr/local/bin/vps-backup.sh
sudo /usr/local/bin/vps-backup.sh
The first run copies everything and takes a while; later runs are incremental and fast.
Schedule it with cron
Run the backup nightly, at a quiet hour:
sudo crontab -e
Add this line (2:30 a.m. server time):
30 2 * * * /usr/local/bin/vps-backup.sh >> /var/log/vps-backup.log 2>&1
Check the log after the first scheduled run: tail -20 /var/log/vps-backup.log. A backup that silently fails is worse than no backup, because it creates false confidence — consider adding a monitoring check (see How to Monitor Your VPS) or a simple email alert on failure.
The rsync alternative
If restic feels like too much machinery, rsync over SSH is the simpler classic. It mirrors a directory to another server:
rsync -avz --delete -e ssh /var/www/ backupuser@BACKUP_SERVER:/backups/myvps/www/
--delete removes files on the destination that no longer exist on the source, keeping a true mirror. The trade-off: rsync keeps only the latest copy — if a file is corrupted on the source, the next rsync overwrites the good copy. Restic’s snapshots protect against that, which is why it is the recommended default. A common compromise is rsync with --link-dest for dated snapshots, but at that point restic is simpler.
Layer 3: WordPress-Specific Backups
If your VPS runs WordPress, add an application-level backup as well. Server-level backups restore the whole machine; WordPress-level backups let you restore a single post, a single plugin’s settings, or the database to yesterday without touching the server.
UpdraftPlus (free) is the standard choice: it backs up files and database to Google Drive, Dropbox, S3 or SFTP on a schedule, and restores from the WordPress admin panel. Install it, connect a remote storage destination, and set a daily schedule. For a WooCommerce store, back up more often — hourly database backups are reasonable when orders flow all day.
This layer is in addition to, not instead of, the server backups. A plugin backup cannot save you if the whole server is gone; a server backup cannot easily restore one deleted page.
What to Back Up (Checklist)
- [ ] Website files (
/var/wwwor your document root) - [ ] Databases (via
mysqldump, not raw file copies) - [ ] Web server configuration (
/etc/nginx,/etc/apache2) - [ ] SSL certificates (
/etc/letsencrypt) - [ ] Application configuration and environment files (
.envfiles,wp-config.php) - [ ] User home directories (
/home) — cron jobs, scripts, SSH keys - [ ] Docker Compose files and volumes (if you use Docker — see How to Install Docker on a VPS)
- [ ] Any custom scripts in
/usr/local/bin
Do not back up: operating-system files (reinstall instead), caches, logs, or package caches. A restore should rebuild the OS fresh and lay your data and configuration on top.
The Restore Test (Do This Before You Need It)
A backup you have never restored is a hope, not a backup. Test twice: once when you set the system up, and once every few months after.
Test 1 — file restore with restic. List snapshots and restore one file to a temporary location:
restic snapshots
restic restore latest --target /tmp/restore-test --include /var/www/html/wp-config.php
ls -la /tmp/restore-test/var/www/html/
If the file is there and readable, the backup chain works end to end: repository, password, network and data integrity.
Test 2 — database restore. Restore a dump to a scratch database and check the tables exist:
gunzip -c /var/backups/dbdump/all-databases.sql.gz | head -20
mysql -u root -p -e "CREATE DATABASE restore_test;"
gunzip -c /var/backups/dbdump/all-databases.sql.gz | mysql -u root -p restore_test
mysql -u root -p -e "SHOW TABLES FROM restore_test;" | head
mysql -u root -p -e "DROP DATABASE restore_test;"
Test 3 — full disaster drill (twice a year). Spin up a fresh VPS, install the base stack, restore files and database from the off-site backup, and confirm the site loads. This is the only test that proves you can rebuild from nothing — and it usually reveals one forgotten item (a cron job, an environment variable, a firewall rule) that you then add to the backup list. Document the steps as you go: in a real disaster you will be stressed, and a written runbook beats memory.
Troubleshooting
“restic: wrong password” on a scheduled run. The cron environment differs from your shell — the password file path or repository variable is not set. The script above sets both explicitly; if you used environment variables in your shell instead, move them into the script or a file cron can read.
“sftp: connection refused / permission denied.” The backup destination is unreachable or the SSH key is not set up for the cron user. Cron runs as root here, so the SSH key must be in /root/.ssh/, and the destination must accept it. Test with sudo ssh backupuser@BACKUP_SERVER — if that prompts for a password, key authentication is not working. See How to Use SSH Keys on Windows for the key concepts, which apply to server-to-server keys too.
Backups succeed but the disk fills up anyway. Two causes: the local database dumps in /var/backups/dbdump accumulate (the script overwrites the same file each night, so check for stray files), or restic’s local cache grows — clear it with restic cache --cleanup. Also check Docker and log growth; see How to Speed Up Your VPS for disk-cleanup steps.
“mysqldump: Got error 1045 Access denied.” The database user or password in the script is wrong. Prefer a dedicated backup user with only SELECT and LOCK TABLES privileges over using root, and store its credentials in /root/.my.cnf (mode 600) instead of the script:
[client]
user=backupuser
password=your-password
Then mysqldump --all-databases needs no -u or -p flags.
Restore works but the site shows a database connection error. The restored wp-config.php (or .env) points at a database name, user or password that does not exist on the new server. Recreate the database user with matching credentials, or update the configuration file. This is the most common post-restore issue and the main reason the full disaster drill matters.
Frequently Asked Questions
How often should I back up my VPS?
Daily for most sites; hourly database dumps for stores or forums where content changes constantly. Provider snapshots weekly (or before any risky change) complement the daily off-site backup. The right frequency is determined by how much data you can afford to lose: if losing a day of orders is unacceptable, back up hourly.
How much storage do I need for off-site backups?
Roughly 2–3 times the size of your live data for a month of retention, thanks to deduplication and incremental snapshots. A 10 GB site typically needs 20–30 GB of backup storage. Restic’s restic stats shows exactly how much your repository uses.
Are provider snapshots enough on their own?
No. They are the fastest recovery option and you should absolutely enable them, but they live with your provider and they capture the whole disk — including any malware or corruption already present. Off-site backups with version history protect against provider failure, account problems, and slow-burn corruption that snapshots faithfully preserve.
Should I back up to the same VPS?
Never as your only copy. A backup on the same disk protects against accidental deletion and nothing else — a disk failure, a provider outage or a ransomware-style attack takes the backup with it. Same-server copies are a convenience layer; off-site is the real backup.
What is the fastest way to recover from a total server loss?
Restore the provider snapshot to a new instance (minutes), then apply the latest off-site backup on top if the snapshot is older than your last off-site run. If no snapshot exists, rebuild from the off-site backup on a fresh server using your documented runbook — this is why the disaster drill matters.
Do I need to back up a server that only runs a VPN or a game server?
Back up the configuration, at least. A WireGuard server is a few small config files; a Minecraft server’s world directory is the irreplaceable part. The operating system and software can always be reinstalled — see How to Create a VPN on Your VPS with WireGuard and How to Host a Minecraft Server on a VPS for what each one needs.
The Bottom Line
Enable provider snapshots today, set up an automated off-site backup with restic tonight, and test a restore this week. The whole setup takes under an hour and then runs itself — and the day you need it, the difference between a five-minute snapshot restore and rebuilding from memory is the difference between a bad morning and a lost business.



Leave a Reply