总结笔记rsync+inotify

rsync+inotify实时同步
intofy:强大,细粒。异步文件系统
  控制文件系统中的添加,删除修改移动 权限等
性能:每秒约200个文件
原理:rsync server------------推送-----rsync从
     inotify服务器对文件监控触发


方法:ls -l /proc/sys/fs/inotify
  是否有3个max文件max_queued_events  16384----327679 max_user_instances max_user_watches8192---50000000
 源码安装
 wget http://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz
 tar zxf 
 cd ..
 ./configure --prefix=/usr/local/inotify
 make
 make install
 ln -s /usr/local/inotify... /usr/local/inotify
 目录结构:
 bin  inotify二进制命令
 include 程序所需的头文件
 lib 动态链接库文件
 share 帮助文档
inotifywait常用的参数
 -r|--recursive 递归查询目录
 -q|--quiet打印监控的事件信息
 -m|--monitor始终保持事件监听的状态
 --excludei<pattern>排除文件或者目录,不区分大小写
 --timefmt<fmt>指定时间输出格式
 --format<fmt>打印使用指定的输出类似格式字符串
 -e|--event<event1>通过此参数指定要监控事件
 events:
  access  文件或者目录的读取
  modify 文件或者目录被修改
  attrib   文件或目录属性被改变
  close封闭 无论,读写模式
  open打开
  moved_to移动
  moved_to移动
  create 创建
  delete删除
  unmount卸载
测试create监控
 /usr/local/inotify-tools-3.14/bin/inotifywait -mrq --timefmt '%d%m%y %H%M' --format '%T %w%f' -e create /backup
测试删除监控
 /usr/local/inotify-tools-3.14/bin/inotifywait -mrq --timefmt '%d%m%y %H%M' --format '%T %w%f' -e delete /backup
实际脚本:
#!/bin/bash
#para
host01=192.168.1.1服务器ip
src =/data0/www/www主的目录
user=rsync_backup
rsync_passfile=/etc/rsync.password
inotify_home=/usr/local/inotify-tool-3.14/
#judge
if [ ! -e "$src" ]\
||[ ! -e "${rsync_passfile}" ]\
||[ ! -e "${inotify_)home}/bin/inotifywait" ]\
||[ ! -e "/usr/bin/rsync" ];
then
 echo "check file and floder"
 exit 9
fi
${inotfiy_hom}/bin/inotfiywait -mrq --timefmt '%d%m%y %H%M' --format '%T %w%f' -e close_write,delete,create,attr5ib $src \
|while read file
do
 #rsync -avz --delete --timout=100 --password-file=${rsync_passfile}$src $usr@$host01::$dst >/dev/null 2>&1
 cd $src && rsync -avz -R ./ --timeout=100 $user@$host01::$dst --password-file=${rsync_passfile}>/dev/null 2>&1
  done
  exit 0
 

你可能感兴趣的:(笔记,rsync,inotify)