Total visit on this blog

Thursday 12 July 2012

rsync – Great Backup Tool

sync is used to perform the backup operation in UNIX / Linux. rsync is a great tool for backing up and restoring files. rsync is basically a synchronous tools which is used synchronize the files and directories from one location to another in an effective way. rsync behaves much same as of rcp but it has many more options.

Important features of rsync

Speed: First time, rsync replicates the whole content between the source and destination directories. Next time, rsync transfers only the changed blocks or bytes to the destination location, which makes the transfer really fast.
Security: rsync allows encryption of data using ssh protocol during transfer.
Less Bandwidth: rsync uses compression and decompression of data block by block at the sending and receiving end respectively. So the bandwidth used by rsync will be always less compared to other file transfer protocols.
Privileges: No special privileges are required to install and execute rsync
Some of the additional features of rsync are:
  • support for copying links, devices, owners, groups and permissions
  • exclude and exclude-from options similar to GNU tar
  • a CVS exclude mode for ignoring the same files that CVS would ignore
  • can use any transparent remote shell, including rsh or ssh
  • does not require root privileges
  • pipelining of file transfers to minimize latency costs
  • support for anonymous or authenticated rsync servers (ideal for mirroring)

GENERAL

There are six different ways of using rsync. They are:
  • for copying local files. This is invoked when neither source nor destination path contains a : separator
  • for copying from the local machine to a remote machine using a remote shell program as the transport (such as rsh or ssh). This is invoked when the destination path contains a single : separator.
  • for copying from a remote machine to the local machine using a remote shell program. This is invoked when the source contains a : separator.
  • for copying from a remote rsync server to the local machine. This is invoked when the source path contains a :: separator or a rsync:// URL.
  • for copying from the local machine to a remote rsync server. This is invoked when the destination path contains a :: separator.
  • for listing files on a remote machine. This is done the same way as rsync transfers except that you leave off the local destination.
Note that in all cases (other than listing) at least one of the source and destination paths must be local.

Syntax

$ rsync options source destination
Source and destination could be either local or remote. In case of remote, specify the login name, remote server name and location.

Examples:

sync example for backing up/copying from remote server to local Linux computer:
rsync -arv user01@server.example.com:/home/user01/ /home/testuser/user01backup/
(/home/testuser/user01backup/ is a local Linux folder path)
Here is what the “-arv” option does:
a = archive – means it preserves permissions (owners, groups), times, symbolic links, and devices.
r = recursive – means it copies directories and sub directories
v = verbose – means that it prints on the screen what is being copied

rsync -rv user01@server.example.com:/home/user01/ /home/testuser/user01backup/
This example will copy folders and sub-folder but will not preserve permissions, times and symbolic links during the transfer

sync -arv –exclude ‘logs’ user01@serve.example.com:/home/user01/ /Users/testuser/user01backup/
This example will copy everything (folders, sub-folders, etc), will preserver permissions, times, links, but will exclude the folder /home/user01/logs/ from being copied

Use of “/” at the end of path:
When using “/” at the end of source, rsync will copy the content of the last folder.
When not using “/” at the end of source, rsync will copy the last folder and the content of the folder.
When using “/” at the end of destination, rsync will paste the data inside the last folder.
When not using “/” at the end of destination, rsync will create a folder with the last destination folder name and paste the data inside that folder.

No comments:

Post a Comment