rsync從linux到linux的文件同步備份
一、環(huán)境
需要備份文件的服務(wù)器(服務(wù)器端):192.168.1.201 (RHEL 5)
接收備份文件的服務(wù)器(客戶端):192.168.1.202 (CENTOS 5)
二、安裝配置
1.服務(wù)器端的配置
A、采用系統(tǒng)默認(rèn)安裝的rsync 編輯/etc/rsyncd.conf文件,如果沒有則新建一個(gè)。
vi /etc/rsyncd.conf
#[globale]
strict modes= yes #check passwd file
port= 873 #default port
logfile= /var/log/rsyncd.log
pidfile= /var/run/rsyncd.pid
max connections= 4
#[modules]
[testlink] #備份模塊
uid= root
gid= root
path= /usr/local/apache/htdocs/testlink/upload_area #要備份的目錄
read only= no
host allow= *
auth users= wwyhy
secrets file= /etc/rsyncd.scrt
[bugfree] #備份模塊
uid= root
gid= root
path= /usr/local/apache/htdocs/bugfree/BugFile #要備份的目錄
read only= no
host allow= *
auth users= wwyhy
secrets file= /etc/rsyncd.scrt
[redmine] #備份模塊
uid= root
gid= root
path= /usr/local/redmine-0.8.1/files #要備份的目錄
read only= no
host allow= *
auth users= wwyhy
secrets file= /etc/rsyncd.scrt
B、 添加一個(gè)密碼文件
vi /etc/rsyncd.scrt
內(nèi)容如下:
wwyhy:123456 #(自己設(shè)置)
C、改變權(quán)限為600
chmod 600 /etc/rsyncd.scrt
D、啟動(dòng)服務(wù)(如開有防火墻請(qǐng)?jiān)试S873端口通過(guò))
rsync --daemon --config=/etc/rsyncd.conf &
2.配置客戶端
客戶端我則自己編譯安裝的rsync-3.0.3.tar.gz的
A、安裝:
tar -zxvf rsync-3.0.3.tar.gz
cd rsync-3.0.3
./configure
make
make install
B、添加密碼文件
vi /etc/rsyncd.scrt (沒有就新建)
內(nèi)容如下:
wwyhy:123456 (文件與客戶端文件內(nèi)容一樣)
C、改文件權(quán)限為600
chmod 600 /etc/rsyncd.scrt
三、開始備份
可以在客戶端通過(guò)man rsync指令來(lái)查看備份指令
我們用腳本來(lái)自動(dòng)執(zhí)行備份
列:rsync -avz --password-file=密碼文件路徑 username@需要備份的主機(jī)IP::備份里的模塊名稱
接收備份文件的路徑
在/root建一個(gè)腳本文件
vi backup
添加內(nèi)容如下:
#1.192.168.1.201上的testlink附件備份指令
rsync -avz --password-file=/etc/rsyncd.scrt wwyhy@192.168.1.201::testlink
/home/wangwei/testlink/upload_area
#2.192.168.1.201上的bugfree附件備份指令
rsync -avz --password-file=/etc/rsyncd.scrt wwyhy@192.168.1.201::bugfree
/home/wangwei/bugfree/BugFile
#3.192.168.1.201上的redmine附件備份指令
rsync -avz --password-file=/etc/rsyncd.scrt wwyhy@192.168.1.201::redmine
/home/wangwei/redmine-0.8.1/files
chmod u+x backup
每晚2.30自動(dòng)執(zhí)行
vi /etc/crontab
30 2 * * * root /root/backup
【編輯推薦】