A Linux VPS backup plan should survive three different failures: a bad update, a deleted file and the loss of the whole server. No single tool covers all three, so this guide combines provider snapshots, file archives, database dumps and off-site copies, and shows how to restore each one.
Before you start
- Root or sudo access to the VPS.
- Somewhere off the server to store copies: another server, object storage or a cPanel account with SSH.
- Read snapshot vs backup vs replication if the terms are new.
Layer 1: snapshots
A snapshot from your VPS provider's panel captures the whole disk in seconds. Take one before every risky change. Snapshots usually live on the same platform as the VPS, so they are not a substitute for off-site backups.
Layer 2: database dumps
Copying live MySQL data files can give a corrupt backup. Dump instead:
mysqldump --all-databases --single-transaction --routines --events | gzip > /backup/db-$(date +%F).sql.gzPostgreSQL:
sudo -u postgres pg_dumpall | gzip > /backup/pg-$(date +%F).sql.gzLayer 3: file archives
Back up what is unique to the server: web roots, configuration and home directories.
tar -czf /backup/files-$(date +%F).tar.gz /etc /var/www /home /root --exclude=/home/*/.cacheLayer 4: off-site copy with rsync
rsync -az --delete /backup/ backupuser@backup.example.net:vps1/Use an SSH key without a passphrase limited to that user. More in rsync backups; for encrypted, deduplicated backups see restic or rclone to S3.
Automate with cron
Put the commands in /usr/local/bin/backup.sh, make it executable and schedule it:
30 2 * * * /usr/local/bin/backup.sh >> /var/log/backup.log 2>&1Delete old local copies to save space:
find /backup -name "*.gz" -mtime +7 -deleteRestore
- Single file:
tar -xzf files-2026-01-10.tar.gz -C / var/www/example.com/index.php - Database:
gunzip < db-2026-01-10.sql.gz | mysql - Whole server: restore the provider snapshot, or build a fresh VPS, install the same packages, then extract the archives and import the dumps.
Warning: A backup you have never restored is a guess. Restore to a test VPS every few months.
FAQ
How often should I back up a VPS?
Daily for databases and changing files, weekly snapshots, and always before upgrades. Follow the 3-2-1 rule.
Are snapshots enough?
No. They usually sit on the same provider and do not help if the account or platform has a problem.
Can I back up a VPS to my cPanel hosting?
Yes, if the plan has SSH and space, but keep within your plan's terms; dedicated backup storage is better for large servers.
