Rsync Basics and Basic use

Source: Internet
Author: User
Tags rsync

1. rsync Sync Tool

1.1, Rsync Introduction

rsync (remote sync) is a data mirroring Backup tool under UNIX systems and a fast incremental backup tool that supports remote synchronization, local replication, and more. and rsync not only transmits fast, but also in the transmission, can realize the differential backup, namely only if the server side and the client between the data is inconsistent, only copies the different parts.

1.1.1, Features:

      • Can be mirrored to save the entire directory tree or file system

      • High file transfer efficiency

      • Secure data transfer with SSH

      • Support for anonymous data transfer

1.1.2, rsync working mode

      • Run directly on this machine, similar to the CP Tool Shell mode (local mode)

      • Use rsh or SSH to implement data transfer between server and client (remote shell mode, which can be used to host its remote transfer process using SSH protocol)

      • List mode, listing only the content in the source without copying (-NV)

      • Server mode, when Rsync is working as a daemon. Can receive the data transfer request from the client, and can synchronize with the client to the server side, or vice versa

1.1.3, synchronous mode

based on an algorithm, also known as the rsync algorithm, the implementation to check your source and target between two files are different, if there is, only to send different files, the same do not copy, so is the fast synchronization tool

1.1.4, disadvantages

The transfer process is not encrypted (but he can use SSH to transmit encryption)

1.2. Common options for Rsync commands

-N: Test synchronization, but do not actually synchronize

-V: Verbose output mode

-Q: Silent mode, no information displayed

-c:checksum, turn on the check function

-R: Recursive replication

Note: Here are a few things to keep in mind, if you copy a file that doesn't have "/" at the end, then he's copying the directory name, and if so, all the files in it.

-A: Archive, preserving the original properties of the file

-P: Preserve file permissions

-T: Keep file timestamp

-L: Preserve Symbolic links

-G: Reserved belong to Group

-O: Reserved owner

-D: Keep device files

-e ssh: using SSH as the transport bearer

-Z: Post-compression transfer

--progress: Show progress bar

--stats: Shows how to perform compression and transfer

usage example: [[email protected]~]# rsync-r--stats-e ssh--progress/etc/pam.d [email protected]:/tmp/

1.3. Server Mode

1.3.1, Service

When Rsync is working in server mode, rsync does not listen on its own because it is a transient daemon and requires a Super Daemon (xinetd)

1.3.2, configuration files

If rsync needs to work and share a local directory storage block, additional configuration files are required. But this profile rsync and is not provided. Although no direct configuration file is provided, there is a file called rsyncd.conf.5.gz under its installation directory, which is the Help manual for Rsync. We can write the corresponding configuration file according to the Help information inside.

1.3.3, service configuration file format

The rsync configuration file is divided into two sections:

Note: The main definition is which shares, each share is similar to samba using [] to define

Global Configuration segment: There is usually only one

Shared configuration segments: You can have multiple

For example: [Share_name] #定义共享名 #有点类似Samba

1.3.4, rsync-Monitored ports

The port that rsync listens on is 873.

1.3.5, rsync command format

Access via rsync daemon:

#从远端服务器拉去数据 Pull:rsync [OPTION ...] [[email protected]] Host::src ... [DEST] rsync [OPTION ...] rsync://[[email protected]]host[:P ort]/src ... [DEST] #向远端服务器推送数据 Push:rsync [OPTION ...] Src... [[email protected]] HOST::D est rsync [OPTION ...] SRC ... rsync://[[email protected]]host[:P ort]/dest

Example: Use the client to execute the following command (push data to the remote server)

[Email protected] ~]# Rsync/etc/fstab 192.168.1.187::tools

Note: Here is a clear definition of which share name to push to

Ii

[Email protected] ~]# Rsync/etc/fstab rsync://192.168.1.187/tools

Example: Use the client to execute the following command (pull data from the remote server to local)

Note: If your tools specifies a shared disk that has data

[Email protected] ~]# rsync-a 192.168.1.187::tools/./[[email protected] tmp]# rsync-a 192.168.1.187::tools/local.repo ./#拉取单个文件

Ii

[Email protected] tmp]# rsync-a rsync://192.168.1.187/tools/fstab.


1.3.6, Experiment: Implement Rsync Installation and application

Experimental topology

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/75/B9/wKiom1ZBWILBvdyBAABexzfB2Xo107.png "title=" 2015-11-10_103536.png "width=" "height=" "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:500px;height:200px; " alt= "Wkiom1zbwilbvdybaabexzfb2xo107.png"/>

Steps

1. To start the Rsync service, install the Super daemon first

[email protected] ~]# Yum install xinetd #安装超级守护进程

2, set the boot automatically start

[Email protected] xinetd.d]# chkconfig xinetd on

3. Install Rsync

[email protected] xinetd.d]# Yum install rsync-y

4. View the Rsync service generated automatically under the Super daemon process

[[email protected] xinetd.d]# vim /etc/xinetd.d/rsyncservice rsync{         disable = no         #   Here to no, that means it's enabled         flags            = IPv6        socket_type      = stream        wait             = no         user            = root         server          = / usr/bin/rsync        server_args     = - -daemon         log_on_failure  += userid 

5. Create a shared directory

[Email protected] xinetd.d]# Mkdir/data

6, edit the configuration file/etc/rsyncd.conf (this file is self-created, the system will not be automatically generated)

[Email protected] xinetd.d]# vim/etc/rsyncd.conf
# global settingsuid = nobodygid = nobodyuse chroot = no    #要不要启用chroot功能max  connections = 10   #最大并发连接数strict  modes = yes       #是否启用严格检查权限, whether the user is allowed to upload and download pid file = /var/run/rsync.pidlog file  = /var/log/rsyncd.log# directory to be synced[tools]path = /data# Where the shared files are stored ignore error = yes         #传输中如果有文件发生错误了怎么办, Yes means ignoring read only = no       #是否是只读write  only = no           #是不是只写 so that others can't see HOSTS ALLOW = 192.168.1.0/24            #允许哪些主机来实现数据同步 (white list) hosts deny = *                      #如果他匹配到上面的, then go straight through, ifNo, deny all list = false                    #是否允许列出所有  true/falseuid = rootgid = root  # Here the UID and GID and the above difference, here is the meaning of this shared directory is running in what capacity. If this is more than writing, it will inherit the above

7. Start the service

[Email protected] xinetd.d]# service xinetd star

8. Test the connection using a Linux client

[Email protected] ~]# Rsync/etc/fstab 192.168.1.187::tools

Note: If the connection is unsuccessful, see if the firewall is turned on

1.3.7, Experiment: Server-side Enable user authentication function

We know that using IP address access authorization is neither convenient nor secure, so the solution is to authorize the user.

Introduced

1, the first to add authentication parameters, is to add the configuration at the shared definition [tools] Add two parameters

Auth users = USERNAME LIST #允许哪个用户, to write a specific name, this user must be the user of your password presence

Secrets file =/etc/rsynce.passwd #密码文件路径, you need to create it yourself

Description: List of user names in USERNAME list comma-delimited rsyncd.passwd

2, create the password file/etc/rsyncd.passwd #这个密码文件有特殊的权限要求, must be 600

Format:

Username:password

Note: The content is clear text, so do the file permission control

Example:

1, edit rsyncd.conf configuration file, add user authentication parameters

[Email protected] data]# Vim/etc/rsyncd.confauth users = Tom, Jerry Secrets file =/etc/rsyncd.passwd

2. Create rsync password file and create user account password

[Email protected] data]# Vim/etc/rsyncd.passwdwqp:pangxiewindchaser:pangxie

3. Modify Permissions

[Email protected] data]# chmod 600/etc/rsyncd.passwd

4. Restart XINETD Service

[Email protected] data]# service xinetd restart

5. Using client-side testing

[Email protected] ~]# rsync/etc/fstab [email protected]::tools


This article is from the "Crab Learn Linux" blog, please be sure to keep this source http://windchasereric.blog.51cto.com/5419433/1711313

Rsync Basics and Basic use

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.