
rsync
原文鏈接:https://blog.csdn.net/hkyw000/article/details/51508204
備份源10.16.77.93
備份端10.16.77.95
原理:利用inotify監(jiān)控mysql數(shù)據(jù)庫數(shù)據(jù)目錄:/usr/local/mysql/data
一.備份端服務的配置
1)確認rsync是否安裝,大多數(shù)linux發(fā)行版默認安裝rsync
rpm -q rsync
2)手動創(chuàng)建rsync的配置文件:/etc/rsyncd.conf
uid=root
gid=root
use chroot = no
max connections = 10
strict modes = yes
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
log file = /var/log/rsyncd.log
[mysqldata]
path = /data/mysqldata
comment = mysql data
ignore errors
read only = no
write only = no
hosts allow = 10.16.77.93
list = false
auth users = rsync_user
secrets file = /etc/rsync.password
3)建立rsync用戶名和密碼文件,并為/etc/rsync.password授權為600
echo "rsync_user:rsync_user_pwd" > /etc/rsync.password
chmod -R 600 /etc/rsync.password
4)啟動rsync服務
rsync --daemon
至此備份端服務配置完成
二.備份源配置
1)設置rsync客戶端密碼文件,將密碼文件的權限設置成600
客戶端只需要設置rsync同步密碼即可,不用重設用戶名
echo "rsync_user_pwd" > /etc/rsync.password
chmod -R 600 /etc/rsync.password
2)安裝inotify
yum install inotify-tools -y
3)編寫運行監(jiān)控腳本。為了保證/usr/local/mysql/data目錄自動同步,安裝完成inotify后,寫一個inotify腳本。
#!/bin/bash
ip=10.16.77.95
src=/data/mysqldata_src/
dst=mysqldata
user=rsync_user
/usr/local/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f' -e modify,delete,create,attrib ${src} \
| while read file
do
rsync -vzrtopg --delete --progress $src $user@$ip::$dst --password-file=/etc/rsync.password > /dev/null && echo "$src was rsyncd"
done