Commit b28a9b49 authored by daidekun's avatar daidekun

增加数据库启动判断

parent 96fe349b
#!/bin/bash #!/bin/bash
export NAMESPACE=`cat /var/run/secrets/kubernetes.io/serviceaccount/namespace`
echo "start replace db domain"
DB_FILE=dump.sql
HOST=$DB_SERVICE_HOST
PORT='3306'
USER='qa' USER='qa'
PASSWORD='qatest' PASSWORD='qatest'
HTTPS='true'
count=1
echo "HOST=$HOST db_is_running=0
PORT=$PORT
USER=$USER until [[ $count -eq 60 ]] || [[ $db_is_running -eq 1 ]]
PASSWORD=$PASSWORD do
HTTPS=$HTTPS let count+=1
NAMESPACE=$NAMESPACE" echo "count is $count"
mysqladmin -h db -u$USER -p$PASSWORD processlist
EXCLUDED_TABLES=( if [ $? -eq 0 ]
clotho.JOB_EXECUTION_LOG then
clotho.JOB_STATUS_TRACE_LOG echo "db is running"
notify.JOB_EXECUTION_LOG db_is_running=1
notify.JOB_STATUS_TRACE_LOG else
xyqb.JOB_EXECUTION_LOG echo "db is not running"
xyqb.JOB_STATUS_TRACE_LOG sleep 1
xyqb.channel fi
xyqb.t_phonenum
mall.jd_address
mall.jd_brand
mall.jd_product_sku_image
mall.jd_property
mall.jd_sku
mall.jd_sku_detail_image
mall.jd_sku_specs
mall.spu_image
mall.sale_product_detail
mall.product_nature_value_bak
mall.product_sku
mall.product_sku_image
mall.product_specification
mall.product_spu
)
IGNORED_TABLES_STRING=''
for TABLE in "${EXCLUDED_TABLES[@]}"
do :
IGNORED_TABLES_STRING+=" --ignore-table=${TABLE}"
done done
echo "mysqldump --host=${HOST} --port=${PORT} --user=${USER} --password=${PASSWORD} --all-databases --no-create-info ${IGNORED_TABLES_STRING} >> ${DB_FILE}" if [[ $db_is_running -eq 1 ]]
mysqldump --host=${HOST} --port=${PORT} --user=${USER} --password=${PASSWORD} --all-databases ${IGNORED_TABLES_STRING} >> ${DB_FILE} then
echo "sed file"
if [[ $HTTPS = true ]];then echo "db is running!!! start execution replace job"
sed -i "s#\.xyqb\.com#-${NAMESPACE}\.q-gp\.com#g; s#\.quantgroup\.cn#-${NAMESPACE}\.q-gp\.com#g; s#-base\.q-gp\.com#-${NAMESPACE}\.q-gp\.com#g" ${DB_FILE}
else export NAMESPACE=`cat /var/run/secrets/kubernetes.io/serviceaccount/namespace`
sed -i "s#\.xyqb\.com#-${NAMESPACE}\.q-gp\.com#g; s#\.quantgroup\.cn#-${NAMESPACE}\.q-gp\.com#g; s#-base\.q-gp\.com#-${NAMESPACE}\.q-gp\.com#g; s#\https#http#g" ${DB_FILE}
fi echo "start replace db domain"
DB_FILE=dump.sql
echo "mysql dump file" HOST=$DB_SERVICE_HOST
mysql --host=${HOST} --port=${PORT} --user=${USER} --password=${PASSWORD} < ${DB_FILE} PORT='3306'
\ No newline at end of file HTTPS='true'
echo "HOST=$HOST
PORT=$PORT
USER=$USER
PASSWORD=$PASSWORD
HTTPS=$HTTPS
NAMESPACE=$NAMESPACE"
EXCLUDED_TABLES=(
clotho.JOB_EXECUTION_LOG
clotho.JOB_STATUS_TRACE_LOG
notify.JOB_EXECUTION_LOG
notify.JOB_STATUS_TRACE_LOG
xyqb.JOB_EXECUTION_LOG
xyqb.JOB_STATUS_TRACE_LOG
xyqb.channel
xyqb.t_phonenum
mall.jd_address
mall.jd_brand
mall.jd_product_sku_image
mall.jd_property
mall.jd_sku
mall.jd_sku_detail_image
mall.jd_sku_specs
mall.spu_image
mall.sale_product_detail
mall.product_nature_value_bak
mall.product_sku
mall.product_sku_image
mall.product_specification
mall.product_spu
)
IGNORED_TABLES_STRING=''
for TABLE in "${EXCLUDED_TABLES[@]}"
do :
IGNORED_TABLES_STRING+=" --ignore-table=${TABLE}"
done
echo "mysqldump --host=${HOST} --port=${PORT} --user=${USER} --password=${PASSWORD} --all-databases --no-create-info ${IGNORED_TABLES_STRING} >> ${DB_FILE}"
mysqldump --host=${HOST} --port=${PORT} --user=${USER} --password=${PASSWORD} --all-databases ${IGNORED_TABLES_STRING} >> ${DB_FILE}
echo "sed file"
if [[ $HTTPS = true ]];then
sed -i "s#\.xyqb\.com#-${NAMESPACE}\.q-gp\.com#g; s#\.quantgroup\.cn#-${NAMESPACE}\.q-gp\.com#g; s#-base\.q-gp\.com#-${NAMESPACE}\.q-gp\.com#g" ${DB_FILE}
else
sed -i "s#\.xyqb\.com#-${NAMESPACE}\.q-gp\.com#g; s#\.quantgroup\.cn#-${NAMESPACE}\.q-gp\.com#g; s#-base\.q-gp\.com#-${NAMESPACE}\.q-gp\.com#g; s#\https#http#g" ${DB_FILE}
fi
echo "mysql dump file"
mysql --host=${HOST} --port=${PORT} --user=${USER} --password=${PASSWORD} < ${DB_FILE}
else
echo "db is not running!!! Do not execution replace job"
fi
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment