站长资讯网
最全最丰富的资讯网站

rsync + inotify 文件同步

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

赞(0)
分享到: 更多 (0)
网站地图   沪ICP备18035694号-2    沪公网安备31011702889846号