文章來源:王琦的個人博客-數據同步之rsync | 第3篇:sersync+rsync ,互聯網打雜,喜歡多語言編程,記錄一些知識碎片,分享一些心得。
前一篇寫了inotify+rsync進行實時同步,但是還有些不足。
- 只能記錄下被監聽的目錄發生了變化,沒有記錄具體到某個文件和目錄。
- rsync在同步時候,每次都是對整個目錄同步,文件多時比較耗時。
sersync是基於inotify開發的。可以具體到某一個文件或者目錄的名字,只同步發生變化的文件或目錄,因此效率會比前者高很多。
sersync下載地址:https://github.com/wsgzao/sersync
sersync配置文件說明
1、監控相關信息
# 過濾不用的信息
<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>
2、數據配置相關信息
<sersync>
<!--指定監控目錄-->
<localpath watch="/opt/tongbu">
<!--指定備份服務器地址和模塊信息-->
<remote ip="172.16.1.41" name="backup"/>
<!--<remote ip="192.168.8.39" name="tongbu"/>-->
<!--<remote ip="192.168.8.40" name="tongbu"/>-->
</localpath>
<rsync>
<!--指定rsync推送時的命令-->
<commonParams params="-az"/>
<!--認證用戶和密碼文件-->
<auth start="true" users="rsync_backup" passwordfile="/etc/rsync.password"/>
<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>
啓動
./sersync -dro /usr/local/sersync/conf/confxml.xml