rsync和inotify文件实时备份配置

测试前,先安装好所需要的软件包。测试中,进行了wxbak、nxbak的双向同步测试。

这里仅列出单向测试记录。

nxbak上安装xinetd服务,充当rsync服务端;

wxbak上安装inotify-tools,可以实时监测wxbak机上指定文件夹的变化,并触发相应的事件,激活rsync以实时同步文件系统的变化到nxbak机上。

推荐阅读:

rsync同步完整配置

利用rsync工具进行同步Windows和Linux机器之间的文件

具体如下:

rsync_arch

服务端 1.开启rsync服务

编辑 /etc/xinetd.d/rsync文件

[root@nxbak]# cat /etc/xinetd.d/rsync # default: off # description: The rsync server is a good addition to an ftp server, as it \ # allows crc checksumming etc. service rsync { disable = no socket_type = stream wait = no user = root server = /usr/bin/rsync server_args = --daemon log_on_failure += USERID }

将disable = yes 改为 disable = no

2.配置rsync服务

创建/etc/rsyncd.conf

[root@nxbak]# vim /etc/rsyncd.conf #2012-06-11 dylanninin@gmail.com settings for rsync server #rsync backup side settings uid = root gid = root use chroot = no max connections = 200 timeout = 600 strict modes = yes port = 873 pid file = /var/run/rsyncd.pid lock file = /var/run/rsyncd.lock log file = /var/log/rsyncd.log #backup fs settings [nxbak] path = /data/nxbak ignore errors comment = rsync rman backup auth users=Oracle uid = root gid = root secrets file = /etc/rsync_server.pwd read only = no list = no hosts allow = 192.168.1.118 hosts deny = 0.0.0.0/32 3.密码文件

创建/etc/rsync_server.pwd

[root@nxbak]# vim /etc/rsync_server.pwd oracle:security

修改权限

[root@nxbak]# chmod 600 /etc/rsync_server.pwd [root@nxbak]# ll /etc/rsync_server.pwd -rw------- 1 root root 17 Jun 12 11:43 /etc/rsync_server.pwd 客户端 1.密码文件 [root@wxbak ]# vim /etc/rsync_client.pwd security

修改权限

[root@wxbak]# chmod 600 /etc/rsync_client.pwd [root@wxbak]# ll /etc/rsync_client.pwd -rw------- 1 root root 10 Jun 12 11:42 /etc/rsync_client.pwd 2.rsync+inotify脚本 [root@wxbak ]# cat /apps/scripts/rsync.sh #!/bin/sh #abstract: #rsync auto sync script #2012-06-11 dylanninin@gmail.com first_release #variables current_date=$(date +%Y%m%d_%H%M%S) rman_path=/apps/rmanbak log_file=/var/log/rsync.log #rsync rsync_server=192.168.1.119 rsync_user=oracle rsync_pwd=/etc/rsync_client.pwd rsync_module=nxbak #rsync_client password check if [ ! -e ${rsync_pwd} ]; then echo -e "rsync client password file ${rsync_pwd} does not exist!" exit 0 fi #inotify function inotify_fun(){ /usr/bin/inotifywait -mrq --timefmt '%d/%m/%y-%H:%M' --format '%T%w%f' \ -e modify,delete,create,move ${rman_path} | while read file do /usr/bin/rsync -vrtzopg --progress --delete --password-file=${rsync_pwd} ${rman_path} ${rsync_user}@${rsync_server}::${rsync_module} done } #inotify inotify_fun >> ${log_file} 2>&1 &

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/b89c00421ecc9dffe76077f26576fc31.html