git备份代码

git备份代码

仓库备份位置: /huawei-bak

vim /huawei-bak/huawei-bak.sh

#!/bin/bash
#项目克隆下来后将其注释即可
PROJECT="
[email protected]:xxxx.git
[email protected]:xxxx.git
[email protected]:xxxx.git
[email protected]:xxxx.git
[email protected]: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备份代码_第1张图片

 

posted on 2019-05-28 10:41  smile-you-me 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/smlile-you-me/p/10935747.html

你可能感兴趣的:(git备份代码)