仓库备份位置: /huawei-bak

vim /huawei-bak/huawei-bak.sh

#!/bin/bash
#项目克隆下来后将其注释即可
PROJECT="
git@codehub.devcloud.huaweicloud.com:xxxx.git
git@codehub.devcloud.huaweicloud.com:xxxx.git
git@codehub.devcloud.huaweicloud.com:xxxx.git
git@codehub.devcloud.huaweicloud.com:xxxx.git
git@codehub.devcloud.huaweicloud.com:xxxx.git
"
for i in $PROJECT
do
  git clone $PROJECT
done
#以下为备份代码
cd /huawei-bak
ls -l |grep ^d|awk -F ' ' '{print $9}'|grep -v bak$ >> 1.txt
cat 1.txt | while read Dir
do
    cd $Dir
    /usr/local/git/bin/git fetch origin      #更新本地的远程分支
    /usr/local/git/bin/git diff --stat master origin/master | grep "changed"    #统计文件的改动,如果有变动则往下执行,反之不执行
    if [ $? -eq 0 ];then
      echo "--------------------------------------------">>../huawei-bak.log
      echo "项目名称: $Dir">>../huawei-bak.log
      echo "同步时间: `date +'%F %T'`">>../huawei-bak.log
      /usr/local/git/bin/git pull >>../huawei-bak.log
      /usr/local/git/bin/git fetch --all      #取远程所有分支到本地(是所有)
    fi
    cd ../
done
rm -rf 1.txt

git备份代码

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-01-20
  • 2022-01-07
  • 2021-11-22
  • 2021-12-19
  • 2022-01-06
  • 2021-06-28
猜你喜欢
  • 2021-08-14
  • 2022-01-30
  • 2022-12-23
  • 2021-07-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案