Bring you into the rsync world

Source: Internet
Author: User
Tags rsync rsync usage

Bring you into the rsync world
GuideRemote synchronize (Rsync) is a remote data synchronization tool that allows you to quickly synchronize files between multiple hosts through the LAN/WAN, or use Rsync to synchronize different directories on the local hard disk. There are three methods to use rsync. There are also six steps to configure rsync. Next, we will introduce rsync, rsync usage and rsync configuration to bring you into the rsync world.I. Introduction to rsync

Remote synchronize (Rsync) is a remote data synchronization tool that allows you to quickly synchronize files between multiple hosts through the LAN/WAN, or use Rsync to synchronize different directories on the local hard disk. When using rsync for remote synchronization, two methods can be used: Remote Shell (ssh is recommended, and ssh is responsible for user authentication) and C/S (that is, the client connects to the remote rsync server, and the rsync server is responsible for user authentication ). Rsync is called a fast method for file synchronization, mainly because it checks whether there are differences between files during file synchronization. It only synchronizes files with differences or not, however, the initial synchronization speed is still slow.

Rsync has many options:-n: when you are not sure whether the command can be executed as needed, you must test it in advance;-n can complete this function;-v: -- verbose, detailed output mode-q: -- quiet, silent mode-c: -- checksum, enable the verification function, force the file transfer verification-r: -- recursive, recursive copy;-: -- archives, archive, retain the original attributes of the file-p: -- perms keep the file permission-t: -- times keep the file timestamp-l: -- links: the symbolic link of the reserved file-g: -- group: the group of the reserved file-o: -- owner: the owner of the reserved file-D: -- devices: The Reserved Device File-H, -- hard-links retains the hard link;-S, -- sparse performs special processing on sparse files to save DST space;-e ssh: indicates using the ssh protocol for bearer-z: transfer after File compression -- progress: display progress bar -- stats: show how to perform compression and transmission -- delete: delete files in DST that do not have SRC, that is, delete unnecessary files in DST;

Ii. rsync usage

Rsync can download the http://rsync.samba.org/here, which is installed by default on CentOS systems.

Rsync has six different working modes:

1. Copy a local file

This mode is enabled when the SRC and DES paths do not contain a single colon ":" separator.

[root@localhost ~]# rsync -avSH /home/feiyu/ /bak/
2. Copy the content of the local machine to the remote machine.

A remote shell program (such as rsh and ssh) is used to copy the content of the local machine to the remote machine. This mode is enabled when the DST path address contains a single colon (:) separator.

[root@localhost ~]# rsync -av /home/feiyu/ 192.168.0.24:/home/feiyu/
3. Copy the contents of the remote machine to the local machine.

A remote shell program (such as rsh and ssh) is used to copy the contents of the remote machine to the local machine. This mode is enabled when the SRC address path contains a single colon (:) separator.

[root@localhost ~]# rsync -av 192.168.0.24:/home/feiyu/  /home/feiyu/ 

Note: When the rsync command is in use, if there is a diagonal line at the end of the Source parameter, the content of the specified directory will be copied instead of the Directory itself; if there is no diagonal line, the directory itself will be copied; the slash at the end of the target parameter does not work. Therefore, the following command

[Root @ localhost ~] # Rsync-r/mydata/data/backups/: the directory data will be directly synchronized to the/backups directory [root @ localhost ~] # Rsync-r/mydata/data // backups/: Synchronize the content in the data/directory to the/backups directory.

The following three modes can be used only when rsync is used as the server. The following describes how to configure rsync as a service.

3. Configure the rsync Service

Configuring a simple rsync service is not complicated, but after rsync is installed, no configuration files are found, so you need to manually create some configuration files. Rsync can start daemon through xinetd or start daemon as an independent process. If you start it as an independent process, you only need to run the command rsync-daemon. However, we generally use it as a super daemon. The installation steps are as follows:

1. Install and start xinetd
[Root @ localhost ~] # Yum-y install xinetd [root @ localhost ~] # Ls/etc/xinetd. d/# The xinetd configuration file of rsync already contains chargen-dgram daytime-dgram discard-dgram echo-dgram rsync time-dgramchargen-stream daytime-stream discard-stream echo-stream tcpmux-server time-stream
2. Provide configuration files for the rsync Service

The configuration file is/etc/rsyncd. conf. for help, use man rsyncd. conf. The configuration file must define one global configuration and multiple rsync sharing configurations.

[Root @ localhost ~] # Cat/etc/rsyncd. conf # Global Settings # port = 873 the default port number is 873, you can leave uid = nobody Unspecified. // specify the UIDgid = nobody, the daemon for transferring files to the module. // specify the GIDuse chroot daemon for transferring files to the file system. max connections = 5 // maximum number of concurrent connections in the directory strict modes = yes # strictly check the file Permission pid file =/var/run/rsyncd. pid // specify the PID file lock file =/usr/local/rsyncd. lock // specifies the lock file that supports max connection. The default value is/var/run/rsyncd. locklog file =/var/log/rsyncd. log // rsync server log # Directory to be synced [mydata] // custom module path =/mydata/data // used to specify the Directory to be backed up ignore errors = yes // some IO errors can be ignored. read only = no // you can set no, the client can upload files. yes is read-only write only = no // no. The client can download the files, yes, you cannot download hosts allow = 192.168.0.0/16 // The IPhosts deny that can be connected = * // disable the connection IPlist = false // when the customer requests, use the module list uid = rootgid = rootauth users = myuser // connection username, which is irrelevant to the linux User Name secrets file =/etc/rsyncd. passwd // verify the password file

Description (deny | allow rule ):
1. Both are unavailable. Access is allowed by default;
2. Only hosts allow is displayed: The whitelist is defined, but the host that is not matched is processed by default rules, that is, allowed;
3. Only hosts deny is displayed: The Blacklist is defined; all of the blacklists are rejected;
4. Both of them appear at the same time: Check hosts allow first, if it matches allow; otherwise, check hosts deny. If it matches, it is rejected. If there is no match between the two, it is processed by the default rule, that is, allow;

3. Create a password file

File Format (plaintext): username: password

[Root @ localhost ~] # Echo "myuser: mypass">/etc/rsyncd. passwd [root @ localhost ~] # Chmod 600/etc/rsyncd. passwd # The permission must be 600
4. Start the service
[root@localhost ~]# service xinetd  start
5. usage (the last three modes)

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

[Root @ localhost ~] # Rsync-av myuser@192.168.0.23: mydata/tmp/# myuser is a user of the rsync server

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

[root@localhost ~]# rsync -av install.log.syslog  myuser@192.168.0.23::mydata 

C. List of remote machine files. This is similar to rsync transmission, but you only need to omit the local machine information in the command.

[root@localhost ~]# rsync -av myuser@192.168.0.23::mydata

Original from: http://www.tianfeiyu.com /? P = 1975

Address: http://www.linuxprobe.com/use-rsync-file.html


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.