数据镜像备份工具rsync
rsync可以用來實現數據本地鏡像和遠程備份。
1,可以鏡像保存整個目錄和文件。
2,可以增量同步數據,文件傳輸率高。
3,可以保持原文件的權限,時間等屬性。
4,可以加密傳輸數據。
5,可以使用rcp、ssh等方式來傳輸文件。
6,支持匿名傳輸。
很多操作系統默認都已經安裝rsync服務,如果沒有安裝可以下載安裝。
下載wget? http://rsync.samba.org/
安裝:
#tar zxvf rsync-3.0.4.tar.gz
#cd rsync-3.0.4
#make
#make install
利用rsync可以實現遠程容災備份。
如:A、B兩個linux系統,A系統作為網站服務器,B系統作為A的遠程容災備份機。因此需要A、B兩個都安裝有rsync軟件,同時A系統作為服務端,B系統作為客戶端。在A系統上運行rsync守護進程,在B系統上通過crontab來定時備份A系統的數據。
在A系統上配置:
# vim? /etc/rsyncd.conf
編輯添加內容:
uid = nobody
gid = nobody
use chroot = no
max connections = 10
strict modes = yes
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsync.log
?
[ixdba]
path = /webdata
comment = ixdba file
ignore errors
read only = no
hosts allow = *
hosts deny = 192.168.1.100
list = false
uid = root
gid = root
auth users = backup
secrets file = /etc/server.pass
其中,/etc/server.pass中添加如下:
#cat /etc/server.pass
backup:ixdba123
#chmod 600 /etc/server.pass
?在A系統上啟動rsync進程
#/usr/local/bin/rsync? --daemon
#ps -ef | grep rsync
root? 20345? 1? 0?? 15:37? ??? 00:00:00? /usr/local/bin/rsync? --daemon
在B系統上配置rsync
為了使同步過程中不用輸入密碼,在B系統上創建一個secrets file ,此文件內容為A 系統rsyncd.conf文件中“auth users” 選項指定用戶的密碼。
#/usr/local/bin/rsync? -vzrtopg? --delete? --progress --exclude "*access*" --exculde? "debug*"? backup@192.168.1.100::ixdba?? /ixdba.net?? --password-file=/etc/server.pass
#cat /etc/server.pass
ixdba123
#chmod? 600 /etc/server.pass
設置定時備份策略
觸發同步知道方式有很多,可以將指令放到crontab來執行。自動完成數據備份。比如:
crontab -e
10 1 * * *? /usr/local/bin/rsync? -vzrtopg? --delete? --progress --exclude "*access*" --exculde? "debug*"? backup@192.168.1.100::ixdba?? /ixdba.net?? --password-file=/etc/server.pass
就可以實現遠程容災備份。
但是通過這樣的方法有個問題,就是rsync通過crontab來觸發執行,但是在兩次觸發同步操作的時間間隔內,服務器和客戶端數據肯能出現不一致。如果在這個時間間隔出現問題,那就意味著數據丟失。那么就需要另外的一個工具來實現0丟失,這就是inotify
需要rsync + inotify來實現數據實時備份。
inotify從linux2.6.13版本開始支持。它是一個文件系統監控工具,通過它可以監控文件添加、刪除、修改、移動等操作事件。隨時隨地實時監控數據的變化,并觸發rsync來實時同步數據。
#uname -r
2.6.18-194.el5PAE
# ll? /proc/sys/fs/inotify/
總計 0
-rw-r--r-- 1 root root 0 04-18 15:32 max_queued_events
-rw-r--r-- 1 root root 0 04-18 15:32 max_user_instances
-rw-r--r-- 1 root root 0 04-18 15:32 max_user_watches
有以上3項輸出表示系統默認支持inotify,可以開始安裝inotify-tools。
wget? http://inotify-tools.sourceforge.net
# tar zxvf? inotify-tools-3.14.tar.gz
#cd? inotify-tools-3.14
#./configure
#make
#make install
#ll? /usr/local/bin/inotifywa*
-rwxr-xr-x 1 root? root? 37264? 04-14? 12:30 /usr/local/bin/inotifywait
-rwxr-xr-x 1 root? root? 37264? 04-14? 12:30 /usr/local/bin/inotifywatch
... ...
?
?
?
?
轉載于:https://blog.51cto.com/haierxing/837785
總結
以上是生活随笔為你收集整理的数据镜像备份工具rsync的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 孕妇梦到生了两个女儿是什么意思
- 下一篇: 用户如何有效地利用数据字典(转)