由於git服務器是自己用普通pc來架設的,雖然對存儲做了軟陣列的存儲冗餘處理,增強了安全性,但還是會有存儲損壞數據丟失的風險。爲了增加安全性,在另外一臺最爲編譯服務器上,定時對倉庫進行備份。
1. 備份的機器:
a) 備份服務器用的是ubuntu系統,地址172.28.1.132,開了ssh服務。
b) 在用於備份的用戶目錄下(假設用戶爲back,密碼爲123456),創建一個用於備份的目錄,如gitback。
c) 在備份目錄gitback下創建一個腳本gitback.sh:
#!/bin/sh
giturl="http://172.28.12.215/chenzewei/"
reslist="besopensource.gitbes2000.git bes2000otaboot.git screenrecorddemo.git StudentVR.gitStudentVR -.git launcherscence.git testdir.gitrk3399-kernel.git gvr-android-sdk.git"
gitbackdir=$PWD
for resin ${reslist};
do
cd ${res}
git fetch
cd $gitbackdir
git clone --mirror ${giturl}${res}
done
2. Git服務器:
a) 增加一個定時任務
執行命令crontab –e
a) 在出現的vi編輯界面最後加入一行:
0 4 * * * sshpass -p 123456 ssh [email protected] "cdgitback && sh gitback.sh"
保存,這個任務會在每天4點執行。
老闆再也不用擔心數據丟失了:)