Don’t you just love a piece of software that has stood the test of time, and averted relegation to the wistful days of yore?? rsync is a perfect example of this. How has rsync achieved this? Well, you see, rsync is awesome!
Say you have a folder on a remote machine that you want to sync up locally. Your first instinct might be ftp. Haha… just kidding! Probably more like sftp or scp. If you are talking a handful of small files, sure those tools are ok. For larger files, or a large amount of files, rsync is your guy. Why? Check it…
rsync has brains. For starters, its faster. But wait there’s more! It will also figure out the diff and transfer only the diff.
Say your remote folder is:
/somePath/thumbnails/maxresdefault
Then perhaps your local folder is:
./maxresdefault
You can bring in the missing files from the remote box like so:
rsync -aP you@remoteBox:/somePath/thumbnails/maxresdefault .
This will take all files from the maxresdefault folder on the remote box – which don’t already exist in the maxresdefault folder on the local box – and copy them to the local maxresdefault folder. Pay careful attention to the fact the local maxresdefault folder is one level down & you don’t run the command from within the local folder itself.
This is “pull” mode. To do “push” mode, just reverse source and destination. Ie:
Pull: rsync [OPTION...] [USER@]HOST:SRC... [DEST] Push: rsync [OPTION...] SRC... [USER@]HOST:DEST
Note that you must have already been able to establish a normal ssh connection in order to do this.
Not only is rsync faster than sftp & scp and able figure out the diffs & only get what you are missing, but when you add the -P option (a combination of the –partial and –progress options), you get the ability to continue where you left off if you loose the connection or need to force it to stop.
The -a option means “archive mode” (another combination of a bunch of other options). Archive mode “ensures that symbolic links, devices, attributes, permissions, ownerships, etc. are preserved in the transfer”.
rsync also works very well for automated backups, but that is another post. Happy rsyncing!