rsync+inotifyでHPリソースを自動的にバックアップする

1.サーバ環境
マスター(master)サーバ:192.168.5.87 inotify
スレーブ(slave)サーバ:192.168.6.88 rsync

2.slaveサーバにrsyncをインストール
um -y install rsync
vim /etc/rsyncd.conf
uid = nginx
gid = nginx
port = 873
host all = 192.168.6.87
use chroot = on
max connections = 4
timeout = yes
[wordpress]
path = /usr/local/nginx/html/wordpress
comment = rsync files
ignore errors
read only = no
list = yes
auth users = rsync
secrets file = /etc/rsync.passwd
vim /etc/rsync.passwd
#ユーザ:パスワード
rsync:rsync

3. master サーバーにinotify-toolsをインストール
wget https://github.com/rvoicilas/inotify-tools/archive/v3.14.tar.gz
tar -zxvf inotify-tools-3.14.tar.gz
cd inotify-tools-3.14
./configure –prefix=/usr/local/inotify
make && make install

vim /etc/rsync.passwd
#パスワード
rsync

4.shellコード
vim inotifyrsync.sh
#!/bin/bash
host=192.168.6.88
src=/usr/local/nginx/html/wordpress/
dst=wordpress
user=rsync
inotifywait=/usr/local/inotify/bin/inotifywait
rsync=/usr/bin/rsync
$inotifywait -mrq –timefmt '%d/%m/%y %H:%M’ –format '%T %w%f’ -e modify,delete,create,attrib $src | while read files
do
$rsync -vzrtopg –delete –progress –password-file=/etc/rsync.passwd $src $user@$host::$dst
echo “${files} was rsynced" >>/tmp/rsync.log 2>&1
done

Nginx

Posted by arkgame