VPS backup and snapshot guide
A server can fail because of a bad update, a mistake, malware or a hardware problem. A good plan combines snapshots, backups and a tested restore. On ONIE, Cloud Servers in Ho Chi Minh City support snapshots and backups, and you can add extra Block Storage for data.
Snapshot vs backup
| Snapshot | Backup | |
|---|---|---|
| What it is | A saved state of the disk at one moment | A separate copy of the server or its data |
| Best for | A quick way back before an upgrade or config change | Recovering from loss, damage or deletion |
| Kept | Close to the original server | On separate storage |
| Speed | Fast to take and restore | Slower, depends on size |
Use both: a snapshot before risky changes and scheduled backups for everything else.
The 3-2-1 rule
Keep 3 copies of important data, on 2 different kinds of storage, with 1 copy somewhere else. A snapshot on the same server is not enough on its own.
Back up files
rsync copies only what changed:
rsync -aH --delete /var/www/ backup@backup-host:/srv/backups/www/restic makes encrypted, deduplicated backups to many targets:
sudo apt install -y restic
restic -r sftp:backup@backup-host:/srv/restic init
restic -r sftp:backup@backup-host:/srv/restic backup /var/www /etc
restic -r sftp:backup@backup-host:/srv/restic forget --keep-daily 7 --keep-weekly 4 --pruneBack up a database
Copy the database with a dump instead of copying live data files:
mysqldump --single-transaction --routines -u root wordpress | gzip > /var/backups/wordpress-$(date +%F).sql.gzFor PostgreSQL use pg_dump.
Automate it
Run backups from cron or a systemd timer, and keep a retention policy so old copies are removed:
sudo crontab -e
# every day at 02:30
30 2 * * * /usr/local/bin/backup.shTest your restore
A backup you never restored is only a guess. Once a month, restore to a spare server and check that the site and the data work. Write down the steps so anyone on your team can do it.
Before big changes
Take a snapshot, make the change, test it, and delete the snapshot when you are sure. This pairs well with a secure SSH setup, and the same habit helps when you upgrade a WordPress site.
Frequently asked questions
How often should I back up?
Daily is common for sites and databases that change often. Back up more often if losing a day of data would hurt.
Are snapshots billed?
Snapshots and backups are billed by the space they use. See the current rates on the pricing page of the service.
Where should I store backups?
Not only on the same server. Use another location or provider so one failure cannot remove every copy.