Chinaunix首页 | 论坛 | 博客
  • 博客访问: 102289
  • 博文数量: 21
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 231
  • 用 户 组: 普通用户
  • 注册时间: 2014-12-16 16:23
文章分类

全部博文(21)

文章存档

2017年(3)

2016年(9)

2015年(9)

我的朋友

分类: 系统运维

2016-10-19 11:05:47

inotify:监控文件目录变化
rsync:实现文件增量同步备份



主服务器,安装rsync客户端及inotify

 [root@node1 ~]# cat rsync.sh
#!/bin/bash
host=192.168.128.131  #备份服务器IP
src=/tmp/        
des=web  #备份服务器 rsyncd.config模块一致
user=trsync   #备份服务器 rsyncd.config用户一致
/usr/local/inotify/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e modify,delete,create,attrib $src  | while read files #实时检测/tmp/主服务器目录文件的变换
do  
rsync -avzL --password-file=/root/rsync.passwd $src $user@$host::$des  #将/tmp/主服务器目录文件增量备份到备份服务器
echo "${files} was rsynced" >>/root/rsync.log 2>&1
done


创建password-file

[root@node1 ~]# cat /root/rsync.passwd
rsync-pwd   #此密码跟备份服务器中的  rsyncd.config密码一致


备份服务器:安装rsync服务端,并配置rsyncd.config

[root@node2 tmp]# vi /etc/rsyncd.conf
uid = root
gid = root
use chroot = no
max connections = 10
strict modes = yes
pid file = /var/run/rsyncd.pid

hosts allow=192.168.128.132 #主服务器IP
hosts only=yes

[web]
path = /tmp/
comment = web file
ignore errors
read only = no
write only = no
list = false
auth users = trsync
secrets file = /etc/rsync.passwd   配置密码


启动rsyncd
rsync --daemon --config=/etc/rsyncd.conf

[root@node2 tmp]# cat  /etc/rsync.passwd  创建
trsync:rsync-pwd

阅读(1430) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~