zoukankan      html  css  js  c++  java
  • Linux下inotify监控文件夹状态,发生变化后触发rsync同步

    1、安装工具
    --inotify
    wget http://cloud.github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz
    tar -zxvf inotify-tools-3.14.tar.gz
    cd inotify-tools-3.14
    ./configure --prefix=/usr/local/inotify
    make && make install

    --rsync
    下载:http://rsync.samba.org/
    tar -zxvf rsync-3.1.0.tar.gz
    cd rsync-3.1.0
    ./configure --prefix=/usr/local/rsync
    make && make install

     

    2、编写运行脚本:
    [root@192.168.1.1 script]$ vim monitor_dircharge.sh
    #!/bin/sh
    ## -------------------------------------------------

    ## @监控目录状态,有变化后触发rsync同步
    ## -------------------------------------------------

    srcdir="/data/www/New/html/www"
    /usr/bin/inotifywait -mrq --timefmt '%d/%m/%y-%H:%M' --format '%T%w%f' -e modify,delete,create,attrib,move ${srcdir}
    | while read file
    do
    sudo rsync -rlptDvzHS --delete --port=9789 --password-file=/etc/rsyncd.password_client /data/www/New/html/www/ root@192.168.1.2::Server/New/html/www/
    done

     

    3、启动脚本
    nohup sudo sh /data/script/monitor_dircharge.sh >> /tmp/inotify.log 2>&1 &

     

    4、添加开机启动
    echo 'nohup sudo sh /data/script/monitor_dircharge.sh >> /tmp/inotify.log 2>&1 &' >> /etc/rc.local

     

  • 相关阅读:
    安装 android sdk 时,dl.google.com 连不上各种尝试
    解决android SDK 安装过程中 packages 列表为空的问题
    Java 集合 -- Deque
    Java 集合 -- Queue
    Java 集合 -- Set
    Java 集合 -- Map
    Java 集合 -- List
    Java 语言进阶 -- 线程
    Java 语言基础知识
    Java 网络编程基础 -- TCP 编程
  • 原文地址:https://www.cnblogs.com/fjping0606/p/6114123.html
Copyright © 2011-2022 走看看