Rsync principle and application detailed

Source: Internet
Author: User
Tags file permissions rsync


Rsync uses the rsync algorithm to synchronize files between local and remote two hosts, which transfer only a different portion of two files, rather than sending the entire transmission at a time, so the speed is pretty fast. The core algorithm assumes that similar files A and B are synchronized between two computers named and, which have access to file A and access to file B

Rsync uses the so-called "rsync algorithm" to synchronize files between local and remote two hosts, which transfer only a different portion of two files, rather than sending it all at a time, so it's very fast.

The core of the algorithm:

Suppose that a similar file A and B are synchronized between two computers named Alpha and beta, where Alpha has access to file a, and beta has access to file B. and assume that the network bandwidth between the host Alpha and beta is very small. Then the rsync algorithm will be done with the following five steps:

1.β splits file B into a set of data blocks that do not overlap with a fixed size of s bytes. The last piece may be smaller than S.

2.β performs two checks on each segmented block: One is a 32-bit scrolling weak checksum and the other is a 128-bit MD4 strong checksum.

3.β These checksum results to alpha.

4.α searches for a block of data with all the size S of file A (the offset can be optional, not necessarily a multiple of s) to find a block of data that has the same weak checksum and strong parity code as a piece of file B. This work can be done quickly with the help of scrolling checksums.

5.α sends a sequence of instructions to Beta to generate a backup of file a on beta. Each instruction here is either proof that file B has a block of data without retransmission, or a block of data that must not match any of the data blocks of file B.

The advantages of rsync are as follows:

1. Can be mirrored to save the entire directory tree and file system;

2. It is easy to maintain the original file permissions, time, soft and hard links;

3. Installation without special permission;

4. Optimized flow, high efficiency of file transfer;

5. You can use RCP, ssh and other means to transfer files, of course, can also be connected through the direct socket;

6. Support for anonymous transmission.

basic syntax via remote shell: rsync [OPTION] [USER@]HOST:SRC DEST uses a remote shell (such as SSH, rsh) to copy the contents of the remote machine to the local machine. The SRC address path is delimited by a single colon ":". rsync [OPTION] SRC [user@]host:dest uses a remote shell (such as rsh, SSH) to copy the contents of the local machine to the remote machine. The DEST address path is delimited by a single colon ":". Via Rsync Daemon way: rsync [option] [user@]host::src DEST or rsync [option] rsync://[user@]host[:P ort]/src [DEST] from remote rsync Copy files from the server to the local machine. The SRC address path is delimited by a double colon::. rsync [option] src [user@]host::D est or rsync [option] src rsync://[user@]host[:P ort]/dest copy files from the local machine to a remote rsync server. The DEST address path is delimited by a double colon::.

If the rsync command specifies only the SRC parameter without specifying the DEST parameter, the source file list is displayed instead of a synchronized copy. Rsync has many functional options, and the common options are as follows:

rsync Common Parameters

Options Description
-A,--archive Archive mode, keeping all file attributes equal to-rlptgod
-V,--verbose Details output
-R,--recursive Recursive handling of subdirectories
-R,--relative Using relative path information
-B,--backup Create a backup
-Z,--compress Compress files that are backed up while they are being transferred
--delete Used to synchronize directories from DEST to delete files that do not exist in SRC
--progress Show backup process

rsync mode

rsync [OPTION] ... src [src] ... [user@] Host:dest

rsync [OPTION] ... [user@] HOST:SRC DEST

rsync [OPTION] ... src [src] ... DEST

rsync [OPTION] ... [user@] HOST::SRC [DEST]

rsync [OPTION] ... src [src] ... [user@] HOST::D EST

rsync [OPTION] ... rsync://[user@]host[:P ort]/src [DEST]



Rsync has six different modes of operation:

Copy local files and start this mode of work when both SRC and des path information do not contain a single colon ":" delimiter.

Use a remote shell program (such as rsh, SSH) to copy the contents of the local machine to the remote machine. This mode is started when the DST path address contains a single colon ":" Separator.

Use a remote shell program (such as rsh, SSH) to copy the contents of the remote machine to the local machine. This mode is started when the SRC address path contains a single colon ":" Separator.

Copy files to the local machine from a remote rsync server. This mode is started when the SRC path information contains the "::" delimiter.

Copy files from the local machine to the remote rsync server. This mode is started when the DST path information contains the "::" separator.

List of files for the remote machine. This is similar to rsync transmission, but simply omitting the local machine information in the command.

working with instances: viewing server-side files and lists # rsync 9.186.110.53::

View the list of modules available on the server side and comment Information # rsync ibmuser@9.186.110.53::www/

View a list of directories and files in the server's WWW module (using the RSYNCD user authentication method) # Rsync ibmuser@9.186.110.53:/var/www/html/

View content in the service-side/var/www/html directory (use server-side system users for authentication, such as Ibmuser) to keep the client-server data synchronized # RSYNC-AVZ ibmuser@9.186.110.53::www//backup1/

Use background service to back up the content under the server's WWW module to the local/backup1 directory, retain the original permissions, attributes, owner and symbolic connections, and use compression to speed up data transfer. # Rsync–avz ibmuser@9.186.110.53:/var/www/html/backup2/

Use SSH to back up remote/var/www/html directory to local/backup2/directory # Rsync-avz--delete ibmuser@9.186.110.53::www//backup3/

Back up the remote WWW module to the local/backup3/directory, synchronize the directory, and delete the extra files in the local directory.

When there is a problem with the data of the server, it is necessary to restore the server through the client's data, so long as the client has the write permission of the server, the SRC and DEST parameters of the rsync command can be restored.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.