How rsync works -- convert

Source: Internet
Author: User
How rsync works


One rsync

1) Software Overview

Rsync is a remote data synchronization tool that allows you to quickly synchronize files between multiple hosts through the LAN/WAN. Rsync is a tool used to replace RCP, which is currently maintained by Rsync uses the so-called "rsyncAlgorithmTo synchronize files between the local and remote hosts. This algorithm only transfers different parts of the two files, rather than transmitting the entire file each time, so the speed is quite fast. The machine running rsync server is also called backup server. One rsync server can back up data of multiple clients at the same time, or multiple rsync servers can back up data of one client.

Rsync can be used with RSH, ssh, or even daemon mode. Rsync server opens a 873 service channel (port) and waits for the peer rsync to connect. During connection, the rsync server checks whether the Password Matches. If the password is checked, file transmission can be started. When the first connection is complete, the entire file will be transferred once, and only different parts of the two files will be transferred at the next time.

Rsync supports most UNIX-like systems, including Linux, Solaris, and BSD. In addition, it also has corresponding versions on the Windows platform, including cwrsync and sync2nas.

The basic features of rsync are as follows:

Images can be used to save the entire directory tree and file system;
It is easy to maintain the permissions, time, and soft and hard links of the original file;
Installation without special permissions;
Optimized process, high file transmission efficiency;
You can use RCP, ssh, and other methods to transmit files. Of course, you can also use a direct socket connection;
Supports anonymous transmission.

2) Core algorithms

Assume that similar files A and B are synchronized between two computers named α and beta. Alpha has access to file a and beta has access to file B. In addition, it is assumed that the network bandwidth between host α and β is very small. Then, The Rsync algorithm is completed in the following five steps:

Beta splits file B into a group of data blocks with a fixed size of S bytes that do not overlap. The last part may be smaller than S.
Beta performs two types of verification on each split data block: one is a 32-bit rolling weak verification, and the other is a 128-bit md4 strong verification.
Beta sends the verification results to α.
α searches all data blocks of file a with the size of S (the offset can be optional, not necessarily a multiple of S ), to find data blocks with the same weak verification code and strong verification code as one of file B. This work can be quickly completed using the features of rolling verification.
Alpha sends a string of instructions to generate a backup of file a on Beta. Each instruction here is either a proof that file B has a data block and does not need to be re-transmitted, or a data block, this data block certainly does not match any data block of file B.


3) how it works



Ii. installation and configuration

First download the rsync Installation File
I use rsync-3.0.7.tar.gz.
: Http://

Step 1 extract:
Tar-zvxf rsync-3.0.7.tar.gz
CD rsync-3.0.7

./Configure -- prefix =/usr/local/rsync
There is a small problem here, that is, G ++/GCC is not installed, So we as a System Architect, this is a small point, according

Fix the error.

Install gcc/g ++
Rpm-ihv kernel-headers-2.6.18-164.el5.i386.rpm
Rpm-ihv glibc-headers-2.5-42.i386.rpm
Rpm-ihv glibc-devel-2.5-42.i386.rpm
Rpm-ihv libgomp-4.4.0-6.el5.i386.rpm
Rpm-ihv gcc-4.1.2-46.el5.i386.rpm
Rpm-IVH gcc-C ++-4.1.2-42. el5.i386. rpm

Continue Configuration
./Configure -- prefix =/usr/local/rsync
Make & make install

Ln-s bin/rsync/usr/bin # Make a shortcut to the bin directory, so that you can directly enter rsync to execute

# Add xinetd. D and set the permission to execute.

Ln-s bin/rsync/etc/xinetd. d
Chmod + x/etc/xinetd. d/rsync

Start rsync server
# Rsync -- daemon
Add a configuration file. Note that this configuration file must be manually added.
Vim/etc/rsyncd. conf
The following is a reference for the configuration file:
Uid = nobody
Gid = nobody
Use chroot = No # Do not use chroot
Max connections = 4 # the maximum number of connections is 4
PID file =/var/run/rsyncd. pid # storage location of PID files
Lock file =/var/run/rsync. Lock # lock file storage location
Log File =/var/log/rsyncd. log # storage location of Log File
Module Parameters
[Web_test] # Here is the Authentication Module name, which needs to be specified on the client side
Path =/home/web_test/# directory of the image to be created. It is indispensable!
Comment = This is a test # comment on this module
Ignore errors # ignore unrelated Io errors
Read Only = yes # Read-Only
List = No # column Files Not Allowed
Auth users = test # The authenticated user name. If this row is not used, it indicates that the user is anonymous and has nothing to do with the system.
Secrets file =/etc/backserver. Pas # authentication file name
Hosts allow =, # allow hosts
Hosts deny = # disable hosts
Transfer logging = Yes
Log format = "% A % F % L"
# Log format = "% o % H [% A] % m (% u) % F % L"

Here is my rsyncd. conf configuration:
Max connections = 2 # maximum number of connections
Log File =/var/log/rsync. log # Log File Path
Timeout = 300 # timeout

Comment = backup
Path =/usr/local/rsync/backup # actual path of this module
Read Only = No
List = Yes
Uid = root # folder user ID
Gid = root # folder Group
Auth users = test # authorize a user
Secrets file =/etc/rsyncd. Secrets # Password File

Special server settings:
Echo "test: 123456">/etc/rsyncd. Secrets
Chmod 600/etc/rsyncd. CONF/etc/rsyncd. Secrets
Echo "All:">/etc/hosts. Allow # Allow the host to allow all request services of the 113 server.

Special client settings:
Echo "123456">/etc/rsync. Pas
Chmod 600/etc/rsync. Pas

Client transfer test:
Rsync-AUV -- password-file =/etc/rsync. Pas test@ backup/data/test
It means to transfer the content in/data/test of the client to the backup folder on the server.
The following statement is slightly different from the preceding statement, but has different functions.
Rsync-AUV -- password-file =/etc/rsync. PAS/data/test test@ Backup (this will

The entire test folder is sent to the backup file on the server. Note that it does not contain the test content, but contains the folder)

Note: Disable iptables. Otherwise, it is easy to mislead the entire configuration process by mistake.


Thanks, thanks!

By itech
The copyright of this article is owned by the author itech. If it is reproduced, please include the author's signature and source. It shall not be used for commercial purposes. Otherwise, you shall be held legally responsible!

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: 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.