Rsync parameter parsing and rsync server

  
 

Considering the security of server data, I consider adding a backup server to achieve better redundancy through data synchronization. Linux has a very good command rsync can achieve differential backup, let's talk about his usage: ▲ suitable system: red flag DC 4.1 or 5.0 or other linux, FreeBSD system ▲ test environment: red flag DC 5.0 First, through rsh or ssh If the rsync server is not set up, we can use the rsync command to perform a fast differential backup directly: Code: Command format: #rsync [option] Source path target path where: [option]: a: use archive mode, equal to - rlptgoD, that is, keep the original file permissions z: indicates that the data is compressed during transmission v: display to the screen e: use remote shell program (can use rsh or ssh) --delete: save the copy accurately, delete the file from the source host, target The host will also be deleted synchronously --include=PATTERN: Do not exclude files or directories that conform to PATTERN --exclude=PATTERN: Exclude all PATTERN-compliant files or directories --password-file: Specify the user authentication password source path for the rsync server And the target path can use the following format: rsync://[USER@]Host[:Port]/Path Server path [USER@]Host::Path Another type of rsync server It is shown in the form of [USER @] Host: Path remote path LocalPath local path ※ It should be noted that the source or destination path must be at least a local path, local path if ignored, will only list files that remote. Example: Code:#rsync -ave ssh test:/home/ftp/pub//home/ftp/pub/Sync the contents of the /home/ftp/pub/directory on the remote test machine in the source path via rsync Go to the local /home/ftp/pub/directory. ◎ Be careful of the /sign at the end of the source path, suffix /notify rsync to copy the contents of the directory, but not copy the directory itself. For example: Code:#rsync -ave ssh test:/home/ftp/pub /home/ftp/will synchronize the pub directory to the local /home/ftp/path. Code:#rsync -azv --delete rsync://[email protected]/blog /var/www/html/Login to 192.168.1.100 via linuxing, synchronize the blog entry of rsync server to local /var/www/html/, and delete the local source path does not exist File or directory. ※Be sure to pay attention to the --delete parameter. When using this parameter, it is recommended to specify the local directory with an absolute path to prevent emptying the current directory. Second, the establishment of rsync server When the server does not open ssh, or the backup party does not have ssh permissions, we can establish an rsync server for anonymous data synchronization. To use the rsync service, you need to set up the server and client: 1. The server main settings file: Code:#vi /etc/rsyncd.conf log file = /var/log/rsyncd.log pid file = /var/run/Rsyncd.pid lock file = /var/run/rsync.lock [test] #rsync section setting name path = /var/www/html/test #syncable data storage path comment = test folder #note uid = Apache #What is the identity to read the file gid = apache # Same as above, must be the user who has read path permission, group ignore errors # ignore error read only = yes #readlist = no # can not list auth users = linuxing #连接The account of the rsync service secrets file = /etc/rsyncd.secrets #Specify the location account password file for storing the account password: Code:#vi /etc/rsyncd.secrets #Format: Account: Password (for each line, account and password) : Separate) After linuxing:backup is saved, you need to make sure the user is root. The permission is 600 Code:#chown root:root /etc/rsyncd.secrets #chmod 600 /etc/rsyncd.secretsStart service: #rsync --daemon Make sure Boot automatically: Modify /etc/xinetd.d/rsy Nc file, change disable=yes to disable=no Code:#sed -i -e "/disable/{ s/yes/no/}" /etc/xinetd.d/rsync #service xinetd.d Restart2, the client uses the method of rsync://in usage one. If the rsync server requires password verification, add the --password-file parameter: Code:#rsync -azv --delete rsync://[email protected]/test /var/www/html --password-file=/etc /test #vi /etc/test #Specify the access password bakcup #chmod 600 /etc/test3, Timing In addition, since the rsync client does not have timing function, we can achieve timing synchronization by adding scheduled tasks in the crontab, such as: Use the -v parameter to prevent swipe) Code:#crontab -e 0 22 * ​​* 1-5 /usr/bin/rsync -az --delete rsync://[email protected]/test /var/www/html --password-file=/etc/test #Specify Monday to Friday, sync at 10 o'clock every night. 3. Summarize the benefits of using rsync: network encryption can be transmitted through ssh, and trust can be built using ssh client key. relationship. When maintaining the synchronization of large, complex directory structures between two computers, it is faster than tar or wget. And it can achieve precise synchronization. Fourth, if the append is compiled by rsync (such as FreeBSD), the path is a bit different: The server's settings file is in: /usr/local/etc/rsyncd.conf Startup file: /usr/local/etc/rc.d/rsyncd .sh command file: /usr/local/bin/rsync System startup hosting: /etc/rc.conf (increase rsyncd_enable="YES")

Copyright © Windows knowledge All Rights Reserved