Automatic Backups with rclone

rclone is a tool to synchronize files to over 70 cloud providers. Ideal for offsite automatic backups of your VPS.

02

Installation

bash
# Recommended method (always downloads latest version)
curl https://rclone.org/install.sh | sudo bash

# Verify
rclone version
03

Configure a cloud provider

bash
rclone config

Follow the interactive wizard. Examples for the most common providers:

Backblaze B2 (economical, recommended)

Amazon S3 / Wasabi / MinIO

Google Drive

  • n → new remote
  • Name: b2backup
  • Storage: 5 (Backblaze B2)
  • Account ID: enter your Application Key ID
  • Application Key: enter your Application Key
  • Done
  • n → new remote
  • Name: s3backup
  • Storage: 5 (Amazon S3 and compatible)
  • Provider: AWS / Wasabi / Other
  • Access Key ID and Secret Access Key
  • Region: enter the region (e.g. eu-central-1)
  • n → new remote
  • Name: gdrive
  • Storage: 17 (Google Drive)
  • Follow OAuth authentication in browser
04

Basic commands

bash
# List files on a remote
rclone ls b2backup:bucket-name/

# Copy local files → cloud
rclone copy /var/www/html b2backup:my-backup/www

# Sync (synchronizes, deletes files no longer present locally)
rclone sync /var/www/html b2backup:my-backup/www

# Copy with progress
rclone copy /var/www b2backup:backup/www --progress

# Copy only new/modified files (faster)
rclone copy /var/www b2backup:backup/www --update
05

Complete backup script

bash
sudo nano /usr/local/bin/backup-vps.sh
bash
#!/bin/bash
# Complete VPS backup with rclone
# Variables
REMOTE="b2backup:my-backup"
DATE=$(date +%Y-%m-%d)
BACKUP_DIR="/tmp/backup-$DATE"
LOG="/var/log/backup.log"

echo "=== Backup $DATE ===" >> $LOG
mkdir -p $BACKUP_DIR

# 1. MySQL backup
echo "Backup MySQL..." >> $LOG
mysqldump --all-databases -u root -p"$MYSQL_ROOT_PASSWORD" \
  --single-transaction --quick 2>/dev/null | gzip > $BACKUP_DIR/mysql-$DATE.sql.gz

# 2. Web file backup
echo "Backup /var/www..." >> $LOG
tar -czf $BACKUP_DIR/www-$DATE.tar.gz /var/www/html 2>/dev/null

# 3. Configuration backup
echo "Backup configs..." >> $LOG
tar -czf $BACKUP_DIR/configs-$DATE.tar.gz \
  /etc/nginx /etc/apache2 /etc/letsencrypt 2>/dev/null

# 4. Upload to cloud
echo "Upload to $REMOTE..." >> $LOG
rclone copy $BACKUP_DIR $REMOTE/daily/$DATE --progress 2>> $LOG

# 5. Local cleanup
rm -rf $BACKUP_DIR
echo "Backup completed: $DATE" >> $LOG

# 6. Delete backups older than 30 days from cloud
rclone delete --min-age 30d $REMOTE/daily/ 2>> $LOG
bash
sudo chmod +x /usr/local/bin/backup-vps.sh
06

Automation with cron

bash
sudo crontab -e
bash
# Backup every night at 3:00
0 3 * * * MYSQL_ROOT_PASSWORD=yourpassword /usr/local/bin/backup-vps.sh

# Weekly backup on Sunday at 2:00
0 2 * * 0 /usr/local/bin/backup-weekly.sh
07

Backup with encryption

To encrypt files before upload (recommended):

bash
rclone config
# Create a new remote of type "crypt"
# Name: b2encrypted
# Remote: b2backup:my-encrypted-bucket
# Enter a strong passphrase
bash
# Now use the encrypted remote
rclone copy /var/www b2encrypted:www

Files are encrypted before upload: even if the bucket is compromised, data is unreadable.

08

Incremental backup with `--backup-dir`

bash
# Keep a current version + backup of what changed
rclone sync /var/www b2backup:backup/current \
  --backup-dir b2backup:backup/$(date +%Y-%m-%d) \
  --progress
09

Verify backups

bash
# Check that files were uploaded
rclone ls b2backup:my-backup/ | head -20

# Compare local vs cloud (find differences)
rclone check /var/www b2backup:backup/www

# Download and verify a single file
rclone copy b2backup:my-backup/mysql-2025-01-01.sql.gz /tmp/
gunzip /tmp/mysql-2025-01-01.sql.gz
mysql -u root -p < /tmp/mysql-2025-01-01.sql
10

Restore from backup

bash
# Download all files from a specific date
rclone copy b2backup:my-backup/daily/2025-01-15 /tmp/restore/

# Restore database
gunzip /tmp/restore/mysql-2025-01-15.sql.gz
mysql -u root -p < /tmp/restore/mysql-2025-01-15.sql

# Restore web files
tar -xzf /tmp/restore/www-2025-01-15.tar.gz -C /

DeluxHost, founded in 2023, offers high-quality hosting solutions for various digital needs. We provide shared hosting, VPS, and dedicated servers with advanced security and global data centers.

© DeluxHost, All rights reserved. | VAT Number : IT17734661006
All Systems Operational