hongblue 发表于 2018-7-29 07:21:16

svn+ansible实现自动回滚和代码的备份跟新

  #!/bin/bash
  #function master() {http://blog.chinaunix.net/attachment/201604/13/30234663_14605166168RuO.png
  #git hooks is post-commit
  REPOS="$1"
  REV="$2"
  #文件日志存放位置
  log="/var/log/svn.log"
  #项目update位置
  DIR=/data/backup/svnrepos
  #备份文件目录{上一量级代码}
  backDIR="/data/backup/test"
  #正式服务提供服务位置{新代码}
  webDIR="/data/backup/src"
  zwebDIR="/data/mydate"
  #环境字符
  export LC_ALL=en_US.UTF-8
  export.UTF-8
  CURDATE=`date +%Y-%m-%d`
  echo "code deployed by at $CURDATE,$REPOS,$REV" >> $log
  #代码更新存放目录
  svn update/data/backup/svnrepos/--username hanye --password hanye131
  #匹配文件是否更新完成,是,执行文件的备份,和上次代码文件的备份,和代码的回滚的匹配
  if [$? -eq 0 ]; then
  echo -e "\033[33;31m svn update success\033[0m" >> $log
  cd /data/backup/svnrepos/
  config1=`cat confile| sed -n '1p'`
  config2=`cat confile| sed -n '2p'`
  if [ "$config1" == "master" ]; then
  if [ "$config2" == "online" ]; then
  cp $webDIR/* $backDIR/ -fr
  cp /data/backup/svnrepos/*$webDIR/ -fr
  ansible 192.168.0.171 -m synchronize -a "src=$webDIR/ dest=$zwebDIR"
  elif [ "$config2" == "local" ];then
  echo "two line is local" >> $log
  fi
  elif [ "$config1" == "rollback" ]; then
  cp $backDIR/* $webDIR/ -fr
  ansible 192.168.0.171 -m synchronize -a "src=$backDIR/ dest=$zwebDIR"
  fi
  else
  echo -e "\033[33;33m svn update notsuccess\033[0m">> $log
  fi
  # master 2>&1 | tee $log
  #if [ "`cat $log| grep -E 'error|failed|warning'|grep -v error.jsp|grep -v error.html|grep -v error.htm`" == "" ];then
  # echo "\033[33;31m Congratuations,push success!\033[0m"
  #else
  #   cat$log | grep -E 'error|failed|warning'|grep -v error.jsp|grep -v error.html|grep -v error.htm
  #   echo "\033[31;33m Push failed,please check the error message carefully!\033[0m"
  #fi
页: [1]
查看完整版本: svn+ansible实现自动回滚和代码的备份跟新