rsync Commands Reference
rsync is the standard tool for efficient file synchronisation and remote transfers. It only sends changed blocks, making it much faster than scp for large directories.
Basic syntax
rsync [options] SOURCE DESTINATION
Common flags: -a (archive — preserves permissions, timestamps, symlinks), -v (verbose), -z (compress in transit), -P (show progress + partial).
Sync over SSH on a custom port
rsync -azv --progress -e "ssh -p 16969" /home/user/public_html/mysite.com/ root@45.76.116.182:/home/user/public_html/mysite.com/
Sync using a specific SSH key
rsync -Pav -e "ssh -i $HOME/.ssh/mykey" username@hostname:/remote/dir/ /local/dir/
Sync using a specific key and port
rsync -Pav -e "ssh -i $HOME/.ssh/mykey -p 2222" username@hostname:/remote/dir/ /local/dir/
Delete files on destination that no longer exist in source
rsync -av --delete /source/dir/ user@host:/dest/dir/
Dry run (preview what would change)
rsync -av --dry-run /source/ user@host:/dest/
Backup with timestamp
rsync -av --backup --backup-dir=/backup/$(date +%Y-%m-%d) /source/ /dest/
Cron-based nightly sync
0 2 * * * rsync -az -e "ssh -i /root/.ssh/backup_key" /var/www/ backup@backup-server:/backups/www/ >> /var/log/rsync.log 2>&1