How to Use Rsync, a Very Beautiful File Transfer & Synchronization Tool
Rsync is an amazing tool for direct server-to-server data transfers. Very speedy, and very smart!
You can use rsync to do synchronizations between source and destination, comparing them, and copying only what’s changed. What’s especially amazing is that rsync only transfers the “parts” of files that are different. This works on a byte-level, not just the file-level. So if only 5 bytes of a 10 MB file have changed, rsync will only transfer those particular 5 bytes. Just imagine the bandwidth savings here, and the speediness! (And oh, this is a linux-only tool. Windows is incapable of such byte-level file system manipulations. Sorry Windows peeps, but as a consolation prize, there does exist an rsync emulation tool.)
ssh remoteuser@remotehost:/remote/dir rsync -avz --progress -e ssh remoteuser@remotehost:/remote/dir/ /this/local/dir/
Note: Rsync has two major modes of operation. The modes are dependent on the absence or presence of the trailing slash on the source directory. The difference between the two is a little bit difficult to describe, but once you get it, you get it.
**Remember: trailing slash on the source directory matters quite a lot. Trailing slash on the destination directory doesn’t matter.
#1: rsync -av /some/path/a/ /some/otherpath/ #2: rsync -av /some/path/a /some/otherpath/
The first case will make /some/otherpath mirror the contents of /some/path/a.
While the second case will create a directory INSIDE OF /some/otherpath/a whose contents will mirror /some/path/a.
In general, we probably use the #1 case most often.
Note: To only simulate the transfer (and not move any files), add the “--dry-run” option.