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 -rf in 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:

ComponentWhere the state livesHow it is recovered
Application codeGit repositoryRedeploy from Git
Database/var/lib/postgresql or /var/lib/mysqlRestore from a dump or physical backup
User uploadse.g. /var/www/app/storageRestore from file backup
Server configuration/etc/nginx, /etc/systemd, cronConfig management or backup
Secrets.env files, certificatesPassword manager or encrypted backup
DNSRegistrar or DNS providerExported 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:

  1. 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.
  2. 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
  1. 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 --prune

Follow 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:

  1. Create a fresh VPS from the deploy page.
  2. Follow the runbook exactly, without shortcuts from memory.
  3. Restore the latest backup and check the data: row counts, recent orders, a few uploaded files.
  4. Time the whole process and compare it with your RTO.
  5. 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.

Related guides