美文网首页Linux
SuSE Linux下 rsync+inotify实现文件自动同

SuSE Linux下 rsync+inotify实现文件自动同

作者: sunland_0416 | 来源:发表于2020-12-02 17:10 被阅读0次

前面的操作已经基本适应日常使用,这次来看看能不能把inotify的配置独立出来
初步设想是把对应模块名称和路径建立一个单独文件module_path.conf;IP存放在另一个文件ip.conf

ip.conf内容如下

192.168.1.166
192.168.1.165
192.168.1.164

module_path.conf脚本如下

/home/test1/rsync web1
/home/test2/rsync web2

inotify脚本如下:

#!/bin/bash
host=192.168.1.170

ip_path="/home/ip.conf"
module_path_path="/home/module_path.conf"

passwd=/home/test/rsync.passwd
log=/home/test/rsyncd.log
user=root

fun_inotify(){
    /home/test/inotify/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w %f %e' -e modify,delete,attrib $1 |while read files
    do
        while read line
        do
            line=$line|sed 's/ //g'
            /usr/bin/rsync -vzrtopg --delete --ignore-errors --password-file=$passwd $1 $user@$line::$2
            echo "${files} was rsynced">>$log 2>&1
        done < $ip_path
    done
}

while read src des
do
    fun_inotify $src $des &
done < $module_path_path

以上修改只是在客户端,源服务器修改,目标服务器,服务端不变

相关文章

网友评论

    本文标题:SuSE Linux下 rsync+inotify实现文件自动同

    本文链接:https://www.haomeiwen.com/subject/lvhuwktx.html