rsync (Remote Sync) is fast, remote and local file transferring tool. It’s used for copying as well as synchronizing files/directories in UNIX/Linux systems.
Pros:
– Supports copying links, devices, owners, groups and permissions.
– It’s faster than scp (Secure Copy) because rsync uses remote-update protocol which allows to transfer just the differences between two sets of files. First time, it copies the whole content of a file or a directory from source to destination but from next time, it copies only the changed blocks and bytes to the destination.
– Rsync consumes less bandwidth as it uses compression and decompression method while sending and receiving data both ends.
Some common options used with rsync commands:
-v, –verbose increase verbosity
-H, –hard-links preserve hard links
-x, –one-file-system don’t cross filesystem boundaries
-z, compress file data
-h, human-readable, output numbers in a human-readable format
-P same as –partial –progress
–partial keep partially transferred files
–progress show progress during transfer
-r, –recursive copies data recursively (but don’t preserve timestamps and permission while transferring data
-a, –archive archive mode, archive mode allows copying files recursively and it also preserves symbolic links, file permissions, user & group ownerships and timestamps
NOTE: You can use either -r or -a to transfer a directory.
Usages:
1) Normal usage
rsync -avHx source destination
2) From remote server to local
rsync -avHx user@server:/absolute/path/source /absolute/path/destination
3) From local to remote server
rsync -avHx /absolute/path/source user@server:/absolute/path/destination
4) Exclude particular file/directory
rsync -avHx source –exclude=”/path/to/file” –exclude=”/path/to/folder/*” destination
5) Connect to remote server using absolute SSH command:
rsync -PavHx source -e “ssh -i /path/to/PrivateKey.pem” user@server:/absolute/path/destination