Automatic Backups with rsync

Ubuntu: Automatic Backups with rsync

Backups are essential for protecting your data against accidental deletion, corruption, or hardware failure. rsync is a powerful tool that synchronizes files and directories between locations. This guide explains how to set up automatic backups with rsync on Ubuntu servers.


Step 1: Install rsync

sudo apt update

sudo apt install rsync -y


Step 2: Run a Basic Backup

rsync -avz /source /backup

This copies files from /source to /backup with compression and verbose output.


Step 3: Backup to a Remote Server

rsync -avz /source user@remote-server:/backup

This synchronizes files to a remote HostPalace server via SSH.


Step 4: Automate Backups with Cron

Edit cron jobs:

crontab -e

Add a daily backup at midnight:

0 0 * * * rsync -avz /source /backup

Step 5: Exclude Files from Backup

rsync -avz --exclude='*.log' /source /backup

This excludes log files from the backup.


Step 6: Verify Backups

rsync --dry-run -avz /source /backup

This simulates the backup without making changes.


Best Practices

  • Always test backups with --dry-run before scheduling
  • Use SSH keys for secure remote backups
  • Store backups on separate disks or servers
  • Regularly verify backup integrity

Note: HostPalace servers support rsync-based backups, making it easy to protect client data across multiple locations.