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
本文鏈接:http://www.thecarconnectin.com/36024.html
網友評論comments