• 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

     

  • 相关阅读:
    java之this关键字
    单位转换类UnitUtil2
    重量WeightFormatUtil辅助类
    语音提示辅助类MySoundAlertUtil
    Android 编程下 Touch 事件的分发和消费机制
    switch case语句的用法
    Struts2之环境配置
    CSS属性绘制图形(一)
    jquery $(document).ready() 与window.onload的区别
    Android开发之ActionBar
  • 原文地址:https://www.cnblogs.com/fjping0606/p/6114123.html
Copyright © 2020-2023  润新知