Rsync file synchronization tool,

Source: Internet
Author: User
Tags rsync

Rsync file synchronization tool,

Some time ago, due to the needs of the company, we needed to synchronize and save the backup files. Later we thought of the file synchronization work Rsync which we are all most familiar with, so we had a great afternoon, then, the general process and Parameter Details are summarized.

First, I understand the general principle of rsync synchronization: Rsync uses the so-called "Rsync algorithm" to synchronize files between local and remote hosts, this algorithm only transmits different parts of two files, instead of the entire copy each time.

Therefore, the transmission speed is quite fast. The Rsync server opens a port of 873 and waits for the client to connect to Rsync. During connection, the Rsync server checks whether the password (passwd) matches. If the password is verified,

You can start file transmission. When the first connection is complete, the entire file will be transferred once, and only the difference between the two files will be transferred next time.

Next, let's make a preliminary setup and complete the task requirements first.

Rsync server (192.168.177.130)

Install rsync

Yum-y install rsync (A rsync configuration file is generated under the etc directory by default)

Edit the configuration file rsyncd. conf (you cannot add comments to the configuration file. Otherwise, an error is reported)

uid = root                     gid = rootuse chroot = nomax connections = 4#pid file = /var/run/rsyncd.pid      lock file = /var/run/rsyncd.locklog file = /var/log/rsyncd.log         exclude = lost+found/transfer logging = yestimeout = 600ignore nonreadable = yes           dont compress   = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2         [test]                                  path = /home/rsynctestignore errors = yesread only = yeswrite only = nohosts allow = 192.168.177.131    hosts deny = *list = falseuid = root gid = rootauth users = rootsecrets file = /etc/rsyncd.passwd

Configuration details

Uid = root # Set the user gid to run the rsync process = rootuse chroot = no # use the default root directory max connections = 4 # maximum number of connections # pid file =/var/run/rsyncd. pid # pid file is not required for yum installation in CentOS7; otherwise, the lock file =/var/run/rsyncd error is returned. lock # specify the lock file log file that supports the max connections parameter =/var/log/rsyncd. log # After the file definition is complete, the system will automatically create exclude = lost + found/transfer logging = yes # enable the rsync server to use ftp files to record the download and upload operations in its own separate timeout = 600 # in the log, this option can overwrite the specified IP timeout time. This option ensures that the rsync server will not always wait for a crashed customer. Timeout is measured in seconds. 0 indicates that no timeout is defined. This is also the default value. An ideal number for anonymous rsync servers is 600. Ignore nonreadable = yes # Skip the unauthorized directory dont compress = * During synchronization *. gz *. tgz *. zip *. z *. Z *. rpm *. deb *. bz2 # files not compressed during transmission [test] # This name is the path where the client uses rsync for synchronization =/home/rsynctest # The actual path to be synchronized ignore errors = yes # specified when determining whether to run the delete operation during transmission, rsyncd ignores the IP address error on the server, generally, when an IO error occurs in rsync, The -- delete operation will be skipped, read only = yes # indicates pullwrite only = no # indicates pushhosts allow = 192.168.177.131 # The address synchronized from the client hosts deny = * # specify not to allow connection to r The host of the sync server can be defined by hosts allow. Hosts deny is not defined by default. List = false # This option sets whether the module should be listed when the customer requests a list of modules that can be used. If this option is set to false, you can create a hidden module. The default value is true. Uid = root # obtain the file identity gid = rootauth users = root # The client obtains the file identity. This user is not a real user in the Local Machine, secrets file =/etc/rsyncd. passwd # the file format USERNAME: PASSWD used to authenticate the client's key must be changed to 600, and the owner must be consistent with the user running rsync. (You need to create it yourself)

Create a password file

Vim/etc/rsyncd. passwd

Format: root: 123456 (former user name and password)

Modify file permissions: chmon 600/etc/rsyncd. passwd

Start rsync server: sudo rsync -- daemon (the client does not need to be started)

Rsync Client(192.168.177.131)  

Install rsync

Yum-y install rsync (A rsync configuration file is generated under the etc directory by default)

Configure the authentication Password File

Echo passwd (password only)>/etc/rsyncd. passwd

Modify permissions

Chmon 600/etc/rsyncd. passwd

Test file synchronization:

Rsync-avz -- progress -- password-file =/etc/rsyncd. passwd root@192.168.177.130: rsynctest/tmp/rsynctest/

  

Test complete!

Command parameters:

-V,-verbose detailed mode output

-Z,-compress compresses backup files during transmission

-R,-recursive processes subdirectories in recursive Mode

-T,-times preserve the file time information

-O and-owner keep file owner information

-P,-perms to keep File Permissions

-G and-group keep file group information

-- Progress shows the transmission progress

-- Delete: delete unnecessary files on the client

The summary is not yet in place. If you have any questions, you can point it out!

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.