Mysql分布式数据库变更自动化部署(二)

2015-07-24 06:09:43 · 作者: · 浏览: 7
部署.

[root@deploydb autodeploy]# sh autodeploy -t deploy -f t1.sql
*************************************************
[2015-02-26 18:49:48]: Preparing to deploy t1.sql to [dfng1db4.se2]...
*************************************************
You deployed success this file ago on first node,Please delete file [/home/skate/autodeploy/issucess] if you want to continue.
[root@deploydb autodeploy]# rm /home/skate/autodeploy/issucess
rm: remove regular file `/home/skate/autodeploy/issucess'? y

2.部署文件不存在
[root@deploydb autodeploy]# sh autodeploy -t deploy -f t1.sql
[/home/skate/autodeploy/ex_dbrelease/t1.sql] not exist! Please confirm whether the file have been uploaded or deployed.
[root@deploydb autodeploy]#

3.多个部署程序同时运行确认

[root@deploydb autodeploy]# sh autodeploy
**********************************
root 8560 8520 0 20:24 pts/2 00:00:00 sh autodeploy -t ftp
root 8580 1632 0 20:24 pts/11 00:00:00 sh autodeploy
**********************************

There is a autodeploy running,continue[Y/N]? N
Input:N,Exit from autodeploy script.

?

Script:

#!/bin/sh
#
# Author:Skate
# Time:2015/02/25
# Function: automate applying db scripts

CURPID=$$
DIR=/home/szhao/autodeploy
DIRLOG=$DIR/log
RELEASEDIR=$DIR/ex_dbrelease
POST_RELEASEDIR=$DIR/post_dbrelease
LOCK=$DIR/autodeploy.lock
LOG=$DIRLOG/autodeploy.log
CFG=$DIR/autodeploy_config.txt
CFGPID=$DIR/${CURPID}_config
DEPLOYLOG=$DIRLOG/deploy_`date "+%Y%m%d%H%M"`_deploy.log
DATE=`date "+%Y-%m-%d %H:%M:%S"`
#LFILE=/tmp/tmpsql.log
RDIR=/tmp/autodeploy
ISDEPLOY='Y'

. $DIR/.PWD
#############################################################################
# Avoid multipe deployment processes running simultaneously
#############################################################################
RUNNUM=`ps -ef | grep autodeploy | grep -v grep | wc -l`

if [ $RUNNUM -gt 2 ];then
   echo "**********************************"
   ps -ef | grep autodeploy | grep -v grep
   echo "**********************************"
   echo  ""
   read -p "There is a autodeploy running,continue[Y/N]? " isrun
   case $isrun in
      Y)
         echo "continue run autodeploy script."
       ;;
      N)
        echo "Input:$isrun,Exit from autodeploy script."
        exit 0
       ;;
      *)
        echo "Error input"
        exit 1
       ;;
    esac
fi

#############################################################################
# Display usage message and exit
#############################################################################
usage() {
  cat < $LOG

cd $DIR 
config_num=`find $DIR/ -name  *_config | wc -l `
if [ ${config_num} -gt 0 ];then
for pid in  `ls -l  *_config | awk '{print $9}' | awk -F_ '{print $1}'`
do
NUM=`ps -ef | awk '{ print $2 }' | grep -E '^${pid}$' | wc -l`
if [ $NUM -eq 0 ] ; then
rm -rf $DIR/${pid}_config
fi
done
fi
#############################################################################
# Upload release file to all nodes
#############################################################################
# sync file to remote
function multi_ftp
{
HOST=$1
LFILE=$2
rsync -avP --bwlimit=1000 $RELEASEDIR/$LFILE $HOST:$RDIR/ >/dev/null 2>&1
if [  $? == 0 ] ; then
   echo "[$LFILE] is transferd to $HOST success."
else
   echo "[$LFILE] is transferd to $HOST fail."
   exit 1
fi
exit 0

}

function multi_deploy
{
host=$1
release