Overview #
rsync
is a fast, reliable, and versatile file-copying tool commonly used on Unix-like systems. It efficiently transfers and synchronizes files between machines and directories by only copying the differences between source and destination. Whether you’re backing up a home directory, syncing production servers, or replicating data across systems, rsync
is a must-have utility in your toolbox.
Why Use Rsync? #
- Efficient: Only transfers changed blocks.
- Flexible: Works over SSH or directly between local directories.
- Powerful: Supports filters, compression, and bandwidth throttling.
- Reliable: Retains file permissions, timestamps, symbolic links, and ownership.
Basic Usage #
Local File Sync #
rsync -avh ~/Documents/ /mnt/backup/Documents/
-a
: Archive mode (preserves permissions, symbolic links, timestamps, etc.)-v
: Verbose-h
: Human-readable numbers (like KB, MB)
Remote File Sync Over SSH #
rsync -avz -e ssh ~/Projects/ user@remote.server:/home/user/Projects/
-z
: Compress data during transfer-e ssh
: Use SSH as the transport protocol
Intermediate Examples #
Delete Files That No Longer Exist on the Source #
rsync -av --delete ~/Media/ /mnt/media_backup/
The
--delete
flag ensures that files deleted on the source are also deleted on the destination.
Exclude Specific Files or Directories #
rsync -av --exclude '*.mp4' --exclude 'node_modules/' ~/Projects/ /mnt/backup/
Dry Run (Simulate Before Execution) #
rsync -av --dry-run ~/Photos/ /mnt/photo_backup/
Advanced Usage #
Throttle Bandwidth Usage #
rsync -avz --bwlimit=5000 ~/Videos/ remote:/data/backup/
--bwlimit=5000
limits the bandwidth to ~5MB/s
Sync Using Rsync Daemon (for persistent services) #
Set up /etc/rsyncd.conf
on the server:
[files]
path = /srv/rsync/files
read only = no
list = yes
Then use:
rsync -av rsync://remote.server/files /local/dir/
Backup with Timestamped Directories #
rsync -a ~/Documents/ "/mnt/backups/Documents-$(date +%Y-%m-%d)/"
Useful for daily backups with clear naming.
Pros and Cons #
Pros #
- ✅ Fast, only transfers deltas
- ✅ Preserves all file metadata
- ✅ Works over SSH securely
- ✅ Ideal for scripting and automation
- ✅ Highly configurable
Cons #
- ❌ Not ideal for syncing databases or locked files
- ❌ Can be complex for new users
- ❌ No built-in encryption at rest (use filesystem or SSH layer for that)
- ❌ Windows support is limited without WSL or Cygwin
Conclusion #
rsync
remains one of the most powerful and efficient tools for syncing and backing up files. From simple directory copies to complex remote backups with bandwidth throttling and exclusion rules, rsync
can handle it all. It’s a staple for sysadmins, developers, and power users alike.
Further Reading: