vim rsync_inotify.sh
#!/bin/bash
RSYNC=“rsync -avzHu /rsync/ rsync://hehe@192.168.1.10/data”
INT_CMD=“inotifywait -mrq -e modify,create,move,delete,attrib /rsync” //触发事件权限
export RSYNC_PASSWORD=123 //可解决rsync同步时,无需输入密码
$INT_CMD | while read DIRECOTRY EVENT FILE;do
$RSYNC 1>/dev/null 2>/var/log/rsync_err.log
done
crontab -e //指定计划任务
- */4 * * * source /etc/profile /usr/bin/rsync -avzHu rsync://hehe@192.168.1.10/data /rsync/ //定时下行同步
- */4 * * * source /etc/profile /usr/bin/rsync -avzHu /rsync/ rsync://hehe@192.168.1.10/data //定时上行同步