原!!自动备份 发布脚本

#!/bin/bash
# used to back up and publish project

#upload war name ,such as "open_devportal" or "open_mssportal" or "api"
UPLOAD_PROJECT="api"

#deploy war name ,such as "portal" or "manager" or "api"
PROJECT="api"

#platform=xxxxdate=$(date "+%Y%m%d")

echo ""
echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
echo "@!!!This script will restart Tomcat service, the live network will be impacted!!!@"
echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
echo ""
read -n1 -p  "#The {$PROJECT} will be republished,pls make sure continue or not? [Y/N]" result

case $result in
Y | y)

    echo ""
    echo ""
    echo "-----Backup the war and config file-----"
    cp /apprun/tomcat/webapps/"${PROJECT}".war  /apprun/warbak/"${PROJECT}"_"${date}"_bak.war
    sleep 2
    cp -r /apprun/kfpt_conf/beijing/ /apprun/kfpt_conf_bak/beijing_"${date}"_bak

    sleep 2
    echo ""
    echo "ls /apprun/warbak | grep ${date}"
    for i in `ls  /apprun/warbak | grep ${date}`;do echo $i;done
    sleep 2
    echo ""

    echo "ls /apprun/kfpt_conf_bak | grep ${date}"
    for i in `ls  /apprun/kfpt_conf_bak | grep ${date}`;do echo $i;done
    sleep 2
    echo ""

    echo ""
    read -n1 -p  "#Pls make sure the war and config file is backup success ? [Y/N]" backupResult
    case $backupResult in
    Y | y)

            echo ""
            echo "-----Stop Tomcat Service, Waiting about 15s-----"
            sudo systemctl stop tomcat
            sleep 15
            check1=`systemctl status tomcat | grep Active:`
            echo ""
            echo "---Pls Check Tomcat status---"
            echo "$check1"
            sleep 2
            echo ""

            read -n1 -p  "#Pls make sure the Tomcat is stopped? [Y/N]" tomcatresult
            case $tomcatresult in
            Y | y)    
                
                echo ""
                echo "-----Delete Old jar and config file-----"
                rm -rf /apprun/tomcat/webapps/"${PROJECT}"*
                echo ""
                echo "ls  /apprun/tomcat/webapps "
                for i in `ls  /apprun/tomcat/webapps`;do echo $i;done
                sleep 2
                echo ""

                rm -rf /apprun/kfpt_conf/beijing*
                echo ""
                echo "ls  /apprun/kfpt_conf "
                for i in `ls  /apprun/kfpt_conf`;do echo $i;done
                sleep 2
                echo ""

                
                echo "-----Copy the war(will change to correct war name) and config file to dedicate path-----"
                cp /home/apprun/"${UPLOAD_PROJECT}".war  /apprun/tomcat/webapps/"${PROJECT}".war
                sleep 1
                cp /home/apprun/beijing.zip /apprun/kfpt_conf
                sleep 1
                cd /apprun/kfpt_conf
                unzip -qo beijing.zip
                sleep 2
                rm -rf beijing.zip

                echo ""
                echo "ls /apprun/tomcat/webapps | grep ${PROJECT}"
                for i in `ls  /apprun/tomcat/webapps | grep "${PROJECT}".war`;do echo $i;done
                sleep 2
                echo ""
                
                echo ""
                echo "ls /apprun/kfpt_conf"
                for i in `ls  /apprun/kfpt_conf`;do echo $i;done
                sleep 2
                echo ""


                echo "-----Start Tomcat Service, wating about 20s-----"
                sudo systemctl start tomcat
                sleep 20
                echo "systemctl status tomcat | grep Active:"
                check2=`systemctl status tomcat | grep Active:`

                echo ""
                echo "$check2"
                echo ""
                echo "Pls check the Tomcat status"
                sleep 2
                echo "The script completed, pls check the logs by yourself"
                ;;    
            N | n)
            echo "Pls check Tomcat status and re-try script";;
            esac
            exit 0                    
    ;;
    N | n)
    echo ""
    echo "Pls check the backup result ";;
    esac
    exit 0
;;

N | n)
    echo ""
        echo "Ok,Good Bye";;

*)
    echo ""
        echo "pls input Y or N";;
esac
exit 0

猜你喜欢

转载自www.cnblogs.com/wuyun-blog/p/9957665.html