rsync + inotify 文件同步
阿新 • • 發佈:2018-11-23
done exclude bash don host onf -i 同步 cti
rpm -e rsync-3.1.2-4.el7.x86_64 --nodeps
rpm -ivh rsync-3.1.2-4.el7.x86_64.rpm
115 服務端,接收文件的地方
echo "web:123" > /usr/local/rsync/rsyncd.passwd
vi /etc/rsyncd.conf
# /etc/rsyncd: configuration file for rsync daemon mode
# See rsyncd.conf man page for more options.
uid = root
gid = root
use chroot = no
max connections = 200
timeout = 1000
transfer logging = yes
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
log file = /var/log/rsyncd.log
log format = %t %a %m %f %b
port = 873
ignore errors
#read only = yes
#address = 192.168.248.136
[web]
path = /home/dqws_ftp/upload/
read only = false
write only = yes
hosts allow = xxxxx
hosts deny = *
list = false
auth users = web
secrets file = /usr/local/rsync/rsyncd.passwd
#read only = yes
#exclude = test/ #不同步的目錄
cd /usr/local/rsync
chmod 600 rsyncd.passwd
rsync --daemon
echo "/usr/local/rsync/bin/rsync --daemon --config=/usr/local/rsync/rsyncd.conf" >> /etc/rc.local
114 客戶端,發送文件的地方
echo "123" > /usr/local/rsync/rsync.passwd
cd /usr/local/rsync
chmod 600 rsyncd.passwd
/usr/bin/rsync -vzrtopg --progress --password-file=/usr/local/rsync/rsyncd.passwd /home/dqws_ftp/upload/ web@xxxxxx::web
刪除安裝包
rpm -ivh inotify-tools-3.14-8.el7.x86_64.rpm
腳本
#!/bin/bash
host=xxxxxx
src=/home/dqws_ftp/upload/
des=web
user=web
/usr/bin/inotifywait -mrq --timefmt ‘%d/%m/%y %H:%M‘ --format ‘%T %w%f%e‘ -e modify,create,attrib $src | while read files
do
/usr/bin/rsync -vzrtopg --progress --password-file=/usr/local/rsync/rsyncd.passwd $src $user@$host::$des
echo "${files} was rsynced" >> /data/logs/rsync.log 2>&1
done
rsync + inotify 文件同步