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.pass $SRC $DEST && echo "At ${TIME} on ${DATE}, file $FILEPATH was backuped up via rsync" >> /var/log/changelist.log
done
#查看文件传输日志
[root@data-centos8 ~]#tail -f /var/log/changelist.log
本文链接:https://www.yunweipai.com/36024.html
网友评论comments