RSync is useful for fast incremental transfer of data. It is very popular across business organizations as it comes with some pretty handy features which sets it apart from the rest. Some of them are;

1) Security – One can transmit the data using the ssh tunneling which provides encryption & safety from eavesdroppers.

2) Speed – Since rsync transmits only the data which has changed over subsequent time, the transmission is fast as only the bits which are changed are transferred & not the entire file. This can mean tremendous saving of time. It also comes with options which lets you fine-tune the transfer which can further improve the transfer speed.

3) Less Bandwidth Intensive – Rsync uses compression & decompression algorithms at the sending & receiving end respectively. This not only speeds up the transfer but also saves the bandwidth.

Let’s dive into using rsync. Rsync follows the basic syntax,

$rsync options source destination

The source & destination can be either local or remote. In case of remote destination, one needs to specify the login name, remote server name/IP address & the directory location.

Some basic Rsync options are;

-z : Enable Compression
-v : Verbose
-r : Recursive
-a : Archive(Recursive, symbolic links, permissions, timestamps, owner & group)

Now that you know what rsync is & have seen the basic syntax of the command, let’s look at a few examples which are mostly used in real-life scenarios.

1) Synchronize two directories on a local system

$rsync -zavr /var/www/html /home/shuttertux

As you can see, both directories are on the local system hence they need to be only referenced by their absolute path.

2) Synchronize files from a local to a remote system

$rsync – zavr /var/www/html root@192.168.100.102:/home/gaurav

Here, the destination directory is on the remote system hence I’ve specified, the user-name(root), the machine’s IP address(192.168.100.102) followed by the directory where I wish to copy the data to(/home/gaurav) on the remote system. Every-time you synchronize with a remote system, you’ll be prompted for a password. Password-less transfers are possible with rsync but we will look at them in a future post.

3) Using SSH with rsync

$rsync -ravz -e ssh /var/www/html root@192.168.100.102:/home/gaurav

The ‘-e ssh’ uses SSH to transfer the data securely.

4) Do not overwrite the modified files at the destination

$rsync -u /var/www/html root@192.168.100.102:/home/gaurav

Here the ‘-u’ option helps to prevent overwriting of modified files at the destination. This can be useful in a typical scenario, when the user on the system or a program modifies the file at the destination location & one needs to retain the modified version of the file.

5) Synchronize only the directory tree structure(not files)

$rsync -v -d /var/www/html root@192.168.100.102:/home/gaurav

The ‘-d’ option helps to synchronize only the directory tree structure and not files.

6) Do not transfer large files

$rsync -avz –max-size=’100K’ /var/www/html root@192.168.100.102:/home/gaurav

K = Kilobytes, M = Megabytes & G = Gigabytes

7) View the changes between the source and destination

$rsync -i /var/www/html root@192.168.100.102:/home/gaurav

There you go. Rsync can be your best friend. It is not difficult to master & once learnt can become indispensable in taking backups. Dig up the rsync man page for more details.

About these ads