inotity-tools是用于监视linux文件系统变化的工具,非常适合于一些要求实时同步的场合,在linux内核为2.6.13版本以上的内核才支持,

使用uanme -r 查看,我使用的是ubuntu

zhxia@ubuntu-zhxia:/var/www/test$ uname -r
2.6.35-22-generic-pae

首先安装inotify-tools,可以自行下载源码包安装,但我使用ubuntu的apt-get方式安装

sudo apt-get install inotify-tools

 

一下shell是将 /var/www目录同步到 /tmp/下

#! /bin/bash
src=/var/www
dest=/tmp/
inotify=`which inotifywait`
rsync=$(which rsync)
$inotify -mrq --timefmt '%Y-%m-%d %H:%M:%s' --format '%T %w%f%e' -e modify,delete,create,attrib $src | \
        while read files
                do
                $rsync -avz --progress $src $dest
                echo "${files} was changed!"
                done

 

相关文章:

  • 2021-10-05
  • 2021-09-23
  • 2022-12-23
  • 2021-07-09
  • 2021-12-20
  • 2021-11-02
  • 2021-09-10
猜你喜欢
  • 2021-08-09
  • 2021-12-10
  • 2021-11-01
  • 2021-11-09
  • 2021-08-21
  • 2021-12-01
相关资源
相似解决方案