首页 > 其他 > 详细

inotify+rsync实现文件同步

时间:2020-06-30 20:07:36      阅读:68      评论:0      收藏:0      [点我收藏+]

#!/bin/bash
src=/test/
dest=test
rsync_secret_file=/etc/rsync_pwdfile
dest_ip=192.168.37.133
user=test
/usr/local/bin/inotifywait -mrq --format ‘%Xe %w %f‘ -e modify,delete,create,attrib,move,open,close,access /test | while read file
do
test_event=$(echo $file | awk ‘{print $1}‘)
test_path==$(echo $file | awk ‘{print $2}‘)
echo -------------$(date)---------------
if [[ $test_event =~ ‘CREATE‘ ]] || [[ $test_event =~ ‘MODIFY‘ ]] || [[ $test_event =~ ‘CLOSE_WRITE‘ ]] || [[ $test_event =~ ‘MOVED_TO‘ ]]; then
echo ‘CREATE or MODIFY or CLOSE_WRITE or MOVED_TO‘
rsync -avzcR --password-file=${rsync_secret_file} ${test_path} ${user}@${dest_ip}::${dest}
fi
if [[ $INO_EVENT =~ ‘DELETE‘ ]] || [[ $INO_EVENT =~ ‘MOVED_FROM‘ ]];then
echo ‘DELETE or MOVED_FROM‘
rsync -avzR --delete --password-file=${rsync_secret_file} ${test_path} ${user}@${dest_ip}::${dest}
fi
if [[ $INO_EVENT =~ ‘ATTRIB‘ ]];then
echo ‘ATTRIB‘
if [ -d ${test_path}];then
rsync -avzcR --password-file=${rsync_secret_file} ${test_path} ${user}@${dest_ip}::${dest}
fi
fi
done

inotify+rsync实现文件同步

原文:https://www.cnblogs.com/lishug/p/13215377.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!