Sunday, June 5, 2011

Rsync using ssh in Linux

Rsync is mainly used for backup operations.It can be used also transfer the file from one place to another.
Just like rcp or rsh.
Only difference in this case is it  just copies the difference between the target and destination file.If some data is missing in the destination file  that alone is copied instead of the copying the complete data
It syncs the file between the two locations.
There are also many options available that control  the transfer.

For simple backup:
This option can be used
Here i am trying to transfer the file from /home/karthik  to /mnt/usb

/usr/bin/rsync -au /home/karthik  /mnt/usb
-u - in this case the file if exits in destination it will not be overritten.
-a-  in this case the data is sent in archive mode.

Rsync can be also be used to transfer the file to the remote server.

rsync -avz karthik@ /root/temp
z- enables compression

Rsync using ssh 
can also be made to use secure shell for transfer :
For this we need to use -e option:

rsync -avz -e ssh karthik@ /root/temp
-e specifies th remote shell to transfer.

Rsync is a effective command to perform the sync of files with many options available:

Some of the useful options are:

-r - to recursively transfer the files.
-z-to compress the files
-q-to quiet mode
-o - to preserve the owner information in the transfer
-g - to preserve group
-p - to preserve permissions of the file.
--timeout - to specify the time out information for the rsync to happen.
--rsync_path - this is used to the rsync comaand path in the remote shell.
 --delete - to delete the files in the destination if the files are not present in the target.
-d -directory structure is only modified in the destination not the file.
-v  - verbose
--progress-  to view the progress of the files.

Another example:

/bin/rsync -tzqogp -e ssh -o BatchMode=yes --rsync-path=/usr/bin/rsync --timeout=30 /home/kkk /home/fff   karthik@
Here the files /home/kkk and /home/fff are transferred from the local server  to the remote server's directory /home/karthik/  in BatchMode using the ssh secure shell.

No comments:

Post a Comment