Quick Answer: To automatically backup a Linux VPS to offsite cloud storage, install rclone and restic, configure an S3-compatible bucket (such as Cloudflare R2, AWS S3, or Backblaze B2), and execute an automated daily cron script that captures MySQL database dumps and compressed filesystem snapshots with client-side AES-256 encryption.
Why Offsite Cloud Backups are Essential for Linux VPS
Running web applications on a cloud VPS without an automated, offsite disaster recovery system is an immense liability. While cloud providers offer manual hypervisor snapshots, hosting backups on the same infrastructure provider does not protect against account suspensions, data center hardware failures, filesystem corruption, or ransomware attacks.
The gold standard in server management is the 3-2-1 Backup Strategy: maintain at least 3 copies of your data across 2 different storage media types, with at least 1 copy stored completely offsite in independent cloud object storage.
Step 1: Installing and Configuring Rclone on Ubuntu / Debian
rclone is a high-performance command-line tool capable of synchronizing files directly to over 40 cloud storage providers, including Amazon S3, Google Drive, Backblaze B2, and Cloudflare R2.
# Install Rclone via official automated script sudo -v ; curl https://rclone.org/install.sh | sudo bash # Launch interactive cloud configuration rclone config
Follow the interactive prompts to create a new remote named cloudstorage, selecting your preferred S3 provider and pasting your API Access Key ID and Secret Access Key.
Step 2: Automated MySQL Database & Web Root Backup Script
Create a dedicated backup script at /usr/local/bin/vps-backup.sh that dumps all active MySQL databases and archives web application directories before syncing to your remote cloud bucket:
#!/bin/bash
# VPS Automated Cloud Backup Script
BACKUP_DIR="/var/backups/vps"
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
RETENTION_DAYS=7
mkdir -p ${BACKUP_DIR}
# 1. Dump all MySQL Databases
echo "Dumping MySQL databases..."
mysqldump --all-databases --single-transaction --quick --lock-tables=false > ${BACKUP_DIR}/all_databases_${TIMESTAMP}.sql
# 2. Archive Web Application Root
echo "Archiving web directories..."
tar -czf ${BACKUP_DIR}/webroot_${TIMESTAMP}.tar.gz /var/www /home/*/public_html 2>/dev/null
# 3. Encrypt and Upload to Cloud Storage via Rclone
echo "Uploading snapshots to S3 storage..."
rclone copy ${BACKUP_DIR}/ cloudstorage:my-vps-backups/daily/ --include "*_${TIMESTAMP}.*"
# 4. Clean up local backups older than retention window
find ${BACKUP_DIR} -type f -name "*_*.sql" -mtime +${RETENTION_DAYS} -exec rm {} \;
find ${BACKUP_DIR} -type f -name "*_*.tar.gz" -mtime +${RETENTION_DAYS} -exec rm {} \;
echo "Backup complete!"
Step 3: Scheduling Daily Cron Execution
Make the script executable and configure a system cron job to run every night at 3:00 AM UTC when web traffic is lowest:
sudo chmod +x /usr/local/bin/vps-backup.sh # Open crontab editor sudo crontab -e # Add daily 3:00 AM automated backup job 0 3 * * * /usr/local/bin/vps-backup.sh >> /var/log/vps-backup.log 2>&1
Testing Disaster Recovery & Backup Restoration
An untested backup is not a backup. Test your disaster recovery procedure by restoring your database and files to a staging directory once every quarter:
# List remote cloud backups rclone ls cloudstorage:my-vps-backups/daily/ # Download and restore specific database snapshot rclone copy cloudstorage:my-vps-backups/daily/all_databases_20260901.sql /tmp/ mysql < /tmp/all_databases_20260901.sql
Cryptographic Snapshot Deduplication with Restic & S3
While basic rclone file synchronization copies raw files over the network, deploying Restic alongside Rclone provides enterprise-grade cryptographic deduplication, point-in-time snapshot histories, and client-side AES-256 encryption before any byte leaves your server.
# Install Restic backup engine sudo apt install restic -y # Initialize an encrypted remote repository via rclone export RESTIC_PASSWORD="YourStrongEncryptionPasswordHere" restic -r rclone:cloudstorage:my-vps-backups/restic init # Create an incremental snapshot of web applications and databases restic -r rclone:cloudstorage:my-vps-backups/restic backup /var/www /var/backups/vps --exclude="*.log" --exclude="*.tmp"
Because Restic analyzes binary block hashes, if only 10 MB of data changes on a 20 GB WordPress site, the subsequent daily snapshot will complete in under 3 seconds and consume only 10 MB of remote cloud storage.
Automated Pruning and Retention Policies
To avoid accumulating years of obsolete snapshots and inflating cloud storage invoices, configure automated lifecycle pruning using Restic’s forgetting policy. Append this command to your daily cron job to retain the last 7 daily backups, 4 weekly backups, and 12 monthly backups:
# Prune old snapshots based on retention policy restic -r rclone:cloudstorage:my-vps-backups/restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 12 --prune
Cloud Storage Provider Comparison: S3 vs B2 vs R2 vs Google Drive
When selecting a destination for your automated Linux VPS backups, consider bandwidth egress pricing alongside per-gigabyte monthly storage fees. Here is how the top object storage backends compare in 2026:
| Storage Provider | Storage Cost / GB | Download Egress Fee | Best Use Case |
|---|---|---|---|
| Cloudflare R2 | $0.015 / GB | $0.00 (Zero Egress) | Top overall choice (10 GB Free Tier) |
| Backblaze B2 | $0.006 / GB | $0.01 / GB | Large multi-terabyte snapshot archives |
| Amazon AWS S3 Standard | $0.023 / GB | $0.09 / GB | Enterprise multi-region compliance |
Troubleshooting Common Rclone & Cron Backup Failures
- Rclone Token Expiration on Google Drive: If using Google Drive or OneDrive remotes, OAuth tokens may expire if the headless VM cannot refresh tokens. Prefer using S3 API keys with permanent service credentials for automated server infrastructure.
- MySQL Table Locking Timeouts: When executing
mysqldumpon active production databases with heavy write traffic, always specify--single-transaction --quickto ensure consistent snapshot reads without locking InnoDB tables or crashing user sessions. - Cron PATH Environment Issues: System cron executes in a minimal environment. Always define the full absolute paths to binaries (e.g.
/usr/bin/rcloneand/usr/bin/mysqldump) in your backup shell scripts.
🔗 Recommended Related Technical Guides:
Zero-Maintenance Hosting with Automated Backups
Don’t want to manage complex Linux backup cron scripts? CpanelFree provides enterprise cPanel web hosting with automated database tools, phpMyAdmin, and 1-click Softaculous installers at 100% zero cost.
Frequently Asked Questions
Which S3 cloud storage provider is most cost-effective for VPS backups?
Cloudflare R2 and Backblaze B2 are the most affordable choices. Cloudflare R2 offers 10 GB free storage with zero egress bandwidth fees, making backup restoration completely free.
Should I use Restic or Rclone for Linux backups?
Use Rclone for simple file synchronization and bucket transfers. Use Restic if you need cryptographic deduplication, point-in-time snapshots, and client-side encryption.

