这篇文章主要介绍“如何编写一键备份gitolite服务器的Shell脚本”,在日常操作中,相信很多人在如何编写一键备份gitolite服务器的Shell脚本问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”如何编写一键备份gitolite服务器的Shell脚本”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
运行一次就能够把gitolite服务器上的仓库备份到本地. 第一次运行会创建远程仓库的本地镜像, 以后每次运行会把本地镜像更新.
本程序只支持 ssh方式
其他的git server貌似不会在 ssh git@xxx 的时候返回repo列表, 所以只能手动备份.
#!/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
到此,关于“如何编写一键备份gitolite服务器的Shell脚本”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注天达云网站,小编会继续努力为大家带来更多实用的文章!