zoukankan      html  css  js  c++  java
  • inotify+rsync实现文件同步

    #!/bin/bash
    src=/test/
    dest=test
    rsync_secret_file=/etc/rsync_pwdfile
    dest_ip=192.168.37.133
    user=test
    /usr/local/bin/inotifywait -mrq --format '%Xe %w %f' -e modify,delete,create,attrib,move,open,close,access /test | while read file
    do
    test_event=$(echo $file | awk '{print $1}')
    test_path==$(echo $file | awk '{print $2}')
    echo -------------$(date)---------------
    if [[ $test_event =~ 'CREATE' ]] || [[ $test_event =~ 'MODIFY' ]] || [[ $test_event =~ 'CLOSE_WRITE' ]] || [[ $test_event =~ 'MOVED_TO' ]]; then
    echo 'CREATE or MODIFY or CLOSE_WRITE or MOVED_TO'
    rsync -avzcR --password-file=${rsync_secret_file} ${test_path} ${user}@${dest_ip}::${dest}
    fi
    if [[ $INO_EVENT =~ 'DELETE' ]] || [[ $INO_EVENT =~ 'MOVED_FROM' ]];then
    echo 'DELETE or MOVED_FROM'
    rsync -avzR --delete --password-file=${rsync_secret_file} ${test_path} ${user}@${dest_ip}::${dest}
    fi
    if [[ $INO_EVENT =~ 'ATTRIB' ]];then
    echo 'ATTRIB'
    if [ -d ${test_path}];then
    rsync -avzcR --password-file=${rsync_secret_file} ${test_path} ${user}@${dest_ip}::${dest}
    fi
    fi
    done

  • 相关阅读:
    C#:反射
    静态和非静态类
    数据的存入取出(注册机方式)
    退出unity运行
    网络流基础
    欧拉回路
    博弈论问题
    洛谷P5304 [GXOI/GZOI2019] 旅行者
    [ZJOI2006]物流运输
    POJ3278 Catch that cow
  • 原文地址:https://www.cnblogs.com/lishug/p/13215377.html
Copyright © 2011-2022 走看看