First, rsync basic configuration and introduction
1. What is rsync?
rsync (rsync-a Fast, Versatile (general), remote (and local) file-copying tool
An open source, fast, versatile tool that enables full and incremental simultaneous local or remote data backup is available on multiple operating systems. Rsync has the ability to enable fast synchronization and backup of data between local and remote host computers.
Features of the 2.rsync
1) Support copying special files, such as connecting file devices, etc.
2) can have the ability to exclude specified file or directory synchronization, equivalent to the exclusion function of packaging command tar--exclude
3) can achieve incremental synchronization, that is, only synchronize the changed data, so the efficiency is very high
3.rsync1. basic command line vs. common options
1) local copy, command line: rsync [OPTION] ... src [src] ... dest
For example, the /etc/hosts/file is copied to the/tmp directory , and its function is the equivalent of CP.
The rsync command is a client command
Rsync-avz (Hold property)/etc/hosts/tmp
2) Local deletion, the equivalent of RM command , the contents of the/tmp directory is replaced into empty.
rsync-avz--delete/null/ /tmp
3) Remote copy rsync supports "local , remote", "remote-to-local" copies of both sides, does not support "remote-- remote" copy PayPal . Rsync's network features are available in two ways:SSH service and rsync--daemon service.
Push: Copy the local/tmp to the remote: 10.0.0.131:/tmp/
Rsync-avzp-e ' Ssh-p '/tmp/10.0.0.131:/tmp/
Pull: Copy the remote 10.0.0.131:/tmp to the local/tmp/
Rsync-avzp-e ' ssh-p ' 10.0.0.131:/data//tmp
4.rsync server-side configuration.
rsync is a C/s hybrid, which is a program that can be used when the client can also serve as a server.--daemon one second to turn the service side. The/etc/services file records that Rsync uses port No. 873 by default. Of course, like other services, rsync also requires configuration files. rsync defaults to looking for/etc/rsyncd.conf. However, this directory does not exist beforehand. The specific format we can man a rysncd.conf, there is a detailed introduction. In fact, similar to samba, here is a simple rsyncd.conf:
#指定访问用户
UID = rsync
#指定访问组
GID = rsync
#禁止chroot (switch users when not connected)
Use chroot = no
#允许访问目录列表
List = False
#最大的连接数
Max connections = 2000
#超时时间
timeout=600
#存放进程号文件的路径
PID file =/var/run/rsyncd.pid
#存放日志文件的路径
Log file =/var/log/rsyncd.log
Address range for #允许访问rsync service
Hosts allow = 10.0.0.0/24
#拒绝访问的rsync服务的地址范围
Hosts Deny = 0.0.0.0/32
#标识为不可读
Read Only = False
#虚拟用户文件
Auth Users=rsync_backup
#密码文件
Secrets File=/etc/rsync.password
##########################
#此为开放的tag:
[Data]
#备份路径
Path =/data
#注释信息
Comment =write by Chen
[Backup]
#备份路径
Path =/backup
######################################
#Rsync Server
#created by Chen 2016.4.22 20:31
# #rsyncd. conf start##
Uid=rsync
Gid=rsync
Use Chroot=no
Max connections=2000
timeout=600
PID File=/var/run/rsyncd.pid
Lock File=/var/run/rsync.lock
Log File=/var/log/rsyncd.log
Ignore errors
Read Only=false
List=false
Hosts ALLOW=10.0.0.0/24
Hosts DENY=0.0.0.0/32
Auth Users=rsync_backup
Secrets File=/etc/rsync.password
########################################
[Backup]
Comment=backup server by Chen 20:36 2016.04.22
Path=/backup [Backup Path]
########## #end ##########################
You can start the Rsync service by completing the above configuration:rsync--daemon
5. See if the service starts a command
[Email protected] ~]#Ps-ef|grep rsync
Root 2833 1 0 20:53? 00:00:00 rsync--daemon
Root 2835 2642 0 20:53 pts/0 00:00:00 grep--color=auto rsync
[Email protected] ~]#NETSTAT-TUNPL |grep rsync
TCP 0 0 0.0.0.0:873 0.0.0.0:* LISTEN 2833/rsync
TCP 0 0::: 873:::* LISTEN 2833/rsync
[Email protected] ~]#lsof-i: 873
COMMAND PID USER FD TYPE DEVICE size/off NODE NAME
rsync 2833 root 3u IPv4 16376 0t0 TCP *:rsync (LISTEN)
rsync 2833 root 5u IPv6 16377 0t0 TCP *:rsync (LISTEN)
[Email protected] ~]#
6. Create users, backup directories and authorizations, and configure passwords
Useradd rysnc-s/sbin/nologin/-M
ID RYSNC
Mkdir/backup
Chown-r rsync.rsync/backup/
echo "Rsync_backup:chen" >/etc/rsync.password
chmod 600/etc/rsync.password
7. Service-side configuration
echo "Chen" >/etc/rsync.password
chmod 600/etc/rsync.password
Complete all of the above steps to enable local and remote and remote to local file and directory data backup
No difference sync:
Rsync-avz--delete [email protected]::backup/tmp/--password-file=/etc/rsync.password----to back up local data when you operate this command
Rsync excludes a file:
Exclude individual files
Rsync-avz--exclude=/tmp/a/tmp/[email protected]::backup--password-file=/etc/rsync.password
Exclude Multiple Files
Rsync-avz--exclude={2,4,5,6}}a/tmp/[Email protected]::backup--password-file=/etc/rsync.password
Advantages of Rsync:
1. Incremental backup synchronization, socket support (daemon), centralized backup
Disadvantages of Rsync:
1. When a large number of small files are synchronized, the time is longer.
2. sync files Larger, 10G such large files sometimes have problems, interruptions. Before the synchronization is complete, the shadow file is hidden, and the transfer is done normally.
Rsync Cons:
1. When a large number of small files are synchronized, the contrast time is longer, and sometimes the rsync process stops. Resolution: A. Package the small files after the synchronization b.drbd (file system synchronization)
2. Synchronization of large files, 10G such large files can sometimes be problematic, interrupted. Before the full synchronization, is the shadow file, synchronization completed to normal files.
Second, rsync Service FAQ Summary
Question one:
@ERROR: Chroot failed
Rsync Error:error starting Client-server Protocol (code 5) at MAIN.C (1522) [receiver=3.0.3]
Reason:
The server-side directory does not exist or has no permissions. Creating a directory and correcting permissions can resolve the issue.
Question two:
@ERROR: Auth failed on module tee
Rsync Error:error starting Client-server Protocol (code 5) at MAIN.C (1522) [receiver=3.0.3]
Reason:
The server side of the module (tee) needs to verify the user name password, but the client does not provide the correct user name password, authentication failed. Provide the correct user name password to resolve this issue.
Question three:
@ERROR: Unknown module ' tee_nonexists '
Rsync Error:error starting Client-server Protocol (code 5) at MAIN.C (1522) [receiver=3.0.3]
Reason:
The specified module does not exist on the server. Provide the correct module name or modify the server side to the module you want to solve the problem.
Question four:
Password file must not being other-accessible
Continuing without password file
Password:
Reason:
This is because the permissions of the Rsyncd.pwd rsyncd.secrets are not correct and should be set to 600. such as: chmod rsyncd.pwd
Question five:
rsync:failed to connect to 218.107.243.2:no route to host (113)
Rsync error:error in Socket IO (code ten) at CLIENTSERVER.C (104) [receiver=2.6.9]
Reason:
The other side does not boot, firewall blocking, through the network has a firewall blocking, it is possible. Shutting down the firewall actually turns on TCP UDP port 873.
Question six:
Rsync Error:error starting Client-server Protocol (code 5) at MAIN.C (1524) [receiver=3.0.7]
Reason:
/etc/rsyncd.conf configuration file contents have errors. Please check the configuration file correctly.
Question seven:
Rsync:chown "" failed:invalid argument (22)
Reason:
Permissions cannot be copied. Remove the parameters for the sync permission.
This article is from the "Let's Go" blog, be sure to keep this source http://purify.blog.51cto.com/10572011/1768103
Rsync for the Linux Data Sync Backup tool