Linux运维管理实际操作中,文件的备份,对每个系统管理者与电脑使用者来说都很重要,常见的方式,将文件传送至另一台电脑或者存储做备份。实际应用中,为了数据文件的安全性,需要实时备份服务器上的文件数据,本文将简述用RsyncInotify来实现文件的实时同步。

利用rsync和inotify实现文件的实时同步

图片1.jpg (22.84 KB, 下载次数: 0)

下载附件  保存到相册

2012-12-4 17:45 上传

实验目的:将192.168.110.12/software/test 目录的文件同步复制到192.168.110.14上的 /software/test 目录中。
OScentos 6.2 64bit
主服务器配置(安装rsyncinotify
Rsync安装
# tar zxvf rsync-3.0.9.tar.gz
# cd rsync-3.0.9
# ./configure –prefix=/usr/local/rsync
# make
# make install
建立密码认证文件
# echo “rsync110.12” > /usr/local/rsync/rsyncd.pas
# chmod 600  /usr/local/rsync/rsyncd.pas
Inotify安装
# tar zxvf inotify-tools-3.14.tar.gz
# cd inotify-tools-3.14
# ./configure –prefix=/usr/local/inotify
# make
# make install
创建启动脚本
# vim /usr/local/inotify/rsync.sh
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#!/bin/sh
src=/software/test/

des=rsync@192.168.110.14::test
/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
        do
                /usr/local/rsync/bin/rsync -avz –delete –progress –password-file=/usr/local/rsync/rsyncd.pas ${src} ${des}
                echo "${files} was rsynced" >> /var/log/rsync.log
                #echo "——————————————————————" >> /var/log/rsync.log
        done
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# chmod + x /usr/local/inotify/rsync.sh
启动
/usr/local/inotify/rsync.sh &
放到系统启动项中,随系统自动启动:
# echo “/usr/local/inotify/rsync.sh &” >> /etc/rc.d/rc.local
备份服务器的配置
Rsync安装
Rsync安装
# tar zxvf rsync-3.0.9.tar.gz
# cd rsync-3.0.9
# ./configure –prefix=/usr/local/rsync
# make
# make install
建立密码认证文件
# echo “rsync:rsync110.12” > /usr/local/rsync/rsyncd.pas
# chmod 600  /usr/local/rsync/rsyncd.pas
建立配置文件
# vim /usr/local/rsync/rsyncd.conf
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
uid = root
gid = root
use chroot = no
max connections = 0
strict modes = yes
timeout = 300
post 873
address = 192.168.110.14
[test]
comment = This is test backup
path = /software/test
ignore errors
read only = no
list = no
auth users = rsync
secrets file = /usr/local/rsync/rsyncd.pas
hosts allow = 192.168.110.12
hosts deny = 0.0.0.0/0
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
启动:
/usr/local/rsync/bin/rsync –daemon –config=/usr/local/rsync/rsyncd.conf
放到系统启动项中,随系统自动启动:
# echo “/usr/local/rsync/bin/rsync –daemon –config=/usr/local/rsync/rsyncd.conf
” >> /etc/rc.d/rc.local
测试:

发表评论

电子邮件地址不会被公开。 必填项已用*标注