rsync+inotifyリソースサーバ間のインクリメンタルバックアップを実現

3031 ワード

テスト環境:
リソースサーバ(プライマリサーバ):192.168.4.163
バックアップサーバ(クライアント):192.168.4.154
リソースディレクトリの同期:/etc/test
実験目的:リソースサーバの同期ディレクトリ下のファイルが変化した場合,バックアップサーバの同期ディレクトリが更新され,リソースサーバに準じて他のクライアントを同期する.
 
一、資源サーバーの構成
1、rsyncをインストールし、インストールパスは:/usr/local/rsync
[root@nginx ~]# cd /usr/src/ 
[root@nginx src]# wget http://rsync.samba.org/ftp/rsync/src/rsync-3.0.9.tar.gz 
[root@nginx src]# tar zxvfrsync-3.0.9.tar.gz 
[root@nginx src]# cd rsync-3.0.9 
[root@nginx rsync-3.0.9]# ./configure--prefix=/usr/local/rsync 
[root@nginx rsync-3.0.9]# make 
[root@nginx rsync-3.0.9]# make install

 
2、インストールinotify、インストールパス/usr/local/inotify
[root@nginx rsync]# cd /usr/src/ 
[root@nginx src]# wget http://cloud.github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz 
[root@nginx src]# tar zxvf inotify-tools-3.14.tar.gz 
[root@nginx src]# cd inotify-tools-3.14 
[root@nginx inotify-tools-3.14]# ./configure --prefix=/usr/local/inotify 
[root@nginx inotify-tools-3.14]# make 
[root@nginx inotify-tools-3.14]# make install 

 
3、自動同期スクリプトの作成autorsync.sh
#!/bin/bash
host=192.168.4.154
src=/etc/test/
des=backup
/usr/local/inotify/bin/inotifywait -mrq --timefmt '%d/%m/%y/%H:%M' --format '%T %w %f' -e modify,delete,create,attrib $src \
| while read files
do
/usr/local/rsync/bin/rsync -vzrtopg --delete --progress $src $host::$des >>/var/log/rsyncprogress.log2>&1 &&
echo "${files} was rsynced">>/var/log/rsync.log 2>&1
done

 
    764権限の付与
#chmod +x rsync.sh

 
5、このスクリプトを実行する
 #sh /tmp/rsync.sh &

 
二、バックアップサーバーの構成
1、rsyncをインストールし、インストールパスは:/usr/local/rsync
[root@nginx ~]# cd /usr/src/ 
[root@nginx src]# wget http://rsync.samba.org/ftp/rsync/src/rsync-3.0.9.tar.gz 
[root@nginx src]# tar zxvfrsync-3.0.9.tar.gz 
[root@nginx src]# cd rsync-3.0.9 
[root@nginx rsync-3.0.9]# ./configure--prefix=/usr/local/rsync 
[root@nginx rsync-3.0.9]# make 
[root@nginx rsync-3.0.9]# make install

 
2、構成/etc/rsyncd.conf
[backup]
uid = root
gid = root
path = /data/backup/
hosts allow = 192.168.4.163
read only = no

 
3、rsyncを起動する
# /usr/local/rsync/bin/rsync --daemon--config=/etc/rsyncd.conf

 
    rsyncスクリプトを起動起動項目に追加できます
# echo "/usr/local/rsync/bin/rsync--daemon --config=/etc/rsyncd.conf" >> /etc/rc.local

 
 
参考記事:http://blog.csdn.net/smile0198/article/details/9704239