RSYNC同步Inotifywait监控

rsync

  1. 本地同步操作
  • . 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下多余的文件,保证目录的内容一致
  1. 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值