zl程序教程

您现在的位置是:首页 >  工具

当前栏目

production自动化发布

自动化 发布 production
2023-09-11 14:16:16 时间

 

 

 

 

 

 

 

#/bin/env sh
#set -e  # errexit
#cwRsyncServer <=> case sensitive(module)
#cwRsyncClinet <=> case insensitive
export LANG=zh_CN.utf8
ml_slb=lb-uf611bih0o3phcwzivxfe
zp_slb=lb-uf6sljbd851v9pgrng6nk
project=$1
alternation=$2


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[@]}


declare -a article # declare indexed array to store project

function make_array(){
    tmp=0
    for b in `IFS=$',';echo $project`;do
        echo $b make_array
        article[$tmp]=$b
        ((tmp++))
    done
}

make_array


echo '################################################################################################'
echo 'projects: '${article[@]}
echo '################################################################################################'


# 备份
function backup(){
    for b in ${article[@]};do
        echo ********************************************************************************************************************************************************************************************
        echo $b File Backup!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        echo ********************************************************************************************************************************************************************************************
        if [[ $b =~ cjml ]];then
            ssh -o StrictHostKeyChecking=no administrator@172.16.20.106 "C:\\Progra~1\\7-Zip\\7z.exe a -snl D:\\backup\\${b}--$(date +%Y-%m-%d_%H-%M-%S).zip D:\\website\\51cjml.com\\${b}\\*"
        else
            ssh -o StrictHostKeyChecking=no administrator@172.16.20.106 "C:\\Progra~1\\7-Zip\\7z.exe a -snl D:\\backup\\${b}--$(date +%Y-%m-%d_%H-%M-%S).zip D:\\website\\zhipeicloud.com\\${b}\\*"
        fi
    done
}

if $3;then
    backup
fi


# 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
}

# 同步至主节点
function succedent(){
    p=172.16.20.106

    # 同步主节点前,调整主节点权重
    if [[ $alternation != 0 ]];then
        equalizer ${mapping[$p]} 0
        sleep $alternation
    fi

    echo ********************************************************************************************************************************************************************************************
    echo Major node 172.16.20.106 File Synchronization!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    echo ********************************************************************************************************************************************************************************************
    for b in ${article[@]};do
        echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        echo Major node 172.16.20.106 entry $b Project File Synchronization starting!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        if [[ $b =~ cjml ]];then
            ssh -o StrictHostKeyChecking=no administrator@172.16.20.106 '%systemroot%\\cwRsync\\bin\\rsync' -az --partial --delete  --force --stats rsync://10.8.0.166/$b /cygdrive/d/website/51cjml.com/$b
            estimate $?


# cat <<eof |& tee -a /c/rsyncd.conf
# [$b]
# path = /cygdrive/d/web/51cjml.com/$b
# exclude = .svn
# comment = $b

# eof


        else
            ssh -o StrictHostKeyChecking=no administrator@172.16.20.106 '%systemroot%\\cwRsync\\bin\\rsync' -az --partial --delete  --force --stats rsync://10.8.0.166/$b /cygdrive/d/website/zhipeicloud.com/$b
            estimate $?


# cat <<eof |& tee -a /c/rsyncd.conf
# [$b]
# path = /cygdrive/d/web/zhipeicloud.com/$b
# exclude = .svn
# comment = $b

# eof


        fi
    done

    # 恢复主节点权重
    if [[ $alternation != 0 ]];then
        equalizer ${mapping[$p]} 100
    fi

}

succedent


# p delegate the ip of the node; b delegate the project
function main(){
    for p in ${!mapping[*]};do

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

        echo ********************************************************************************************************************************************************************************************
        echo $p File Synchronization!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        echo ********************************************************************************************************************************************************************************************

        # 调整节点$p权重 => 0
        if [[ $alternation != 0 ]];then
            equalizer ${mapping[$p]} 0
            sleep $alternation
        fi

        for b in ${article[*]};do
            echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            echo $b Project File Synchronization starting!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            if [[ $b =~ cjml ]];then
                ssh -o StrictHostKeyChecking=no administrator@$p '%systemroot%\\cwRsync\\bin\\rsync' -az --partial --delete --force --stats rsync://172.16.20.106/$b /cygdrive/d/website/51cjml.com/$b
                estimate $?
            else
                ssh -o StrictHostKeyChecking=no administrator@$p '%systemroot%\\cwRsync\\bin\\rsync' -az --partial --delete --force --stats rsync://172.16.20.106/$b /cygdrive/d/website/zhipeicloud.com/$b
                estimate $?
            fi
        done

        # 调整节点$p权重 => 100
        if [[ $alternation != 0 ]];then
            equalizer ${mapping[$p]} 100
        fi
    done
}

main

# todo show slb status
echo ********************************************************************************************************************************************************************************************
echo Catalogue SLB $ml_slb exhibition!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
echo ********************************************************************************************************************************************************************************************
/c/windows/show_slb_status.exe $ml_slb
echo ********************************************************************************************************************************************************************************************
echo Zhipei SLB $zp_slb exhibition!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
echo ********************************************************************************************************************************************************************************************
/c/windows/show_slb_status.exe $zp_slb