zl程序教程

您现在的位置是:首页 >  系统

当前栏目

linux shell脚本分享:备份gitlab代码仓库,存在则pull,不存在clone

Linux备份shell代码 分享 脚本 存在 仓库
2023-09-14 09:01:51 时间

脚本中用到的二进制文件get-dmcca-repos给予golang实现 目的是将所有git仓库地址写入到如下文件gitlab-url.txt 代码见我的另外一篇博客:

https://blog.csdn.net/a772304419/article/details/125525733?spm=1001.2014.3001.5501

#!/bin/bash

# set -e

cat > ~/.netrc <<-EOF
machine git.xxxxx.com
login git用户名
password git密码
EOF

git_clone() {
  git clone $1
}

git_pull(){
  if test -d $1
  then
    # 进行pull操作
    cd $1 && git pull && cd ..
  fi
}

main(){
  # golang实现 将所有git仓库写入到如下文件 代码见我的另外一篇博客:
  # https://blog.csdn.net/a772304419/article/details/125525733?spm=1001.2014.3001.5501
  ./get-dmcca-repos
  for line in $(<gitlab-url.txt)
  do
    tmp=`echo ${line##*/}`
    project=`echo ${tmp%.git*}`
    if test -e $project
    then
      git_pull $project
    else
      git_clone $line
    fi
  done
  rm -f gitlab-url.txt
}

main