rsync+inotify實現文件時實同步 git
1 uid = root 2 gid = root 3 use chroot = no 4 max connections =5 5 pid file =/var/run/rsyncd.pid 6 lock file =/var/run/rsync.lock 7 log file =/var/log/rsyncd.log 8 [www] 9 path=/data/httpd/wwwroot/ 10 comment = update 11 ignore errors 12 read only = no 13 list = no 14 hosts allow =192.168.0.0/255.255.255.0 15 auth users = root 16 uid = root 17 gid = root 18 secrets file =/etc/rsyncd.secrets
1 #!/bin/bash 2 src=/data/httpd/wwwroot/ 3 des=www 4 host="192.168.0.6 192.168.0.7 192.168.0.8" 5 /usr/local/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M'--format '%T %w%f%e'-e close_write,delete,create,attrib $src |while read files 6 do 7 for hostip in $host 8 do 9 rsync -vzrtopg --delete --progress --password-file=/etc/rsyncd.secrets $src root@$hostip::$des 10 done 11 echo "${files} was rsynced">>/tmp/rsync.log 2>&1 12 done