YAZONG 我的开源

sersync示例

  ,
0 评论0 浏览
前提条件:

  

使用sersync要事先配置rsync的部分内容,请参考我的另一篇博文“[以rsync的daemon工作模式传输数据(https://blog.llyweb.com/articles/2016/06/10/1578160452581.html)”。

  

其中nfs01为客户端,backup为服务端。

  

  

  

[root@nfs01 tools]#mkdir –p /home/oldboy/tools

  

#通过rz –y的方式上传本地sersync_64bit_binary_stable_final.tar.gz到/home/oldboy/tools目录下。

  

  

[root@nfs01 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

  

  

[root@nfs01 tools]# tar -ztf sersync_64bit_binary_stable_final.tar.gz

  

GNU-Linux-x86/

  

GNU-Linux-x86/sersync2

  

GNU-Linux-x86/confxml.xml

  

  

[root@nfs01 sersync]# mkdir -p /usr/local/sersync/bin/

  

[root@nfs01 sersync]# mkdir -p /usr/local/sersync/conf/

  

  

[root@nfs01 tools]# tar -zxf /home/oldboy/tools/sersync_64bit_binary_stable_final.tar.gz -C /usr/local/sersync/

  

  

[root@nfs01 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

  

  

#备份并放入自个规定的目录中

  

[root@nfs01 sersync]# cp /usr/local/sersync/GNU-Linux-x86/sersync2 /usr/local/sersync/bin/sersync

  

  

[root@nfs01 sersync]# cp /usr/local/sersync/GNU-Linux-x86/confxml.xml /usr/local/sersync/conf/

  

#加入环境变量

  

[root@nfs01 bin]# echo "exportPATH=$PATH:/usr/local/sersync/bin" >>/etc/profile

  

  

[root@nfs01 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/

  

#使环境变量生效

  

[root@nfs01 profile.d]# source /etc/profile

  

#需要修改的地方已标红

  

[root@nfs01 ~]# 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/p_w_picpaths"/>

  

</localpath>

  

</plugin>

  

</head>

  

上述文件解释:

  

1)<remoteip="10.0.0.41" name="backup"/>

  

#服务端地址和目录,backup还对应服务端中/etc/rsyncd.conf的path = /backup/

  

2)<authstart="true" users="rsync_backup" passwordfile="/etc/rsync.password"/>

  

#rsync_backup对应服务端/etc/rsyncd.conf中的'auth users = rsync_backup'

  

#/etc/rsync.password是客户端的内容要对应服务端etc/rsync.password中的内容。

  

#客户端[root@nfs01 profile.d]# cat /etc/rsync.password

  

oldboy

  

#服务端

  

[root@backup backup]# cat /etc/rsync.password

  

rsync_backup:oldboy

  

#注意服务端中backup目录的权限

  

[root@backup /]# ls -ld /backup/

  

drwxr-xr-x 3 rsync rsync 4096 Jun 10 14:37 /backup/

  

  

#测试

  

[root@nfs01 ~]# sersync -r -d -o /usr/local/sersync/conf/confxml.xml

  

  

#查看客户端本地

  

[root@nfs01 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

  

[root@nfs01 backup]# pwd

  

/backup

  

  

#查看服务端

  

[root@backup backup]# pwd

  

/backup

  

[root@backup 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

  

  

#下述删除同理。

  

[root@nfs01 backup]# touch test1

  

[root@backup backup]# ls -l test1

  

-rw-r--r-- 1 rsync rsync 0 Jun 10 14:16test1

  

  

[root@nfs01 backup]# rm -f test1

  

[root@backup backup]# ls -l test1

  

ls: cannot access test1: No such file ordirectory

  

[root@backup 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

  

  

#放入开机启动里

  

[root@nfs01 profile.d]# echo"/usr/local/sersync/bin/sersync -r -d -o /usr/local/sersync/conf/confxml.xml">>/etc/rc.local

  

[root@nfs01 profile.d]# tail -1/etc/rc.local

  

/usr/local/sersync/bin/sersync -r -d -o/usr/local/sersync/conf/confxml.xml

标题:sersync示例
作者:yazong
地址:https://blog.llyweb.com/articles/2016/06/10/1578160204303.html