加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

rsync+inotify 脚本

发布时间:2020-12-14 00:36:21 所属栏目:Linux 来源:网络整理
导读:#!/bin/sh chkconfig: 2345 10 90 description: This Rsync script based on inotify. date: 2019-04-08 version: 1.0 src1=/test #监控的路径des1=uploaders/ #需要同步到那台服务器上的rsync模块名称rsync_passwd_file=/etc/server.pass #密码交互文件ip=1
#!/bin/sh

chkconfig: 2345 10 90

description: This Rsync script based on inotify.

date: 2019-04-08

version: 1.0

src1=/test #监控的路径des1=uploaders/ #需要同步到那台服务器上的rsync模块名称rsync_passwd_file=/etc/server.pass #密码交互文件ip=192.168.8.178 #需要同步的IPuser=yihong #需要同步方的用户inotify=/usr/bin/inotifywaitcd ${src1}$inotify -mrq --timefmt ‘%y-%m-%d %H:%M‘ --format ‘%T %w%f %e‘ --event modify,create,move,delete,attrib ./ |while read filedoINO_EVENT=$(echo $file | awk ‘{print $4}‘)INO_FILE=$(echo $file | awk ‘{print $3}‘)echo "-------------------------$(date)---------------------------" >> /var/log/rsync.log 2>&1echo $file >>/var/log/rsync.log 2>&1if [[ $INO_EVENT=‘CREATE‘ ]]||[[ $INO_EVENT=‘MODIFY‘ ]]||[[ $INO_EVENT=‘CLOSE_WRITE‘ ]]||[[ $INO_EVENT=‘MOVED_TO‘ ]];thenecho ‘CREATE or MODIFY or CLOSE_WRITE or MOVED_TO‘ >> /var/log/rsync.log 2>&1rsync -avzcR $(dirname ${INO_FILE}) ${user}@${ip}::${des1} --password-file=${rsync_passwd_file} >>/var/log/rsync.log 2>&1fiif [[ $INO_EVENT=‘DELETE‘ ]]||[[ $INO_EVENT=‘MOVED_FROM‘ ]];thenecho ‘DELETE or MOVED_FROM‘ >>/var/log/rsync.log 2>&1rsync -avzR --delete $(dirname ${INO_FILE}) ${user}@${ip}::${des1} --password-file=${rsync_passwd_file}>>/var/log/rsync.log 2>&1fiif [[ $INO_EVENT=‘ATTRIB‘ ]];thenecho ‘ATTRIB‘ >>/var/log/rsync.log 2>&1if [ ! -d "$INO_FILE" ];thenrsync -avzcR $(dirname ${INO_FILE}) ${user}@${ip}::${des1} --password-file=${rsync_passwd_file}>>/var/log/rsync.log 2>&1fifidone&

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读