production 项目回退

  

 

 

 

 

echo "which package to retroversio?:disabled"

#ssh administrator@172.16.20.106 "ssh administrator@172.16.20.106 C:\\Progra~1\\git\\bin\\bash -c /c/scripts/dir-web.sh" > /c/scripts/web.log
ssh administrator@172.16.20.106 'dir /b /o:-d d:\backup' > /c/scripts/web.log
if ! [[ -z "$1" ]];then
    grep "$1" /c/scripts/web.log
else
    echo "select a project above to retrovresio!:disabled"
fi
if [[ "$#" != 2 ]];then
    echo '################################################################################################'
    echo You must select a project! Revaluate your Option,choose again!
    echo '################################################################################################'
    exit 77
fi

aboriginal=$1
project=${aboriginal%--*}
echo '################################################################################################'
echo You are retreating $project
echo '################################################################################################'


alternation=$2
set -e
export LANG=zh_CN.utf8
ml_slb=lb-uf611bih0o3phcwzivxfe
zp_slb=lb-uf6sljbd851v9pgrng6nk

declare -a origin=(
i-uf6hkhn8wpq3hkwyx2wtA172.16.20.106
i-uf611rcwyofcyb0d10z7A172.16.20.107
i-uf60q7yyu6cvfajdp4j8A172.16.20.108
i-uf6hi6q15ypumirnwf5zA172.16.20.63
i-uf6hi6q15ypumirnwf60A172.16.20.64
i-uf6hi6q15ypumirnwf61A172.16.20.65
)

declare -A mapping

function make_dict(){
    for b in ${origin[*]};do
        mapping[${b#*A}]=${b%A*}
    done
}

make_dict

echo mapping key = ${!mapping[*]}
echo mapping value = ${mapping[@]}


# tinker up SLB
function equalizer(){
    /c/windows/modify_ecs_weigth $ml_slb $1 $2  # $1 delegate ecs, $2 delegate weight
    if [[ $? != 0 ]];then
        echo '################################################################################################'
        echo tinker up Catalogue SLB $ml_slb ECS $1 failed
        echo '################################################################################################'
        exit 99
    fi
    /c/windows/modify_ecs_weigth $zp_slb $1 $2
    if [[ $? != 0 ]];then
        echo '################################################################################################'
        echo tinker up ZhiPei SLB $zp_slb ECS $1 failed
        echo '################################################################################################'
        exit 99
    fi

}


# 检查文件传输错误
function estimate(){
    if [[ $1 != 0 ]];then
        echo ********************************************************************************************************************************************************************************************
        echo sychronization failed!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        echo ********************************************************************************************************************************************************************************************
        exit 50
    fi
}


# retreat Major Node 172.16.20.106
function succedent(){
    p=172.16.20.106
    if [[ $alternation != 0 ]];then
        equalizer ${mapping[$p]} 0
        sleep $alternation
    fi

    # 主节点恢复文件
    if [[ $project =~ cjml ]];then
        ssh -o StrictHostKeyChecking=no administrator@172.16.20.106 "C:\\Progra~1\\7-Zip\\7z.exe x -y -oD:\\website\\51cjml.com\\${project} D:\\backup\\${aboriginal}"
    else
        ssh -o StrictHostKeyChecking=no administrator@172.16.20.106 "C:\\Progra~1\\7-Zip\\7z.exe x -y -oD:\\website\\zhipeicloud.com\\${project} D:\\backup\\${aboriginal}"
    fi

    if [[ $alternation != 0 ]];then
        equalizer ${mapping[$p]} 100
    fi
}

succedent


function main(){
    for p in ${!mapping[@]};do

        # 跳过主节点
        if [[ $p == '172.16.20.106' ]];then
            continue
        fi

        echo ********************************************************************************************************************************************************************************************
        echo $p retreat!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        echo ********************************************************************************************************************************************************************************************

        if [[ $alternation != 0 ]];then
            equalizer ${mapping[$p]} 0
            sleep $alternation
        fi

        echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        echo Project $project retreat starting!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        if [[ $project =~ cjml ]];then
            ssh -o StrictHostKeyChecking=no administrator@$p '%systemroot%\\cwRsync\\bin\\rsync' -az --partial --delete --force  --stats rsync://172.16.20.106/$project /cygdrive/d/website/51cjml.com/$project
            estimate $?
        else
            ssh -o StrictHostKeyChecking=no administrator@$p '%systemroot%\\cwRsync\\bin\\rsync' -az --partial --delete --force  --stats rsync://172.16.20.106/$project /cygdrive/d/website/zhipeicloud.com/$project
            estimate $?
        fi

        if [[ $alternation != 0 ]];then
            equalizer ${mapping[$p]} 100
        fi
    done

}

main

 

posted @ 2020-11-27 17:00  ascertain  阅读(110)  评论(0编辑  收藏  举报