Can you ‘rsync’ with me??

Some of the things that a programmer needs to know is how to duplicate/back up his/her code so that even if he loses his /her copy, he/she can still recover his/her work. And of course, we want to do it with some security. Now I know you’re thinking SVN for the first one: SVN works like a charm, especially when it comes to coding and code updates. And for the second (security) one, there’s ssh.

Well, then, what about we combine back up and security in one go? This is where rsync comes in. With rsync, I “sync” (sorry, couldn’t help it with the joke) my work in my PC to another PC in the next room, or the server room. I can even sync with a PC halfway across the world. But where’s the security you ask? Well, that’s were ssh comes in.

We can use rsync and ssh together. rsync allows one directory’s data to be mirrored as is (even the permissions) to another directory, whether it be remote or local. And as you may know already, ssh takes care of the security, encryption, etc.

So how do we do it? Well, one implementation is the following:

rsync -e ssh -av <source> <destination>

It’s as simple as that. What the previous command basically says is that we use ssh as a remote shell (-e), print some information regarding the transfer (-v), and synchronize all files (-a).

As an example, say I have a PC at some room at some floor of the building with address , and I have a directory there:


Where I want to dump my current codes at the present working directory:


Now, let’s try ‘syncing’ my current working directory to my hard drive at

rsync -e ssh  -v  *  kubuntu@

Of course, since it is ssh, I am prompted to enter my password. After entering it, here’s what happens:

kubuntu@'s password:
skipping directory docs
skipping directory ma3x
skipping directory qt codes
skipping directory tests

sent 13317215 bytes  received 1406 bytes  409803.72 bytes/sec
total size is 13311523  speedup is 1.00

Success! So when I edit something in my current directory, even the smallest one, say I update a file’s time stamp:

$ ls -lh vid_log.txt
-rw-r--r-- 1 f f 40 2007-08-07 02:50 vid_log.txt

$ touch vid_log.txt

$ ls -lh vid_log.txt

-rw-r--r-- 1 f f 40 2007-08-08 00:27 vid_log.txt

There we go. So let’s see if our little rsync command will help us out with this little change. I again issue:

rsync -e ssh  -av  *  kubuntu@

and the output is

kubuntu@'s password:
building file list ... done

sent 121037 bytes  received 48 bytes  14245.29 bytes/sec
total size is 18345757  speedup is 151.51

Yet another success (^)___(^) Since all we modified was the file vid_log.txt, and when we issued the same rsync command as before, naturally it only needed to update the vid_log.txt file on the other directory! Nice.

Aahh… the wonders of ssh…more to come soon! (^)____(^)


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: