rsync备份同步

服务器端:

每个需要备份的项目所在的服务器作为rsyncserver端,配置如下:

 

Rsync的配置文件配置允许备份目录:/etc/rsync.conf如下:

 

uid = nobody
gid = nobody
use chroot = no
max connections = 3
transfer logging = true
log format = %h %o %f %l %b
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log

[project]
path = /opt/hosts/
exclude = app_log/ resin_log/ .*
comment = BACKUP CLIENT IS SOLARIS 8 E250
ignore errors
read only = yes
list = no
auth users=sg
secrets file = /etc/rsyncd.secrets

[server]
path = /opt/resin/conf
exclude = /*
include = /resin.conf
comment = BACKUP CLIENT IS SOLARIS 8 E250
ignore errors
read only = yes
list = no
auth users=sg

相应的密钥文件也在/etc下:rsyncd.secrets

 

配置文件模块:project是要备份的项目,server是要备份的resin服务器配置文件

 


客户端:

客户端即我们备份服务器,采取主动抓取策略:

1,客户端服务器地址:124.238.235.53

2,定时脚本,密码文件目录:/usr/local/bin,主站和小站的定时任务分开执行,脚本分别为:rsync_guagua.shrsync_xiao.sh,定时任务每天晚上23点执行

3,备份web服务器resin启动脚本:/usr/local/bin/run/xxx_run.sh,每个resin对应一个启动脚本,该脚本自动拷贝该resin需要加载的项目和resin配置文件到指定的目录。该脚本自动部署相应的项目和启动resin服务

客户端同步脚本:

 

#!/bin/sh
DATE=`date +%y%m%d`
projectDir=/opt/backup/xiaozhan_platform/$DATE/project
serverDir=/opt/backup/xiaozhan_platform/$DATE/server
if [ ! -d "$projectDir" ]; then
 echo "making dir $projectDir"
 mkdir -p "$projectDir"
fi
if [ ! -d "$serverDir" ]; then
 echo "making dir $serverDir"
 mkdir -p "$serverDir"
fi
#shenghua
rsync -vzrtopg --progress --delete [email protected]::project $projectDir/shenhua --password-file=/usr/local/bin/rsyncd.pwd>/var/log/rsync.$DATE.log
rsync -vzrtopg --progress --delete [email protected]::server $serverDir/shenhua --password-file=/usr/local/bin/rsyncd.pwd>/var/log/rsync.$DATE.log
#hongxiu
rsync -vzrtopg --progress --delete [email protected]::project $projectDir/hongxiu --password-file=/usr/local/bin/rsyncd.pwd>/var/log/rsync.$DATE.log
rsync -vzrtopg --progress --delete [email protected]::server $serverDir/hongxiu --password-file=/usr/local/bin/rsyncd.pwd>/var/log/rsync.$DATE.log

备份机resin启动脚本:

#!/bin/sh

DATE=`date +%y%m%d`

cp -rf /opt/backup/xiaozhan_platform/$DATE/project/shenhua/* /opt/hosts

cp -f /opt/backup/xiaozhan_platform/$DATE/server/shenhua/resin.conf /opt/resin/conf

if [ $? -eq 0 ];then

 echo "start....."

 /opt/resin/bin/httpd.sh start

fi

猜你喜欢

转载自guying1028.iteye.com/blog/1851370