Thursday, July 17, 2008

rsyn facts!!

What is Rsync?
rsync is a file transfer program for Unix systems. rsync uses the “rsync algorithm” which provides a very fast method for bringing remote files into sync. It does this by sending just the differences in the files across the link, without requiring that both sets of files are present at one of the ends of the link beforehand. Some features of rsync include

  1. Can update whole directory trees and filesystems
  2. Optionally preserves symbolic links, hard links, file ownership, permissions, devices and times
  3. Requires no special privileges to install
  4. Internal pipelining reduces latency for multiple files
  5. Can use rsh, ssh or direct sockets as the transport
  6. Supports anonymous rsync which is ideal for mirroring

The Basics

If you don’t already have it installed, get it done this way on Debian systems:

apt-get install rsync

On other Linux distributions you would use yum(Fedora/CentOS) or yast (SuSE) to install rsync.

The base requirement of the rsync system is that you install the rsync program on the source and destination hosts. The easiest way to transfer files is to use a remote shell account. To copy a group of files to your home directory on host, you can run this command:

rsync file1 file2 … host:

Rsync defaults to rsh as the remote shell and that is not secure. Instead you can have rsync use ssh by using the option –rsh or -e ssh option:

rsync -e ssh file1 file2 … host:destination_dir

Copying one folder to another:

rsync -r /home/lxpages/junk /home/backups/junk/

That will copy the folder with simple application, without that much are to preservation of permissions/owners/etc. To make exact
duplicates, we can add the -a switch.

rsync -av /home/lxpages/junk /home/backups/junk

The above retains ALL ownership/permission and rsync in verbose mode.

rsync -av --delete /var/www/junk /home/lxpages/junk

The –delete keeps destination folder identical to source by removing any files that don’t match src dir.

rsync -av --delete -e ssh /home/lxpages/junk

Rsync everything from remote server and folder /home/lxpages/junk to local server and folder /home/lxpages/junk.

There are many more examples which I will include later parts. For now just remember that man page is your friend. Simply type ‘man rsync’ and read/view all the available options you can play around with.


No comments: