rsync+inotify实现数据的实时备份实例

 

1.原后台与新后台数据复制同步

Ip:10.123.11.143 (新)

10.123.11.145 (旧)

2.新服务器上建立rsync服务器:

vi /etc/default/rsync   

将RSYNC_ENABLE=false改为RSYNC_ENABLE=true     

 cp /usr/share/doc/rsync/examples/rsyncd.conf /etc/

vi rsyncd.conf

# sample rsyncd.conf configuration file

# GLOBAL OPTIONS

#motd file=/etc/motdlog file=/var/log/rsyncd

# for pid file, do not use /var/run/rsync.pid i

f# you are going to run rsync out of the init.d script.

pid file=/var/run/rsyncd.pid

syslog facility=daemon

#socket options=

# MODULE OPTION

[host21]      

comment = public archive       

 path = /opt/woshare        

use chroot = no#      

 max connections=10        

lock file = /var/lock/rsyncd

# the default for read only is yes...      

 read only = no      

  list = yes       

 uid = root      

  gid = root

#       exclude =

 #       exclude from =

 #       include =

#       include from =

#       auth users =         

secrets file = /etc/rsyncd.secrets        

strict modes = yes

#       hosts allow =

#       hosts deny =        

ignore errors = yes        

ignore nonreadable = no       

 transfer logging = no

#       log format = %t: host %h (%a) %o %f (%l bytes). Total %b bytes.       

 timeout = 600       

 refuse options = checksum dry-run        

dont compress = *.gz *.tgz *.zip *.z *.rpm *.deb *.iso *.bz2 *.tbz

echo "syncer:syncer123">/etc/rsyncd.secrets  

   A:安装inotify工具inotify-tools    

     由于inotify特性需要Linux内核的支持,在安装inotify-tools前要先确认Linux系统内核是否达到了 2.6.13以上,如果Linux内核低于2.6.13版本,就需要重新编译内核加入inotify的支持,

     也可以用如下方法判断,内核是否支持 inotify:

[root@localhost webdata]# uname -r

2.6.18-164.11.1.el5PAE

[root@localhost webdata]# ll /proc/sys/fs/inotify

总计 0-rw-r--r-- 1 root root 0 04-13 19:56 max_queued_events

-rw-r--r-- 1 root root 0 04-13 19:56 max_user_instances

-rw-r--r-- 1 root root 0 04-13 19:56 max_user_watches

如果有上面三项输出,表示系统已经默认支持inotify,接着就可以开始安装inotify-tools了。

可以到http://inotify-tools.sourceforge.net/下载相应的inotify-tools版本,

然后开始编译安装:[

root@localhost  ~]# apt-get install inotify-tools

[root@localhost inotify-tools-3.14]# ll /usr/local/bin/inotifywa*

-rwxr-xr-x 1 root root 37264 04-14 13:42 /usr/local/bin/inotifywai

t-rwxr-xr-x 1 root root 35438 04-14 13:42 /usr/local/bin/inotifywatch

inotify-tools安装完成后,会生成inotifywait和inotifywatch两个指令,其中,inotifywait用于等待文件或文件集上的一个特定事件,它可以监控任何文件和目录设置,并且可以递归地监控整个目录树  

  B:建立自动上传脚本vi  rsync-new21.sh   

  #!/bin/bash

SRC=/opt/woshare/

DST=/opt/woshare/

INWT=/usr/bin/inotifywait

RSYNC=/usr/bin/rsync

$INWT  -mrq --timefmt '%d%m%y %H:%M' --format '%T%w%f' -e modify,delete,move,create,attrib $SRC| 

while read file

do

$RSYNC -qzrtopg --delete --password-file=/etc/rsync-client.pass $SRC syncer@10.123.11.143::host21

Done

<p></p><pre>
 
 

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值