inotify+rsync实时同步起源及简介
inotify服务机制
inotify实施准备
inotify配置是建立在rsync服务的基础上
inotify,sersync,lsyncd
sersync功能更多,可以做各种过滤,但从性能上看,通过测试得出inotify性能更高,每秒钟能同步好几百张图片,inotify 150张就不能实时了
实施前检查rsync daemon是正常
[root@A oldboy]# ps -ef |grep daemon root 1261 1 0 Dec11 ? 00:00:04 /usr/bin/rsync --daemon root 13942 1945 0 02:57 pts/0 00:00:00 grep daemon
并且可以正常推送
[root@B scripts]# rsync -avz /data/ rsync_backup@192.168.129.128::data --password-file=/etc/rsync.password sending incremental file list ./ 10 100 11 sent 4345 bytes received 1893 bytes 4158.67 bytes/sec total size is 0 speedup is 0.00
工作场景
inotify的安装
inotifywait命令常用参数
inotify.sh脚本配置参数
[root@B data]# cat /server/scripts/inotify1.sh #!/bin/bash #para host01=192.168.129.128 src=/data dst=oldboy user=rsync_backup rsync_passfile=/etc/rsync.password inotify_home=/usr/local/ #judge #if [ ! -e "$src"] \ #|| [ ! -e "${rsync_passfile}" ] \ #|| [ ! -e "${inotify_home}/bin/inotifywait" ] \ #|| [ ! -e "/usr/bin/rsync" ] ; #then # echo "Check File and Folder" # exit 9 #fi ${inotify_home}/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f' -e close_write,delete,create,attrib $src \ | while read file #读前一段代码输出的 文件 do #rsync -avzP --delete --timeout=100 --password-file=${rsync_passfile} $src $user@$host01::$dst >/dev/null 2>&1 cd $src&& rsync -aruz -R --delete ./ --timeout=100 $user@$host01::$dst--password-file=${rsync_passfile} >/dev/null 2>&1 done exit 0