Data loss is not a matter of “if” but “when” — a misconfigured script or accidental deletion can wipe months of work in seconds. Automated backups are your insurance policy. This guide covers three tools: rsync for simple file sync, Restic for encrypted snapshots, and Rclone for cloud storage. For help choosing a VPS with enough storage for backups, compare VPS providers on our comparison table.
Why You Need Automated Backups
- Recover from accidental file deletion or configuration errors (most common cause of data loss)
- Restore after security breaches or ransomware attacks
- Migrate between VPS providers without manual file transfers
- Maintain point-in-time recovery for databases and application state
Follow the 3-2-1 rule: three copies of your data, on two different media types, with one copy off-site (different provider or physical location).
Option 1: rsync — Simple File-Level Backups
rsync transfers only changed blocks, making it ideal for backing up web roots and config files:
#!/bin/bash
# /usr/local/bin/backup-rsync.sh
BACKUP_SRC="/var/www /etc /home"
BACKUP_DST="/backup/vps-daily"
REMOTE_HOST="[email protected]"
REMOTE_PATH="/backups/$(hostname)"
# Local backup
rsync -avz --delete --exclude="*.log" --exclude="cache/*" \
$BACKUP_SRC $BACKUP_DST/
# Remote backup (off-site)
rsync -avz --delete -e "ssh -i /root/.ssh/backup_key" \
$BACKUP_SRC $REMOTE_HOST:$REMOTE_PATH/Option 2: Restic — Encrypted, Deduplicated Snapshots
Restic creates encrypted snapshots with automatic deduplication. Each backup only stores changed data, saving significant storage space. Backups are encrypted with AES-256 before leaving your server.
# Install restic
sudo apt install -y restic
# Initialize a repository
restic init --repo /backup/restic-repo
# Create your first backup
restic --repo /backup/restic-repo backup /var/www /etc /home
# View snapshots
restic --repo /backup/restic-repo snapshotsSet up retention policies:
# Keep: 7 daily, 4 weekly, 6 monthly
restic --repo /backup/restic-repo forget --keep-daily 7 --keep-weekly 4 --keep-monthly 6 --prune
# Full automated backup script
#!/bin/bash
export RESTIC_REPOSITORY="/backup/restic-repo"
export RESTIC_PASSWORD="your-strong-password"
restic backup /var/www /etc /home --exclude="*.log" --tag=automated
mysqldump --all-databases | restic backup --stdin --stdin-filename mysql-dump.sql --tag=mysql
restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 6 --pruneOption 3: Rclone — Cloud Storage Backups
Rclone syncs data to Backblaze B2, AWS S3, Google Cloud Storage, Wasabi, and 40+ other providers:
# Install rclone
sudo -v ; curl https://rclone.org/install.sh | sudo bash
# Configure a remote (interactive)
rclone config
# Sync to cloud
rclone sync /var/www backup-remote:my-vps-backups/www \
--progress --checksum --exclude="*.log"Combine Restic with Rclone for encrypted cloud backups:
# Initialize Restic with rclone backend
restic init --repo rclone:backup-remote:restic-repo
# Backup directly to cloud storage
restic --repo rclone:backup-remote:restic-repo backup /var/www /etc
# Automate
#!/bin/bash
export RESTIC_REPOSITORY="rclone:backup-remote:restic-repo"
export RESTIC_PASSWORD="your-password"
restic backup /var/www /etc /home --exclude="*.log"
restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 6 --pruneAutomating with Cron
# Edit crontab: crontab -e
# Daily backup at 2 AM
0 2 * * * /usr/local/bin/backup-restic.sh > /var/log/backup.log 2>&1
# Weekly full backup to cloud (Sunday 3 AM)
0 3 * * 0 /usr/local/bin/backup-rclone.sh > /var/log/backup-cloud.log 2>&1
# Database dump every 6 hours
0 */6 * * * /usr/local/bin/backup-mysql.sh > /var/log/backup-db.log 2>&1Always test your backups:
sudo /usr/local/bin/backup-restic.sh
grep backup /var/log/syslog | tail -5
restic check --repo /backup/restic-repoRestoring from Backups
Knowing how to restore matters more than the backup itself:
# Restore latest snapshot
restic --repo /backup/restic-repo restore latest --target /restore
# Restore specific files
restic --repo /backup/restic-repo restore latest \
--include /var/www/myapp --target /tmp/restore
# Mount snapshot as filesystem
restic mount /mnt/restic-mountAutomated backups are non-negotiable for any production VPS. Start with rsync, add Restic for encrypted deduplication, and use Rclone for off-site storage. For a VPS with scalable storage, consider InterServer VPS or Cloudways managed VPS for managed backups. Always compare VPS providers on our comparison table before committing to a provider.




Leave a Reply
You must be logged in to post a comment.