脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|shell|

服务器之家 - 脚本之家 - shell - 一键备份gitolite服务器的Shell脚本

一键备份gitolite服务器的Shell脚本

2023-02-20 14:02shell教程网 shell

这篇文章主要介绍了一键备份gitolite服务器的Shell脚本,需要的朋友可以参考下

运行一次就能够把gitolite服务器上的仓库备份到本地. 第一次运行会创建远程仓库的本地镜像, 以后每次运行会把本地镜像更新.

本程序只支持 ssh方式

其他的git server貌似不会在 ssh git@xxx 的时候返回repo列表, 所以只能手动备份.

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/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

延伸 · 阅读

精彩推荐