Inotify+Rsync实现linux文件实时同步(2)

来源:it168 作者:it168
  '=' -f 2 `
#
inotifywait
-mrq --timefmt '%d/%m/%y %H:%M' --format  '%T %w%f %e' \
--event modify,create,move,delete  ${src} | while read  date time file event
        
do
                echo $event
            
for i in $des
            
do
                
case $event in
                MODIFY
|CREATE|MOVE|MODIFY,ISDIR|CREATE,ISDIR|MODIFY,ISDIR)
                        #echo $src
                        no_src_root_file_name
=`echo $file|sed "s#$src##g"`
                        final_target_dest
=$i$no_src_root_file_name

                       echo rsync
-avz --delete --progress $file $final_target_dest
                        rsync
-avz --delete --progress $file $final_target_dest
                ;;
                DELETE
|DELETE,ISDIR)
                        src_file_up_dir
=`echo $file|awk -F"/" '{NF=NF-1;OFS="/";print $0}'`
                        no_root_src_file_up_dir
=`echo $file|awk -F"/" '{NF=NF-2;OFS="/";print $0}'|sed "s#$src##g"`
                        final_target_dest_up_dir
=$i$no_root_src_file_up_dir
                echo    rsync
-avz --delete --progress $src_file_up_dir $final_target_dest_up_dir
                        rsync
-avz --delete --progress $src_file_up_dir $final_target_dest_up_dir
                ;;
                esac
            done
        done
############################################################################################
rsync.conf
local directory
=/EBS/www/projects
#dest_here
dest
=root@174.129.219.40:/EBS/www
20090723
--format '%T %w%f'

  其中的%f参数: %f When an event occurs within a directory, this will be replaced with the name of the File which caused he event to occur. Otherwise, this will be replaced with an empty string.

  如果不加%f参数,当一个文件夹里的文件发生变化时,不会输出文件名(需要自己echo脚本里read的变量),而时输出发生变化的文件的文件夹名,可以将这一点用于减少rsync遍历中的delete事件。

  另外,%w是用于输出发生变化的文件的。

  %w This will be replaced with the name of the Watched file on which an event occurred.


时间:2010-03-03 22:03 来源:it168 作者:it168 原文链接

好文,顶一下
(2)
66.7%
文章真差,踩一下
(1)
33.3%
------分隔线----------------------------


把开源带在你的身边-精美linux小纪念品
论坛精华
一周热点
无觅相关文章插件,快速提升流量