How to Set Up Automatic VPS Backups to an External Storage
Automatic VPS Backup Setup
🔹 Why It’s Important
Automatic backups are essential for data security and server stability. They help to:
- protect your data from loss in case of system failure or human error;
- quickly restore your VPS after a crash or update problem;
- store backups safely on external storage, independent from your VPS.
It’s recommended to schedule backups daily or weekly to a remote server or cloud.
⚙️ 1. Preparing the VPS
Ensure you have SSH access to the VPS.
Update the system:
sudo apt update && sudo apt upgrade -y
Install the required tools.
For Ubuntu/Debian:
sudo apt install rsync -y
For CentOS:
sudo yum install rsync -y
Make sure you have access to the external storage (remote VPS, FTP, or cloud).
🌐 2. Setting Up Backups with rsync
rsync is a simple and reliable tool to synchronize data between servers. Example command:
rsync -avz /var/www/ user@backupserver:/backups/vps1/
Where:
/var/www/— directory to back up;user@backupserver— username and IP/domain of backup server;/backups/vps1/— path to store backups.
💡 Tip: Set up SSH key-based authentication to avoid password prompts:
ssh-keygen
ssh-copy-id user@backupserver
☁️ 3. Using rclone for Cloud Backups
rclone works with cloud storage like Google Drive, Dropbox, AWS S3, etc.
Installation:
sudo apt install rclone -y
or
sudo yum install rclone -y
Configuration:
rclone config
Choose n (new remote), set a name (e.g. gdrive), select storage type (Google Drive, S3, etc.), authorize access.
Example command:
rclone sync /var/www/ gdrive:vps-backups --progress
🕒 4. Automating with cron
To run backups automatically, create a cron job.
Open the cron editor:
sudo crontab -e
Add one of these lines:
0 3 * * * rsync -avz /var/www/ user@backupserver:/backups/vps1/ >> /var/log/backup.log 2>&1
or, for rclone:
0 2 * * * rclone sync /var/www/ gdrive:vps-backups --progress >> /var/log/backup.log 2>&1
Explanation:
0 3 * * *— runs every day at 03:00;- output is saved to
/var/log/backup.log.
🧱 5. Checking Backups
- Verify that new files appear in
/backupsor cloud storage. - Try restoring a few files to confirm integrity.
- Regularly clean up old backups to save storage space.