How to Set Up Automatic VPS Backups to External Storage
Automatic VPS Backup Setup
Automatic backups are essential for protecting server data. They allow you to restore files in case of system failures, errors, or accidental changes. Storing backups on a separate server or in the cloud significantly increases reliability.
It is recommended to schedule daily or weekly backups to another VPS or cloud storage.
1. Preparing the Server
Make sure you have SSH access to the VPS.
Update the system:
sudo apt update && sudo apt upgrade -y
Install file synchronization tools:
For Ubuntu / Debian:
sudo apt install rsync -y
For CentOS:
sudo yum install rsync -y
Ensure access to external storage: another VPS, a remote server, NAS, or a cloud service.
2. Backing Up Using rsync
Basic command example:
rsync -avz /var/www/ user@backup-server:/data/backups/vps/
Explanation:
/var/www/— directory to be backed upuser@backup-server— user and hostname of the backup server/data/backups/vps/— backup directory on the remote server
To avoid password prompts, set up SSH keys:
ssh-keygen
ssh-copy-id user@backup-server
3. Cloud Backups via rclone
Suitable for Google Drive, Dropbox, S3, OneDrive, etc.
Installation:
sudo apt install rclone -y
or
sudo yum install rclone -y
Configuration:
rclone config
Backup command:
rclone sync /var/www/ cloud:vps-backups --progress
cloud is the name defined during configuration.
4. Automation Using cron
Open cron scheduler:
sudo crontab -e
Example for rsync (daily at 03:00):
0 3 * * * rsync -avz /var/www/ user@backup-server:/data/backups/vps/ >> /var/log/backup.log 2>&1
Example for rclone (at 02:00):
0 2 * * * rclone sync /var/www/ cloud:vps-backups --progress >> /var/log/backup.log 2>&1
5. Verification & Maintenance
- Check periodically that backups are being created
- Test the restore process at least once
- Monitor storage usage and remove outdated backups