First, Introduction
Rsync is a remote data synchronization tool that allows you to quickly sync files between multiple hosts. rsync uses the so-called "Rsync algorithm" to synchronize files between local and remote two hosts, which transmits only the different portions of two files, rather than the entire transfer every time, so it is quite fast. Of course, not only remotely, synchronizing locally, replicating data can also use this command, and only transfer different parts of the file.
Second, configure the rsync server
1. Start Rsync Server
#vim/etc/xinetd.d/rsync
Change disable's Yes to No
1 service rsync 2 { 3 disable = no 4 socket_type = stream 5 wait = no 6 User = 7 Server =/usr/bin/rsync 8 Server_args = --daemon 9 log_on_failure += USERID 10 }
2. Configure/etc/rsyncd.conf (manual generation required)
Global parameter UID= root//users running the rsync daemonGID = root//groups running the rsync daemonUse chroot = no//do not use chrootMax connections =4 //Maximum number of connections is 4Strict modes =yes//whether to check the permissions of the password filePort =873 //Default Port 873PID file =/var/run/rsyncd.pid//where to store the PID fileLockFILE =/var/run/rsync.Lock //where to store the lock fileLog file =/var/log/rsyncd.log//where the logging files are storedmodule parameters [Backup]//here is the name of the authentication module, which needs to be specified on the client sidePath =/home/backup///need to back up the directory, indispensable! Comment = This isA test//The comment information for this moduleIgnore errors//some unrelated IO errors can be ignoredRead Only = yes//Read-only#list = No//column files are not allowedAuth users = WJ//authenticated user name, if no this line is anonymous, this user is not system-independentSecrets file =/etc/rsync.pas//Password and user name comparison table, password files generated by themselvesHosts allow =192.168.1.1,10.10.10.10 //Allow hostHosts Deny =0.0.0.0/0 //Prohibit host#transfer logging = yes
3. Configure the rsync password (the path is already written in the configuration file above)
/etc/rsync.pas (name casually, as long as it is consistent with the above configuration file), format (one user on a line)
Account: Password
#vi/etc/rsync.pas
WJ:1111
Permissions: Because Rsync.pas stores the user name and password for the rsync service, it is important. To set Rsync.pas to root, with a permission of 600.
#cd/etc
#Chown root:root Rsync.pas
#chmod Rsync.pas
4. Let the configuration take effect
#service xinetd Restart
5. Synchronizing files
① fetching files from server side
#rsync-VZRTOPG--progress--delete [email protected]::backup /home/backup--password-file=/etc/rsync.pas
② uploading files to server side
#rsync-VZRTOPGP. WJ@192.168.78.129::backup
Iii. details of rsync command parameters
-A archive mode
-V indicates verbose detailed display
-P represents the option function in place of both-partial and-progress
-Z means compression
-R means recursive recursion
-T means keeping the original file creation time
-O means to keep the original file owner
-p means to keep the parameters of the original file
-G means to keep the original file's owning group
-e SSH establishes an encrypted connection.
--delete means that if the server side deletes the file, then the client also deletes the file accordingly, maintaining true consistency.
--exclude does not contain the/ins directory
--partial prevents rsync from deleting the copied portion when the transmission is interrupted (if the transfer is interrupted while the file is being copied, the default action of Rsync is to undo the pre-action, i.e. from the target machine
Delete a portion of a file that has been copied. )
--progress means to show detailed progress
--size-only This parameter is used in two folders is only a few new files in the source folder, there is no duplicate and modified files, because the content can be modified to the same size, and is skipped. This parameter can greatly improve the efficiency of synchronization because it does not need to check whether the contents of a file of the same name are the same.
--password-file to specify the password file that contains the password for the specified authenticated user on the server side. This can be used in the script without the need to interactively enter the authentication password, it is important to note that this password file permission property to be set to be only master readable.
[Email Protected]::backup
WJ refers to a user who specifies authentication on the server side
192.168.78.129 refers to the server-side IP
:: Backup indicates the server side needs to synchronize the module name;
Configuring the Rsync server under Linux