• jenkins调用shell执行数据库升级及备份


    ###this is deploysql.sh###

    #!/bin/bash
    LANG="en_US.UTF-8"
    date=`date +'%Y%m%d_%H%M%S'`
    user=root
    password=yourpassword
    cd /root/SQLtest/
    svn up
    if [ $? = 0 ];then
        get_env=`cat /root/SQLtest/upgrade.sql |grep ^#ENV=|sed 's/#ENV=//g;s/.$//'`
        get_host=`cat /root/SQLtest/upgrade.sql |grep ^#HOST=|sed 's/#HOST=//g;s/.$//'`
        host=${get_host}
      if [ -n "${get_env"}] && [ -n "${get_host}"];then
        echo -e "正在获取 ${get_env} ip:${get_host}需要备份的表... "
        backup_tables=`cat /root/SQLtest/upgrade.sql |grep ^#backup_tables=|sed 's/#backup_tables=//g;s/.$//'`
        OLD_IFS="$IFS"
        IFS=","
        tables=($backup_tables)
        IFS="$OLD_IFS"
        if [ -n "$tables" ];then
          echo -e "您需要备份的表有:${tables[*]} "
          for table in ${tables[@]}
          do
        echo -e "mysqldump -uroot -pdbpasswd ${table%.*} ${table#*.} > ${table%.*}_${table#*.}_${date}.sql "
          done
          if [ $? -eq 0 ]
          then
            echo -e "备份成功! "
            echo -e "正在执行升级SQL... "
            mysql -u$user -p$password -h $host <<EOF
            source /root/SQLtest/upgrade.sql;
    EOF
          else
            echo -e "备份失败! "
          fi
        else        
          echo -e "警告:您没有输入任何需要备份的表!但是升级SQL依然执行... "
          echo -e "正在执行升级SQL... "
          mysql -u$user -p$password -h $host <<EOF
          source /root/SQLtest/upgrade.sql;
    EOF
        fi
      else
        echo -e "ENV or HOST not found! "
      fi
    else
        echo -e "svn update failed! "
    fi


    #this is testENV.sql#

    ################################声明主机(运维维护)##############################################

    #ENV=准生产环境
    #HOST=192.168.1.1.

    ################################END###################################################




    #################################声明需要备份的表,建议对升级有操作的表进行备份,可以为空,即不备份直接升级(开发维护)######################################

    #请在下一行“backup_tables=”后输入需要备份的表,格式:db.table多个之间用“,”分隔

    #backup_tables=mysql.user,mysql.host

    ##################################END##################################################





    ################################提供升级操作SQL(开发维护)############################################
    use mysql;
    show tables;
    ################################END#####################################################

  • 相关阅读:
    2D Polygons( Poygon) CGAL 4.13 -User Manual
    2D Convex Hulls and Extreme Points( Convex Hull Algorithms) CGAL 4.13 -User Manual
    Linear and Quadratic Programming Solver ( Arithmetic and Algebra) CGAL 4.13 -User Manual
    3D Spherical Geometry Kernel( Geometry Kernels) CGAL 4.13 -User Manual
    2D Circular Geometry Kernel ( Geometry Kernels) CGAL 4.13 -User Manual
    MySQL开启日志跟踪
    Cookie&Session
    Web服务器——WSGI
    win10上安装redis
    Ubantu上安装Redis
  • 原文地址:https://www.cnblogs.com/nbuntu/p/5753178.html
Copyright © 2020-2023  润新知