#在服务端
yum install rsync
vi /etc/rsyncd.conf
uid = root
gid = root
use chroot = no
max connections=0
log file=/var/log/rsyncd.log
pid file=/var/run/rsyncd.pid
lock file=/var/run/rsyncd.lock
[media]
path = /var/www/html/magento/media
read only = no
list = no
auth users = root
secrets file = /etc/media.pas
vi /etc/media.pas
root:root1234
chmod 600 /etc/media.pas
/usr/bin/rsync --daemon --config=/etc/rsyncd.conf
#在客户端
yum install inotify-tools
vi /etc/rules.txt
- *.svn*
vi /bin/inotify_rsync.sh
#!/bin/sh
if [ ! -f /etc/media.pas ];then
echo "root1234">/etc/media.pas
/bin/chmod 600 /etc/media.pas
fi
log=/var/log/rsync.log
src="/var/www/html/magento/media/"
host="192.168.1.104"
module="media"
/usr/bin/inotifywait -mr --timefmt '%d/%m/%y %H:%M' --format '%T %w %f' -e close_write,modify,delete,create,attrib $src | while read DATE TIME DIR FILE; do
FILECHANGE=${DIR}${FILE}
/usr/bin/rsync -avH --delete --progress --password-file=/etc/media.pas $src --exclude-from="/etc/rules.txt"root@$host::$module &
echo "At ${TIME} on ${DATE}, file $FILECHANGE was backed up via rsync" >> $log
done
chmod +x /bin/inotify_rsync.sh
/bin/inotify_rsync.sh &