inotify_tools + rsync 日志增量备份,增量导入

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


转载于:https://my.oschina.net/chunhei2008/blog/352320

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值