前文我展示了一個關於Debian系統配置的指令碼,而新裝電腦除了配置之外還有一個問題就是……資源的遷移!(對於一般的資源可以使用scp拷貝,當然在區域網路內scp的速度相當可觀,但是對於git倉庫這樣的特殊資源,直接使用scp可能會影響git倉庫的使用哦!)
我個人的習慣時將所有的git倉庫都放在一個叫做repository的目錄下。如果通過一個個檢查該目錄下dirs/.git/config下的地址,然後一條條git clone 來在另一台機器上重建倉庫目錄顯得有點太不專業了,所以我寫了個非常簡單的指令碼(my_repository.sh)讀取倉庫中的地址,並把所有地址都追加到一個檔案中,然後使用另外一個指令碼(clone.sh)對這個檔案中所有的地址進行git clone ,很簡單。
首先,看一下搜集git倉庫地址的shell指令碼:
#!/bin/bash
# (C) 2014 Yunlong Zhou <reaper888@yeah.net>
# Under licence GPL
# File : my_repository.sh
# Introduction:
# This script is using for collect all the git address to a file -- repository_file
# Useage :
# 1. cd repository -- cd to the dir that you store all the git repository
# 2. chmox +x my_repository.sh -- give the script a execute permission
# 3. ./my_repository.sh
# for delete old temp file ,if there is !
if [ -f all_dir -a -f repository_file ]; then
echo "Now delete old temp file"
rm all_dir repository_file 2> /dev/null
fi
# read all the items under this dir to the file all_dir
ls -l | awk '{print $9}' > all_dir
# deal with every git repository dir and collect the url then store to file repository_file
while read FILE_NAME
do
if [ $FILE_NAME != " " -a -d $FILE_NAME -a -s $FILE_NAME ];then
echo "Now dealing the "$FILE_NAME
if [ -d $FILE_NAME/.git ]; then
grep -e "url" $FILE_NAME/.git/config | cut -d "=" -f2 | cut -d " " -f2 >>repository_file
fi
fi
done < all_dir
# remove temp file and give a Hint !
rm all_dir
if [ $? == 0 ]; then
echo "Ok,all the url of your repository have been send to file -- repository_file"
fi
現在,所有倉庫目錄下的git倉庫地址已經被添加到repository_file檔案中,如:
bkjia.com@zhouyl:~/repository$ cat repository_file
git://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git
git://gitorious.org/tinylab/pleac-shell.git
git://git.kernel.org/pub/scm/linux/kernel/git/clrkwllms/rt-tests.git
...
這裡省略了十幾個個人倉庫
現在我們可以使用scp將repository_file檔案以及對下面的這個指令碼拷貝到新安裝的電腦上(scp repository_file clone.sh bkjia.com@192.168.2.110:/tmp/),然後直接運行clone.sh(./clone.sh)即可!
#!/bin/bash
# (C) 2014 Yunlong Zhou <reaper888@yeah.net>
# Under licence GPL
# File : clone.sh
# Introduction:
# This script is using for git clone every item in repository_file
# Useage :
# 1. ./clone.sh
if [ ! -f repository_file ]; then
echo "There is no repository_file ,we will exit"
exit
fi
while read READLINE
do
echo "Now we will clone $READLINE"
git clone $READLINE
done < repository_file
rm repository_file
Git 的詳細介紹:請點這裡
Git 的:請點這裡
推薦閱讀:
Fedora通過Http Proxy下載Git
在Ubuntu Server上安裝Git
伺服器端Git倉庫的建立(Ubuntu)
Linux下Git簡單使用教程(以Android為例)
Git權威指南 PDF高清中文版