zoukankan      html  css  js  c++  java
  • inotify+rsync安装配置

    环境 系统 IP地址
    主服务器 CentOS7.4 192.168.1.1
    备份服务器 CentOS7.4 192.168.1.2

     

    一、备份服务器

    安装rsync(备)

    wget https://rsync.samba.org/ftp/rsync/src/rsync-3.1.3.tar.gz
    tar -xf rsync-3.1.3.tar.gz
    ./configure --prefix=/usr/local/rsync 
    make && make install 
    

     配置rsyncd.conf

    cat <<EOF> /etc/rsyncd.conf 
    pid file = /var/run/rsync.pid  
    log file = /var/log/rsync.log 
    lock file=/var/run/rsync.lock  
    secrets file = /etc/rsync.pw  
    motd file = /etc/rsyncd.motd  
    transfer logging = yes  
    log format = %t %a %m %f %b  
    syslog facility = local3  
    [data]  
    path = /data/test/
    comment = data
    exclude = 
    port = 873
    uid = root
    gid = root
    timeout = 600
    max connections = 200
    use chroot = no
    read only = no
    list = no
    hosts allow = 192.168.1.1
    EOF
    

     可以设置多个目录

    #增加test1目录  
    [test1]  
    path = /data/test1  
    list = yes  
    ignore errors  
    comment = ucweb-file system  
    secrets file = /etc/rsync.pw  
    exclude = blank.png ; spinner.gif ; downsimple.png ; rails.png ; WEB-INF/  
    

    建立密码认证文件

    cat <<EOF> /etc/rsync.pw  
    root:123456  
    EOF
    

    配置rsyncd.motd文件,开始传送的时候会显示

    cat <<EOF> /etc/rsyncd.motd  
    ###############################  
    #                             #  
    #        start rsync          #  
    #                             #  
    ###############################  
    EOF
    

    启动rsync

    /usr/local/rsync/bin/rsync --daemon --config=/etc/rsyncd.conf  
    

    开机启动rsync

    echo '/usr/local/rsync/bin/rsync --daemon --config=/etc/rsyncd.conf'>>/etc/rc.d/rc.localer 

    二、主服务器

    建立密码认证文件

    cat <<EOF> /etc/rsync.pw  
    123456
    EOF
    

    测试开始

    /usr/local/rsync/bin/rsync -avH --port=873 --progress --delete /data/test/ root@192.168.1.3::data --password-file=/etc/rsync.pw
    

    查看192.168.1.2上是否有同步

    安装inotify-tools

    yum install inotify-tools -y
    

    新建inotify.sh文件同步

    #!/bin/sh  
    # get the current path  
    CURPATH=`pwd`  
    /usr/bin/inotifywait -mr --timefmt '%d/%m/%y %H:%M' --format '%T %w %f' -e modify /data | while read date time dir file; do  
           FILECHANGE=${dir}${file}  
           # convert absolute path to relative  
           FILECHANGEREL=`echo "$FILECHANGE" | sed 's_'$CURPATH'/__'`  
    
           /usr/bin/rsync -avH --port=873 --progress --delete /data/test/ root@192.168.1.2::data --password-file=/etc/rsync.pw 
           echo "At ${time} on ${date}, file $FILECHANGE was backed up via rsync"  
    done  
    


    注意: 

    如果仅仅是备份的话,不要带delete参数

    参考链接

    https://blog.csdn.net/liuzheng0915/article/details/52003942

    三、研究

    lrsync

    https://www.cnblogs.com/zxci/p/6243574.html

  • 相关阅读:
    计算机一些常见名词解释
    [MSF]server/capture/http_javascript_keylogger键盘记录
    .net(C#)访问Oracle数据库的几种免安装组件的对比
    C# UserControl 判断是否是设计模式中
    Python_cmd的各种实现方法及优劣(subprocess.Popen, os.system和commands.getstatusoutput)
    python 怎么启动一个外部命令程序, 并且不阻塞当前进程
    创建注记图层C# IFeatureWorkspaceAnno
    VisualSVN Server 导入已存在的库
    带您了解Oracle层次查询
    win7系统使用engine进行开发报错,“未能加载文件或程序集”
  • 原文地址:https://www.cnblogs.com/luchuangao/p/9118937.html
Copyright © 2011-2022 走看看