1、inotify_tools + rsync 日志增量备份配置
日志生产机:
inotify_tools
rysnc
日志分发脚本:
#!/bin/bash
host1=192.168.1.100
src=/tmp/test/
dst1=web1
user1=web1user
/usr/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e modify,delete,create,attrib $src \
| while read files
do
/usr/bin/rsync -vzrtopg --delete --progress --password-file=/etc/server.pass $src $user1@$host1::$dst1
echo "${files} was rsynced" >>/tmp/rsync.log 2>&1
done
大概的意思就是利用inotify_tools 监控文件夹,文件有变化时会有相应的事件,从而调用rysnc作同步
密码文件格式 password
日志接收机:
uid = nobody
gid = nobody
use chroot = no
max connections = 10
strict modes = yes
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
[web1]
path = /tmp/test/
comment = test rsync
ignore errors
read only = no
write only = no
hosts allow = 192.168.1.99
hosts deny = *
list = false
uid = root
gid = root
auth users = web1user
secrets file = /etc/web1.pass
服务器的密码文件格式为 user:password
rysnc --daemon // 服务器端rsync 守护模式启动
2、增量导入
日志接收机
#!/bin/bash
inotifywait -rm --format "%w%f" -e close_write /tmp/test | while read files
do
// 这里由于事件打印出来的文件名后面带了几位特殊字符,需要去掉才是真正的文件名
files=${files/\/./\/}
len=${#files}
len=`expr $len - 7`
#echo $files
echo ${files:0:$len}
# done some thing load 这里可以对文件进行操作
sleep 5
done