運(yùn)行一次就能夠把gitolite服務(wù)器上的倉(cāng)庫(kù)備份到本地. 第一次運(yùn)行會(huì)創(chuàng)建遠(yuǎn)程倉(cāng)庫(kù)的本地鏡像, 以后每次運(yùn)行會(huì)把本地鏡像更新.
其他的git server貌似不會(huì)在 ssh git@xxx 的時(shí)候返回repo列表, 所以只能手動(dòng)備份.
#!/bin/sh server=serv_addr
root_dir=`pwd`
echo "whill back in dir: ${root_dir}"
ssh "git@${server}" | awk '{print $1$2,$3}' | grep "^RW" | awk '{print $2}' | while read line do
echo " "
echo "-------------------------------------"
if [ ! -d "${root_dir}/${line}.git" ]; then
echo "repo not init on local, init it ..."
mkdir -p "${root_dir}/${line}.git"
cd "${root_dir}/${line}.git"
cd ..
git clone --mirror "git@${server}:${line}.git"
else
echo "repo already init on local, update it ..."
cd "${root_dir}/${line}.git"
git remote update
git gc
fi done