Technical Tutorials
Automated VPS Backup Solution (2025) - Protect Your Data from Catastrophic Loss
The complete 2025 guide to automated VPS backups. Learn how to use Rclone to sync your databases and files to cloud storage (S3/OneDrive/GD) on a schedule, building an unbreakable line of defense for your data.

In the world of VPS, there are only two kinds of people: those who are backing up, and those who have experienced data loss and are now tearfully scrambling to set up backups.
Whether it's an SSD hardware failure at your hosting provider, a hacker attack, or your own slip of the hand running rm -rf /, without a backup all your hard work (blog posts, user data, configuration files) can be wiped out in a single second.
This article will teach you how to use the powerful tool Rclone to build a fully automated, offsite, heterogeneous VPS backup solution.
Before diving into the technical details, remember the golden rule of backup used worldwide:
- 3 copies: Original data + 2 backups.
- 2 media types: Don't store them all on the same disk.
- 1 offsite: At least one backup must be stored in a physically different location (such as another data center or cloud storage).
Rclone is known as the "Swiss Army knife of cloud storage" and supports more than 50 mainstream storage providers (such as Google Drive, OneDrive, S3, Cloudflare R2, and more).
Run the official one-click installation script:
sudo -v ; curl https://rclone.org/install.sh | sudo bash
After installation is complete, enter rclone config and follow the prompts to configure your cloud storage.
We'll split the backup into two parts: databases and website files.
Create a backup script backup_db.sh:
#!/bin/bash
# 配置信息
DB_USER="backup_user"
DB_PASS="your_password"
DB_NAME="your_db_name"
BACKUP_DIR="/tmp/vps_bak/db"
DATE=$(date +%Y%m%d_%H%M%S)
# 创建备份目录
mkdir -p $BACKUP_DIR
# 导出数据库并压缩
mysqldump -u$DB_USER -p$DB_PASS $DB_NAME | gzip > $BACKUP_DIR/${DB_NAME}_$DATE.sql.gz
# 上传到云端 (假设你配置的 rclone remote 名字叫 remote_backup)
rclone copy $BACKUP_DIR remote_backup:vps_backups/database/ -q
# 清理本地临时文件(保留 1 天)
find $BACKUP_DIR -mtime +1 -name "*.sql.gz" -exec rm -rf {} \;
Create the script backup_files.sh:
#!/bin/bash
# 配置信息
SRC_DIR="/var/www/html"
BACKUP_DIR="/tmp/vps_bak/files"
DATE=$(date +%Y%m%d_%H%M%S)
# 创建备份目录
mkdir -p $BACKUP_DIR
# 压缩文件
tar -czf $BACKUP_DIR/web_files_$DATE.tar.gz $SRC_DIR
# 同步到云端
rclone copy $BACKUP_DIR remote_backup:vps_backups/files/ -q
# 清理本地 3 天前的备份
find $BACKUP_DIR -mtime +3 -name "*.tar.gz" -exec rm -rf {} \;
Now that we have the scripts, we need them to run automatically every day. Use Linux's built-in crontab:
crontab -e
Add the following content at the end of the file:
# 每天凌晨 2:00 备份数据库
0 2 * * * /bin/bash /path/to/backup_db.sh
# 每周日凌晨 3:00 备份网站文件
0 3 * * 0 /bin/bash /path/to/backup_files.sh
- Encrypted backups: Rclone supports the
cryptmodule, which can encrypt files before uploading. Even if the cloud storage provider is hacked, what the hackers get is unbreakable gibberish. - Multiple backup locations: You can configure multiple Rclone remotes and back up to OneDrive and S3 at the same time.
- Regular restore testing: This is the most important part! Every month, try manually restoring data from a backup once. A backup that can't be restored isn't a backup, it's a placebo.
Setting up this solution takes only 10 minutes, but it buys an indefinite insurance policy for your VPS business. When it comes to data security, any laziness can cost you dearly.
If you find manual scripts too much trouble, you can also try tools with a UI, such as Duplicati or BorgBackup, which offer deduplication and incremental backup features.