rsync+inotify实现实时备份

主服务器上执行:
ssh-keygen
ssh-copy -i ~/.ssh/id_rsa.pub [email protected]
ssh -l root 192.168.189.129
建立ssh免密钥验证

主服务器上保存如下代码为rsync_inotify.sh:
#!/bin/bash
src=/var/www/html
#des需要升一级目录
des=/var/www
ip=192.168.189.129
inotifywait -mrq --timefmt '%d/%m/%y-%H:%M' --format '%T %w %f' -e modify,delete,create,move,attrib $src |while read file
do
rsync -aP --delete $src root@$ip:$des
done
主服务器上执行nohup sh rsync_inotify.sh &后台实时监控,指定目录下的所有文件及目录的属性(modify,delete,create,move,attrib等)变化,触发rsync实时备份。

猜你喜欢

转载自blog.51cto.com/efoni/2176240