手机版
你好,游客 登录 注册
背景:
阅读新闻

rsync + inotify 实时数据备份

[日期:2012-06-24] 来源:Linux社区  作者:linux521 [字体:大 中 小]

二、rsync配置

1、分别在三台主机上安装rsync(一般CentOS系统默认都安装了):

yum install rsync

2、slave配置

手动在slave节点 /etc 下添加 rsyncd.conf 内容如下:

uid = nobody
gid = nobody
use chroot = no
max connections = 10
strict modes = yes
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log

[web]
path = /web/wwwroot/
comment = web file
ignore errors
read only = no
write only = no
hosts allow =  *
#hosts deny = *
list = false
uid = root
gid = root

将rsync添加到开机启动

echo "/usr/bin/rsync --daemon" >> /etc/rc.local

三、master同步检测

1、master检测脚本

  1. #!/bin/bash 
  2. SRC=/web/wwwroot/ 
  3. INWT=/usr/local/bin/inotifywait 
  4. host1=(192.168.1.71 192.168.1.72) 
  5. user=webuser 
  6. $INWT -mrq --timefmt '%Y/%m/%d %H:%M:%S' --format '%T %w%f%e' \ 
  7.   -e close_write,delete,create,attrib,move $SRC \ 
  8.         | while read files 
  9.                 do 
  10.                     for ((i=0;i<${#host1[@]};i++)) 
  11.                     do 
  12.                         /usr/bin/rsync -vzrtopg --delete --progress  $SRC $user@${host1[$i]}::web 
  13.                         echo "${files} was rsynced ${host1[$i]}" >>/tmp/rsync.log 2>&1 
  14.                     done 
  15.                 done 

 将上述脚本(内容根据自己实际情况修改)保存为 rs.sh,赋予执行权限,并加入到开机启动中,这里不再啰嗦。

2、效果测试

在master上启动脚本

sh rs.sh

在master建立测试文件

master上输出结果:

查看slave结果:

如图所示,测试ok了。

linux
相关资讯       rsync  inotify 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款