Cloud & Virtualization
Disaster Recovery Planning for a VPS: A Practical Guide
By NileVPS Team · Published · 5 min read
اقرأ المقال بالعربيMost teams think about disaster recovery for the first time on the worst day of the year: a dropped database, a compromised server, an update that left the machine unbootable. A disaster recovery (DR) plan is the work you do in advance so that day becomes an inconvenience instead of a catastrophe. You need no second data center, just to know what you protect, where the copies live, and how long recovery takes.
What counts as a disaster?
"Disaster" sounds like fire or flood, but for most small and medium projects the real causes are more ordinary:
- Human error:
rm -rfin the wrong directory, a migration run against production, a deleted DNS record. - Software failure: a bad package update, a corrupted filesystem, a full disk that crashes the database.
- Security incidents: ransomware, a stolen SSH key, a hacked CMS plugin that has to be wiped.
- Provider or hardware problems: a host node failure, a network outage in one location.
- Account problems: an expired payment, a lost password, a locked account with no recovery contact.
Only one of these is about hardware, which is why "my provider has redundant disks" is not a DR plan.
Step 1: Inventory what you must recover
Write down every piece of the system and where its state lives. For a typical web application on a VPS:
| Component | Where the state lives | How it is recovered |
|---|---|---|
| Application code | Git repository | Redeploy from Git |
| Database | /var/lib/postgresql or /var/lib/mysql | Restore from a dump or physical backup |
| User uploads | e.g. /var/www/app/storage | Restore from file backup |
| Server configuration | /etc/nginx, /etc/systemd, cron | Config management or backup |
| Secrets | .env files, certificates | Password manager or encrypted backup |
| DNS | Registrar or DNS provider | Exported zone file |
Anything without an answer in the last column is a gap. Secrets and DNS are the gaps people discover most often in the middle of an incident.
Step 2: Set recovery targets
Decide two numbers for each service: how much data you can afford to lose (RPO) and how long you can afford to be down (RTO). An online store might accept 15 minutes of data loss and two hours of downtime; an internal wiki might accept a day of both. These targets decide how often you back up and how much automation you need. We cover them in depth in RPO and RTO explained.
Step 3: Build layered backups
No single mechanism is enough. Combine layers:
- Snapshots of the whole VPS before risky changes such as OS upgrades. They are fast to take and fast to roll back, but they usually live with the same provider, so they are not a complete off-site copy.
- Application-level database dumps, which are consistent and portable:
pg_dump -Fc -U app appdb > /backup/appdb-$(date +%F).dump
mysqldump --single-transaction --routines appdb | gzip > /backup/appdb-$(date +%F).sql.gz- File backups of uploads and configuration with a deduplicating tool such as restic or BorgBackup, pushed to storage in a different provider or region:
restic -r s3:https://s3.example.com/my-backups backup /var/www/app/storage /etc
restic -r s3:https://s3.example.com/my-backups forget --keep-daily 7 --keep-weekly 4 --pruneFollow the 3-2-1 idea: three copies, on two kinds of storage, with one off-site. If an attacker gets root on your server, they can delete any backup the server can delete, so keep at least one copy the server can write to but not erase (append-only or immutable storage, or a pull-based backup run from another machine).
Step 4: Write the runbook
During an incident nobody remembers the exact pg_restore flags. A runbook is a short document, stored outside the server it describes, that lists:
- Who decides that a disaster is declared and who does the work.
- Where the backups are and how to access them (credentials kept in a password manager, not on the server).
- Exact steps to provision a new VPS, install the stack, restore data and switch DNS.
- How to verify the restored service works.
Keep DNS TTLs reasonably low (for example 300 seconds) on records you may need to repoint, so a switch to a new server takes effect quickly.
Step 5: Test the restore
A backup you have never restored is a hope, not a backup. Schedule a drill at least every quarter:
- Create a fresh VPS from the deploy page.
- Follow the runbook exactly, without shortcuts from memory.
- Restore the latest backup and check the data: row counts, recent orders, a few uploaded files.
- Time the whole process and compare it with your RTO.
- Fix every step that was unclear, then delete the test server.
Drills regularly reveal problems such as a silently empty dump, a missing encryption key, or a restore that takes six hours instead of one.
A minimal DR checklist
- [ ] Inventory of components and their state
- [ ] RPO and RTO agreed per service
- [ ] Automated daily database and file backups
- [ ] One off-site copy the server cannot delete
- [ ] Runbook stored outside the server
- [ ] Alerts on backup failure
- [ ] Restore drill in the last three months
FAQ
Are VPS snapshots enough for disaster recovery?
No. Snapshots are excellent for quick rollbacks, but they normally live with the same provider and account. A compromised account, or a mistake unnoticed for days, can leave you with no usable copy. Combine snapshots with off-site backups.
How often should I test my backups?
At minimum once a quarter, and after any major change to the stack, such as a database version upgrade or a new storage path. Automated checks that a backup file exists and is not empty are useful daily, but only a real restore proves the data is usable.
Do small websites really need a DR plan?
Yes, though it can be small. A single page listing where backups are, how to restore them and who to call beats improvising under pressure.