rsync
- 本地同步操作
- . rsync [选项] 本地目录1 本地目录2
- rsync[选项]本地目录1/本地目录2
rsync同步工具常用选项: - -n:测试同步过程,不做实际修改
- -delete : 删除目标文件内多余的文档
- -a : 归档模式,相当于-rlptgoD
- -v:显示详细操作信息
- -z:传输过程中启用压缩/解压
rsync -a /boot /todir //将目录/boot同步到/todir下
rsync -a /boot/ /todir //将目录/boot下的文档同步到/todir中
rsync -anv /boot /todir //模拟同步过程,不真同步,提示同步时传输了那些文件
rsync -a --delete /boot/ /todir //删除目录todir下多余的文件,保证目录的内容一致
- rsync+SSH远程同步
- rsync […] user@host:远程目录 本地目录
- rsync […] 本地目录 user@host:远程目录
rsync root@192.168.4.7:/ //查看远程主机有哪些子目录
rsync -a root@192.168.4.7:/etc/passwd ./ //从远程主机下载passwd到当前目录
inotifywait监控工具
inotifywait监控操作:
inotifywait [选项] 目标文件夹
- 常用命令选项:
-m 持续监控(捕获一个事件后不退出)
-r 递归监控,包括子目录及文件
-q 减少屏幕输出信息
-e 指定监视的modify,move,create,delete,attrib等事件类型
安装操作
tar xf inotify-tools-3.13.tar.gz -C /usr/srcc/ //解包
cd /usr/src/inotify-tools-3.13/
./configure //配置
make //编译
make install //安装
inotifywait --help //检查安装结果
inotifywait -mrq -e create,modify,move,attrib,delete /opt &
//监控/opt目录下的新建,修改,改名,更改权限,删除等事件
######################################################
#!/bin/bash
dir = /var/www/html
while inotifywait $dir
do
rsync -az --delete $dir root@web2:/$dir
done