rsync+sersync进行数据同步备份

sersync功能多

  1. 支持配置文件管理
  2. 真正的守护进程
  3. 可以对失败文件定时重传
  4. 第三方的http接口
  5. 默认多线程(cdn更新)

 

sercver:192.168.138.131:(配置与之前的一样)

client:192.168.138.132

 

网查参考了很多人家的博客,然后总结写出来的

 

64位下载地址:https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/sersync/sersync2.5.4_64bit_binary_stable_final.tar.gz

客户端的配置:

tar xvf sersync2.5.4_64bit_binary_stable_final.tar.gz

将该文件夹内的两个文件拷贝到/usr/local/sersync/目录下(目录不存在,自己创建)

创建密码文件,权限600

touch /etc/rsyncd.passwd

echo ‘123456’ > /etc/rsyncd.passwd

创建需要备份的目录:

mkdir /123

 

编辑配置confxml.xml(这里是借鉴别人的博客写的)

<?xml version="1.0" encoding="ISO-8859-1"?>

<head version="2.5">

<host hostip="localhost" port="8008"></host> #保留字段,默认即可

<debug start="false"/> #是否开启调试模式,默认false即可

<fileSystem xfs="true"/> #是否开启支持xfs文件系统,Centos7默认都是xfs的了,所以建议true开启

<filter start="false"> #是否开启过滤模式,根据需求开启,例:过滤以.php结尾的文件(.*)\.php

<exclude expression="(.*)\.svn"></exclude> #过滤以.svn结尾的文件

<exclude expression="(.*)\.gz"></exclude> #过滤以.gz结尾的文件

<exclude expression="^info/*"></exclude> #过滤监控目录下的info路径

<exclude expression="^static/*"></exclude> #过滤监控目录下的static路径

<exclude expression="wwwroot/blogwhsir/*"></exclude> #过滤wwwroot/blogwhsir/目录下所有文件

</filter>

<inotify> #inotify监控事件

<delete start="true"/> #如果不开启此项,在删除监控目录下的文件时,目标服务器的文件则不会同时删除,根据需求开启

<createFolder start="true"/> #不开启不能监控子目录,建议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"> #指定要监控的本地目录

<remote ip="127.0.0.1" name="tongbu1"/> #指定要同步的目标服务器的IP地址,及目标服务器rsync的[模块]

<!--<remote ip="192.168.8.39" name="tongbu"/>-->

<!--<remote ip="192.168.8.40" name="tongbu"/>-->

</localpath>

<rsync> #配置rsync

<commonParams params="-artuz"/> #rsync的参数

<auth start="false" users="root" passwordfile="/etc/rsync.pas"/> #是否开启rsync的认证模式,需要配置users及passwordfile,根据情况开启(如果开启,注意密码文件权限一定要是600)

<userDefinedPort start="false" port="874"/><!-- port=874 --> #远程目标服务器的端口不是默认端口时使用

<timeout start="false" time="100"/><!-- timeout=100 --> #是否开启rsync的超时时间

<ssh start="false"/>

</rsync>

<failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once--> #目标服务器传输失败时会重新传输,再次失败会写入rsync_fail_log中,每隔一段时间(timeToExecute)执行脚本再次传输

<crontab start="false" schedule="600"><!--600mins--> #对监控目录与目标服务器每隔一段时间进行一次整体同步,默认600分钟,根据个人情况是否开启

<crontabfilter start="false"> #如果之前开启了文件过滤,这里也要设置过滤

<exclude expression="*.php"></exclude>

<exclude expression="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="https://blog.whsir.com"/>

<regexurl regex="false" match="cms.xoyo.com/site([/a-zA-Z0-9]*).xoyo.com/images"/>

</localpath>

</plugin>

</head>

 

我自己编辑的配置文件:

<?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="false"/>

         <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="/123">

             <remote ip="192.168.138.131" name="backup"/>

             <!--<remote ip="192.168.8.39" name="tongbu"/>-->

             <!--<remote ip="192.168.8.40" name="tongbu"/>-->

         </localpath>

         <rsync>

             <commonParams params="-artuz"/>

             <auth start="true" users="ming" passwordfile="/etc/rsyncd.passwd"/>

             <userDefinedPort start="false" port="874"/><!-- port=874 -->

             <timeout start="false" time="100"/><!-- timeout=100 -->

             <ssh start="false"/>

         </rsync>

         <failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->

         <crontab start="false" schedule="600"><!--600mins-->

             <crontabfilter start="false">

                   <exclude expression="*.php"></exclude>

                   <exclude expression="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>

 

启动服务:

         /usr/local/sersync/sersync2 –n 10 –d –o /user/local/sersync/confxml.xml

                   -n:启动线程数量

                   -d:daemon方式启动

                   -o:指定配置文件

-r参数作用是:开启实时监控的之前对主服务器目录与远程目标机器的目录进行一次整体同步

-m参数:不进行同步,只运行插件 ./sersync -m pluginName

sersync在第一次启动的时候,不会自动吧启动之前文件备份,只有事件触发后,文件才会全部备份或者其他方法:

      cd /usr/local/sersync/

      ./sersync2 -r

同步完成

 

同时,也可以指定多个配置文件,例如1confxml.xml、2confxml.xml等等,然后在指定配置文件的时候对多个文件进行指定,然后就可以同时监控多个目录了

 

然后通过再/123下创建文件检测同步是否完成

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

xuuuuuuuuMing

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值