实时数据同步: inotify+rsync+shell

inotify+rsync+shell 脚本实现实时数据同步

按 5.3 搭建好 rsyncd的备份服务器,在数据服务器上创建inotify_rsync.sh脚本

[root@data-centos8 ~]#vim inotify_rsync.sh
#!/bin/bash
SRC='/data/www'
DEST='rsyncuser@rsync服务器IP::backup'
rpm -q rsync &> /dev/null  || yum -y install rsync
inotifywait  -mrq  --exclude=".*/.swp" --timefmt '%Y-%m-%d %H:%M:%S' --format '%T %w %f' -e create,delete,moved_to,close_write,attrib {SRC} |while read DATE TIME DIR FILE;do
        FILEPATH={DIR}{FILE}
        rsync -az --delete  --password-file=/etc/rsync.passSRC DEST && echo "At{TIME} on {DATE}, fileFILEPATH was backuped up via rsync" >> /var/log/changelist.log
done

#查看文件传输日志
[root@data-centos8 ~]#tail -f  /var/log/changelist.log 

本文链接:http://www.yunweipai.com/36024.html

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/courses/52523.html

(0)
上一篇 2021年8月6日 16:22
下一篇 2021年8月6日 16:22

相关推荐

发表回复

登录后才能评论