[心得] Snapshot型 增量備份 backup
最近一直在煩惱linux 的備份方案
由於備份起來 要能夠支援即時備援 所以弄起來特別煩惱
由於公司是使用NFS做檔案集中管理 為了怕NFS server 檔案故障
所以需要做每日 每天 甚至每小時的備份 不能壓縮起來是因為怕NFS SERVER掛點了以後
要能夠馬上頂替著用
下面是CEO幫我寫 然後我在改寫一部份的script 與大家參考
#!/bin/csh -f
## this script is written by David
set DES = "/db/snapshot"
set DATE = `date +%H%M_%m%d%y`
set domain = `domainname`
set SNAP = "weekily.0/daily"
if ($#argv != 0) then
echo " "
if ( "$1" == "-h" ) then
echo " working in Hourily mode"
set SNAP = "hourily"
endif
if ( "$1" == "-d" ) then
echo " working in Daily mode"
set SNAP = "weekily.0/daily"
endif
if ( "$1" == "-w" ) then
echo " working in Weekily mode"
set SNAP = "weekily"
endif
endif
### test dir
if ( $user != "root" ) then
echo " ERROR: The Task must run by root "
exit
endif
if ( ! -d $DES ) then
echo " ERROR: Datebase cannot be seen, check snapshot dir "
exit
endif
if (! -f /stor13/In_d64 ) then
echo " ERROR: Datebase lost, check stor13 "
exit
endif
if (! -f /users/In_rh64 ) then
echo " ERROR: Datebase lost, check users"
exit
endif
if ( -d $DES/${SNAP}.5 ) then
echo " delete the oldest version of snapshot "
rm -rf $DES/${SNAP}.5 ## delete 5
echo " move the snapshot dir name + 1 "
endif
if ( -d $DES/${SNAP}.4 ) then
mv $DES/${SNAP}.4 $DES/${SNAP}.5 ## 4 --> 5
endif
if ( -d $DES/${SNAP}.3 ) then
mv $DES/${SNAP}.3 $DES/${SNAP}.4 ## 3 --> 4
endif
if ( -d $DES/${SNAP}.2 ) then
mv $DES/${SNAP}.2 $DES/${SNAP}.3 ## 2 --> 3
endif
if ( -d $DES/${SNAP}.1 ) then
mv $DES/${SNAP}.1 $DES/${SNAP}.2 ## 1 --> 2
endif
if ( -d $DES/${SNAP}.0 ) then
mv $DES/${SNAP}.0 $DES/${SNAP}.1 ## 0 --> 1
endif
## make hard link from snapshot DIR 1 --> 0
echo "make hard link from $DES/${SNAP}.1/to $DES/${SNAP}.0/"
cp -al $DES/${SNAP}.1/. $DES/${SNAP}.0/
echo " clear sync log for all mode"
rm -rf $DES/${SNAP}.0/snapshot_*
################################################
## now , start the backup
################################################
## in all mode , sync the users and ccase/ccase.tw
set task = "rsync -av --delete /users/ $DES/${SNAP}.0/users"
echo $task
$task
echo " " >! $DES/${SNAP}.0/snapshot_users_${DATE}
## in domain rdwic , sync the ccase
if ( $domain == "rdwic" ) then
set task = "rsync -av --delete /ccase/ $DES/${SNAP}.0/ccase"
echo $task
$task
echo " " >! $DES/${SNAP}.0/snapshot_ccase_${DATE}
endif
## in domain twrdwic , sync the ccase.tw
if ( $domain == "twrdwic" ) then
set task = "rsync -av --delete /ccase.tw/ $DES/${SNAP}.0/ccase.tw"
echo $task
$task
echo " " >! $DES/${SNAP}.0/snapshot_ccase.tw_${DATE}
endif
### in daily moe sync the rf mx
if ( $SNAP == "weekily.0/daily" ) then
set task = "rsync -av /mx/ $DES/${SNAP}.0/mx"
echo $task
$task
echo " " >! $DES/${SNAP}.0/snapshot_mx_${DATE}
endif
## in Weekily Mode , sync the stor13
if ( $SNAP == "weekily" ) then
set task = "rsync -av --delete /stor13/ $DES/${SNAP}.0/stor13"
echo $task
$task
echo " " >! $DES/${SNAP}.0/snapshot_stor13_${DATE}
endif
目前的缺點是
1. 在 hourily daily weekily 都會保留六份備份 weekily太多了
2. hourily 與 daily 的備份會事先取前一天的備分做一份所有檔案的Hard link
再與伺服器資料作更新 這樣子的作法是為了節省磁碟空間
假設 users 總共有 10G 那snapshot 下來的
hourily.0/users 與 hourily.1/users 各自有10G 但是卻是指到同一份inode
daily 也是
但是 .... 要是inode掛掉的話 那備份全毀 所以
weekily的備份是不可以用hard link
可以先將上個星期的資料另外本機自己 sync一份到weekily.0
然後再與server 做RSYNC
其實這個用rsync的參數究可以辦到了 但是我試驗了很多事 都做不起來....
3. rsync的過程中是會print出來 希望用tee command同步抄寫到
snapshot_stor13_${DATE} 檔案裡面 這樣子就可以清楚知道SYNC了多少資料量
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 60.248.150.178
推
05/17 00:50, , 1F
05/17 00:50, 1F
Linux 近期熱門文章
23
129
PTT數位生活區 即時熱門文章