How to use rsync

By | February 14, 2014

rysnc – for keeping remote folders synchronised

rsync is really good for keeping folders synchronised across two computers. With one command new or changed files can be sent over a network. It is even possible to compress and send the data securely via ssh.

The procedures for using it are a little different for linux and Windows. There are already quite a few good guides on the internet for this,  and I have tried to bring some of them together here.

Installing

Installing – Ubuntu/Linux

On ubuntu it is easy to install rsync. From a terminal type:

sudo apt-get install rsync

similar commands will exist for other flavours of Linux.

Installing – Windows

In windows we need to use cygwin to access rsync. This is easy enough: just run the cygwin setup file. Search for ‘rsync’ and install it.

how to use rsync

You can install rsync in windows using cygwin.

If you haven’t done so already I’d also recommend setting up openssh on cygwin at the same time (I’ve covered this here).

How to use rsync

Once installed on windows or linux, the usage of rsync should be pretty much the same.


rsync -avz -e ssh --exclude "*Trash*/" --exclude "*gconf*/" ~/ user@host:~/cygdrive/c

where the -e ssh indicates that we will connect via ssh – with ssh keys set up we won’t need a password everytime we run this command. There are also '--exclude' commands to ignore certain files or folders. This can be useful if there are temporary files that you don’t care about moving.

I like to have rysnc commands in a script to make it quicker and easier to synchronise my folders. rsync commands can also be scheduled with cron.

rsync and ssh

Using SSH keys can make synchronising between computers a bit more straightforward as you don’t have to type your password in each time to connect to the remote computer. This is something I’ve written about previously.

Further information on setting up rsync is available here or on the rsync website, and some more examples are available here.