The best time to set up backups is before you need them. Here's a simple, reliable routine for any VPS.
What to back up
- Databases — the most critical and easiest to lose.
- Application files and user uploads.
- Configuration (web server, environment files).
A basic database backup
mysqldump mydb | gzip > /backups/mydb-$(date +%F).sql.gz
Automate with cron
0 3 * * * /usr/local/bin/backup.sh # every day at 3am
The golden rules
- Off-site: copy backups to another location (object storage, another server) — a backup on the same VPS won't help if the VPS fails.
- Rotate: keep several days/weeks and delete old ones.
- Test restores: a backup you've never restored is a guess, not a backup.
Many providers also offer snapshot backups as an add-on — convenient, but combine them with your own database dumps for full coverage.