background:
0. Server data is very important and will be in trouble once disk corruption occurs. As a manager, it is necessary to synchronize the data in real time.
1. Rsync is a good and backup tool, let's take Ubuntu as an example to talk about its compounding.
2. If my server a IP is 10.141.247.12, the IP of my backup client B is 10.141.247.13
server-side compounding:
1. Open rsync as a server switch, modify the contents of the file/etc/default/rsync one of the following (see link for the entire file contents)
Rsync_enable=true
2./etc/rsyncd.conf the contents of the new compounding document (or see links)
#[globale]
Strict modes = yes
#rsync default port
port = 873
logfile =/var/log/rsyncd.log pidfile
= /var/run/rsyncd.pid
Max connections = 4
auth users = backup, user
Secrets file =/etc/rsyncd.scrt
#[ Modules] Each path responding to a module
[appbackup]
path =/home/aborn/backup
#hosts allow=9.4.122.24< C14/>[databackup]
Path =/home/data
Description: A) Auth users must be the same as the user name in/ETC/RSYNCD.SCRT, but not necessarily the user name in the system, the name of a random take
b Each path to be backed up is a module, where there are two paths corresponding to module [Appbackup] and [DataBackup]
3. The new password file/etc/rsyncd.scrt the corresponding contents as follows:
backup:configurebackup@#$^&* () Google
User:passwordpassword
There are two users backup and user, the colon corresponds to the password, note that the file property is 600 (other users do not have read and write permissions)
4. Open the backup service (after opening the account can be NETSTAT-TUPLN to see if 873 ports are open, if the success of the Open)
Sudo/etc/init.d/rsync start
Client Compounding
1. If the current working directory is ~/backup
2. Create the password file Rsyncd.scrt in the current working directory, the content is the same as the server side, and the property is 600
3. Create the configuration file client.conf in the current working directory, as follows:
Backuppath= "/home/aborn/backup/";
serverip= "10.141.247.12"
module= "Appbackup databackup"
#OPTIONS = "-vazu--progress--delete"
options= " -vazu--progress "
Description: Where Backuppath is the client data store path
ServerIP is the IP address of server a machine
Module is a module that corresponds to the server-side/etc/rsyncd.conf, with multiple module separated by a space
4. Run the backup script rsyncclient.sh, which reads as follows
#!/bin/bash ################################################################## # NAME # rsyncclient.sh----running in
Client machine, which # is used to backup data in client machine # USAGE #/rsyncclient.sh # # AUTHOR # Aborn Jiang (aborn.jiang@gmail.com) # Note # pls configure the file client.conf and Rsyncd.scrt # # # ################################################################ abspath=$ (dirname $) Source ${ABSPATH}/ client.conf function Get-user-pwd () {# Obtain usrname and password iusr=$ (cat ${abspath}/rsyncd.scrt|tr-d ' |grep -V "^$" |
\ grep-v "^#" |head-n 1|awk-f: ' {print} ') ipwd=$ (cat ${abspath}/rsyncd.scrt|tr-d ' |grep-v "^$" | \ Grep-v "^#" |head-n 1|awk-f: ' {print $} ') if [-Z ${iusr}] | |
[Z ${ipwd}];then echo iusr= $iUSR ipwd= $iPWD "echo" RSYNCD.SCRT format illegal, please check! ";
exit-1; FI # produce password file echo "$iPWD" > ${abSpath}/.pass chmod ${abspath}/.pass [!-D $BACKUPPATH] && mkdir-p ${backuppath}} function Backup
-module () {# print key information imodule=$1 echo echo "---------------------------------------------------"
echo "----backup module ${imodule}@${serverip} begin" echo "----time= ' date '----" echo "Abspath=${abspath}" echo "Backuppath=${backuppath}" echo "iusr= $iUSR ipwd= $iPWD" echo "Options=${options}" Imodulebackp
Ath=${backuppath}/${imodule}; [! D-${imodulebackpath}] && mkdir-p ${imodulebackpath} # Begin backup Rsync ${options} ${iusr}@${server Ip}::${imodule} ${imodulebackpath} \--password-file=${abspath}/.pass If [$!= 0];then echo----
Backup Module ${imodule}@${serverip} failed. "
else echo "----Backup module ${imodule}@${serverip} succuess." Fi echo "----time= ' date '----" echo "---------------------------------------------------" echo
The function __main__ () {GET-USER-PWD for MD in $MODULE does backup-module $md done} __main__
Note: The entire project document see my GitHub thisLink Configure.rsync