Rsync Backups
rsync is the standard Unix tool for efficient file synchronization and backup. It transfers only the differences between source and destination, making it fast for incremental backups of large directories. rsync over SSH is the simplest way to copy files between servers securely without setting up additional software. It is the tool behind most simple backup scripts on Linux servers.
How rsync works
rsync delta transfer:
Source file: 100MB file (modified 5MB in the middle)
Destination: same 100MB file from yesterday
↓
rsync splits files into blocks, computes checksums
↓
Transfers only changed blocks: ~5MB transferred (not 100MB)
↓
Destination file updated to match source
First backup: transfers everything (full copy)
Subsequent backups: transfers only changes (fast)Basic rsync commands
# Essential rsync flags:
# -a = archive mode (preserves permissions, timestamps, symlinks, owner)
# -v = verbose (show what's being transferred)
# -z = compress during transfer (good for slow networks)
# -h = human-readable sizes
# --delete = delete files in destination that no longer exist in source
# --exclude = skip files matching this pattern
# -n = dry run (show what would be transferred without doing it)
# Backup /var/www to a local directory:
rsync -avh /var/www/ /mnt/backup/www/
# Dry run first to preview:
rsync -avhn /var/www/ /mnt/backup/www/
# Backup with deletion (make destination exactly mirror source):
rsync -avh --delete /var/www/ /mnt/backup/www/
# Exclude patterns:
rsync -avh --exclude="*.log" --exclude="cache/" /var/www/ /mnt/backup/www/
Incremental backup with hard links
# rsync + hard links = space-efficient incremental backups
# Each snapshot directory looks like a full backup but only uses space for changes
sudo nano /usr/local/bin/rsync-backup.sh
/usr/local/bin/rsync-backup.sh — incremental backup with snapshots
#!/bin/bash
BACKUP_DIR="/mnt/backup"
SOURCE="/var/www"
DATE=$(date +%Y-%m-%d)
LATEST="$BACKUP_DIR/latest"
rsync -avh --delete --link-dest="$LATEST" \ # Hard-link unchanged files from latest snapshot
"$SOURCE/" "$BACKUP_DIR/$DATE/"
# Update the 'latest' symlink to point to today's snapshot:
rm -f "$LATEST"
ln -s "$BACKUP_DIR/$DATE" "$LATEST"
echo "Backup complete: $BACKUP_DIR/$DATE"
# Each daily directory appears to be a full backup:
ls /mnt/backup/
# 2025-06-07/ 2025-06-08/ 2025-06-09/ latest -> 2025-06-09/
# Files unchanged between days are hard links (same inode, no extra disk space):
ls -li /mnt/backup/2025-06-08/index.html /mnt/backup/2025-06-09/index.html
# Same inode number = hard link, not a copy
Rsync over SSH to remote servers
# Push backup to remote server:
rsync -avh /var/www/ backupserver:/backup/webserver-www/
# Pull backup from remote server:
rsync -avh backupserver:/backup/ /local/restore/
# Specify SSH key or options:
rsync -avh -e "ssh -i /root/.ssh/backup_key -p 2222" /var/www/ user@backupserver:/backup/
# Use a dedicated backup user with SSH restrictions:
# In /home/backupuser/.ssh/authorized_keys on the backup server:
# command="rsync --server --sender -logDtprze.iLsfxC . /backup/",no-port-forwarding,no-X11-forwarding ssh-rsa AAAA...
Conclusion
rsync with -a --delete --link-dest gives you space-efficient daily snapshots where each day looks like a full backup but only stores changed files. The critical flags: -a preserves all metadata, --delete removes files no longer in source (keeps mirror in sync), and --link-dest hard-links unchanged files from the previous backup to save space. Always do a dry run with -n first when using --delete to verify you won't accidentally remove important files.
FAQ
Is Rsync Backups important for Ubuntu administrators?+
Yes. It supports practical Ubuntu administration because it connects directly to server reliability, security, troubleshooting, or daily operations.
Should I practice this on a live server?+
Use a lab VM first. After you understand the command output and rollback path, apply the workflow carefully on real systems.
What should I do after reading this article?+
Run the practice commands, write down what each one shows, and continue to the next article in the Ubuntu roadmap.
Need help with Ubuntu administration?
Work directly with Muhammad Irfan Aslam for Ubuntu Server, Linux, cloud, Docker, DevOps, CI/CD, or infrastructure troubleshooting support.
Hire Me for Support