sersync的简单例子
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sersync的简单例子相关的知识,希望对你有一定的参考价值。
前提条件:
使用sersync要事先配置rsync的部分内容,请参考我的另一篇博文“以rsync的daemon工作模式传输数据”。
其中nfs01为客户端,backup为服务端。
[[email protected] tools]#mkdir –p /home/oldboy/tools
#通过rz –y的方式上传本地sersync_64bit_binary_stable_final.tar.gz到/home/oldboy/tools目录下。
[[email protected] tools]# ls -l/home/oldboy/tools/sersync_64bit_binary_stable_final.tar.gz
-rw-r--r-- 1 root root 727290 Jun 10 12:55/home/oldboy/tools/sersync_64bit_binary_stable_final.tar.gz
[[email protected] tools]# tar -ztf sersync_64bit_binary_stable_final.tar.gz
GNU-Linux-x86/
GNU-Linux-x86/sersync2
GNU-Linux-x86/confxml.xml
[[email protected] sersync]# mkdir -p /usr/local/sersync
[[email protected] sersync]# mkdir -p /usr/local/sersync/bin/
[[email protected] sersync]# mkdir -p /usr/local/sersync/conf/
[[email protected] tools]# tar -zxf /home/oldboy/tools/sersync_64bit_binary_stable_final.tar.gz -C /usr/local/sersync/
[[email protected] tools]# ls -l /usr/local/sersync/GNU-Linux-x86/
total 1772
-rwxr-xr-x 1 root root 2214Oct 26 2011 confxml.xml
-rwxr-xr-x 1 root root 1810128 Oct 26 2011 sersync2
#备份
[[email protected] sersync]# cp /usr/local/sersync/GNU-Linux-x86/sersync2 /usr/local/sersync/bin/sersync
[[email protected] sersync]# cp /usr/local/sersync/GNU-Linux-x86/confxml.xml /usr/local/sersync/conf/
#加入环境变量
[[email protected] bin]# echo "exportPATH=$PATH:/usr/local/sersync/bin" >>/etc/profile
[[email protected] profile.d]# tail -1/etc/profile
exportPATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/sersync/bin/
#使环境变量生效
[[email protected] profile.d]# source /etc/profile
#需要修改的地方已标红
[[email protected] ~]# cat/usr/local/sersync/conf/confxml.xml
<?xml version="1.0"encoding="ISO-8859-1"?>
<head version="2.5">
<host hostip="localhost"port="8008"></host>
<debug start="false"/>
<fileSystem xfs="false"/>
<filter start="false">
<exclude expression="(.*)\.svn"></exclude>
<exclude expression="(.*)\.gz"></exclude>
<exclude expression="^info/*"></exclude>
<exclude expression="^static/*"></exclude>
</filter>
<inotify>
<delete start="true"/>
<createFolder start="true"/>
<createFile start="false"/>
<closeWrite start="true"/>
<moveFrom start="true"/>
<moveTo start="true"/>
<attrib start="false"/>
<modify start="false"/>
</inotify>
<sersync>
<!--
<localpath watch="/opt/tongbu">
-->
<localpathwatch="/backup">
<remoteip="10.0.0.41" name="backup"/>
<!--<remote ip="192.168.8.39"name="tongbu"/>-->
<!--<remote ip="192.168.8.40"name="tongbu"/>-->
</localpath>
<rsync>
<commonParams params="-artuz"/>
<authstart="true" users="rsync_backup"
passwordfile="/etc/rsync.password"/>
<userDefinedPort start="false"port="874"/><!-- port=874 -->
<timeoutstart="true" time="100"/><!-- timeout=100 -->
<ssh start="false"/>
</rsync>
<failLogpath="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--defaultevery 60mins execute once-->
<crontab start="false"schedule="600"><!--600mins-->
<crontabfilter start="false">
<excludeexpression="*.php"></exclude>
<excludeexpression="info/*"></exclude>
</crontabfilter>
</crontab>
<plugin start="false" name="command"/>
</sersync>
<plugin name="command">
<param prefix="/bin/sh" suffix=""ignoreError="true"/> <!--prefix /opt/tongbu/mmm.sh suffix-->
<filter start="false">
<include expression="(.*)\.php"/>
<include expression="(.*)\.sh"/>
</filter>
</plugin>
<plugin name="socket">
<localpath watch="/opt/tongbu">
<deshost ip="192.168.138.20" port="8009"/>
</localpath>
</plugin>
<plugin name="refreshCDN">
<localpath watch="/data0/htdocs/cms.xoyo.com/site/">
<cdninfo domainname="ccms.chinacache.com"port="80" username="xxxx" passwd="xxxx"/>
<sendurl base="http://pic.xoyo.com/cms"/>
<regexurl regex="false"match="cms.xoyo.com/site([/a-zA-Z0-9]*).xoyo.com/images"/>
</localpath>
</plugin>
</head>
上述文件解释:
<remoteip="10.0.0.41" name="backup"/>
#服务端地址和目录,backup还对应服务端中/etc/rsyncd.conf的path = /backup/
<authstart="true" users="rsync_backup" passwordfile="/etc/rsync.password"/>
#rsync_backup对应服务端/etc/rsyncd.conf中的‘auth users = rsync_backup‘
#/etc/rsync.password是客户端的内容要对应服务端etc/rsync.password中的内容。
#客户端[[email protected] profile.d]# cat /etc/rsync.password
oldboy
#服务端
[[email protected] backup]# cat /etc/rsync.password
rsync_backup:oldboy
#注意服务端中backup目录的权限
[[email protected] /]# ls -ld /backup/
drwxr-xr-x 3 rsync rsync 4096 Jun 10 14:37 /backup/
#测试
[[email protected] ~]# sersync -r -d -o /usr/local/sersync/conf/confxml.xml
#查看客户端本地
[[email protected] backup]# ll
total 8
drwxr-xr-x 2 root root 4096 May 26 04:0710.0.0.31
-rw-r--r-- 1 root root 672 May 26 04:58 flag_2016-05-26
[[email protected] backup]# pwd
/backup
#查看服务端
[[email protected] backup]# pwd
/backup
[[email protected] backup]# ll
total 8
drwxr-xr-x 2 rsync rsync 4096 May 26 04:0710.0.0.31
-rw-r--r-- 1 rsync rsync 672 May 26 04:58 flag_2016-05-26
#下述删除同理。
[[email protected] backup]# touch test1
[[email protected] backup]# ls -l test1
-rw-r--r-- 1 rsync rsync 0 Jun 10 14:16test1
[[email protected] backup]# rm -f test1
[[email protected] backup]# ls -l test1
ls: cannot access test1: No such file ordirectory
[[email protected] backup]# ll
total 8
drwxr-xr-x 2 rsync rsync 4096 May 26 04:0710.0.0.31
-rw-r--r-- 1 rsync rsync 672 May 26 04:58 flag_2016-05-26
#放入开机启动里
[[email protected] profile.d]# echo"/usr/local/sersync/bin/sersync -r -d -o /usr/local/sersync/conf/confxml.xml">>/etc/rc.local
[[email protected] profile.d]# tail -1/etc/rc.local
/usr/local/sersync/bin/sersync -r -d -o/usr/local/sersync/conf/confxml.xml
以上是关于sersync的简单例子的主要内容,如果未能解决你的问题,请参考以下文章