git备份代码

仓库备份位置: /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

 

posted @ 2019-05-28 10:41  Linux大魔王  阅读(758)  评论(0编辑  收藏  举报