My coworker created this script that can dynamically generate stop/start many database instances registered in /etc/oratab, this is a RAC server that has 12c and 11g oracle_homes RDBMS, the generated scripts will loop /etc/oratab and stop the TAF services gracefully first then stop the instances:
-sh-4.1$ more stop_all_instances.sh
#!/bin/sh
#
# Program: stopallinstances.sh
# Purpose: stop all database instances on the server
# -----------------------------------------------------------------------------
#
# History
#
# Date Rev Who Comments
# --------- ---- -------------- -----------------------------------------------
# 04Jan2018 1.0 Bing Ge Created
# 03Sep2019 2.0 Bing Ge change to start the db in parallel.
#
# ---------------------------------------------------
#
LOCATION=/home/oracle/bge
STARTDB=$LOCATION/scripts/start_db.sh
STOPDB=$LOCATION/scripts/stop_db.sh
timestamp=`date +%Y_%m_%d_%H_%M_%S`
hostname=`hostname`
LOG_LOCATION=$LOCATION/logs
LOG_FILE=$LOG_LOCATION/stopallinstances_$hostname_$timestamp.log
rm $STARTDB
rm $STOPDB
/net/ACEDBA/ACEDBA/bge/scripts/create_scripts_for_db_in_oh.sh -e prd -v 12 -o /u01/app/oracle/product/12.1.0.2/ACEPRD
/net/ACEDBA/ACEDBA/bge/scripts/create_scripts_for_db_in_oh.sh -e prd -v 12 -o /u01/app/oracle/product/12.1.0
/net/ACEDBA/ACEDBA/bge/scripts/create_scripts_for_db_in_oh.sh -e prd -v 11 -o /u01/app/oracle/product/11.2.0.4
/net/ACEDBA/ACEDBA/bge/scripts/create_scripts_for_db_in_oh.sh -e prd -v 11 -o /u01/app/oracle/product/11.2.0/db_1
chmod +x $STARTDB
chmod +x $STOPDB
$STOPDB | tee -a $LOG_FILE
while [[ "$(ps -ef | grep stopinstance | grep -v grep)" != "" ]] ;
do
sleep 5
echo -n '.'
done
echo "All DB in the list should be down, please check."
exit
The following are the scripts of create_scripts_for_db_in_oh.sh being called above:
-sh-4.1$ more /net/ACEDBA/ACEDBA/bge/scripts/create_scripts_for_db_in_oh.sh#!/bin/sh## Program: create_scripts_for_db_in_oh.sh# Purpose: create start/stop scripts for all databases running in the input ORACLE HOME.# -----------------------------------------------------------------------------## History## Date Rev Who Comments# --------- ---- -------------- -----------------------------------------------# 04DSep2019 1.0 Bing Ge Created## ---------------------------------------------------#timestamp=`date +%Y_%m_%d_%H_%M_%S`hostname=`hostname`ORATAB=/etc/oratab_dbaHOSTNAME=`hostname`LOCATION=$HOME/bgeSTARTALLDB=$LOCATION/scripts/start_db.shSTOPALLDB=$LOCATION/scripts/stop_db.shLOG_LOCATION=$LOCATION/logsLOG_FILE=$LOG_LOCATION/create_scripts_for_db_in_oh_$hostname_$timestamp.logRAC=yusage(){echo "usage: create_scripts_for_db_in_oh.sh [-e dev|tst|sit|uat|stg|prd -v 11|12 -r y|n -o oracle_home -p patch_list -m email] | [-h]]"}while [ "$1" != "" ]; docase $1 in-e | --env ) shiftENV=$1;;-v | --version ) shiftVERSION=$1;;-r | --rac ) shiftRAC=$1echo $RAC;;-o | --oracle_home ) shiftexport ORACLE_HOME_P=$1export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:/usr/ccs/bin:$PATHexport LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH;;-p | --patch_number ) shiftPATCHES_LIST=$1echo $PATCHES_LIST;;-m | --email ) shiftTo_EMAIL_ADDR=$1;;-h | --help ) usageexit;;* ) usageecho "111$1222"exit 1esacshiftdoneecho ${VERSION}echo ${ENV}echo "RAC=${RAC}"STARTDB=$LOCATION/scripts/start_${VERSION}_${ENV}_db.shSTOPDB=$LOCATION/scripts/stop_${VERSION}_${ENV}_db.shDBPATCH=$LOCATION/scripts/dbpatch_${VERSION}_${ENV}.shecho $DBPATCHrm $STARTDBrm $STOPDBrm $DBPATCHif [ $VERSION == "11" ]thenPATCH_LOCATION="/net/ACEDBA/ACEDBA/patches/11.2.0.4"elsePATCH_LOCATION="/net/ACEDBA/ACEDBA/patches/12.1.0.2"fiecho " creating start/stop/datapatch script for dbs running in $ORACLE_HOME."cat $ORATAB | while read LINEdocase $LINE in\#*) ;; #comment-line in oratab*)DB_NAME=`echo $LINE | awk -F: '{print $1}' -`ORACLE_HOME_1=`echo $LINE | awk -F: '{print $2}' -`if [ "$DB_NAME" == '*' ] ; then# same as NULL SID - ignore this entryORACLE_SID=""continuefi#echo ${DB_NAME}#echo ${ORACLE_HOME_1}#echo ${ORACLE_HOME_P}if [ "$ORACLE_HOME_1" == "${ORACLE_HOME_P}" ] ; then. ${ORACLE_HOME_1}/${DB_NAME}.envecho ${DB_NAME}if [ ${ORACLE_SID} == "LSNR" ] ; thenecho "do nothing for ${ORACLE_SID}"elsestopinstance="$LOCATION/scripts/stopinstance${ENV}${ORACLE_SID}";startinstance="$LOCATION/scripts/startinstance${ENV}${ORACLE_SID}";datapatch="$LOCATION/scripts/datapatch${ENV}${ORACLE_SID}";rm $stopinstancerm $startinstancerm $datapatchecho "export ORACLE_SID=${ORACLE_SID}">>$stopinstanceecho "export ORAENV_ASK=NO">>$stopinstanceecho ". /usr/local/bin/oraenv">>$stopinstanceecho "export ORACLE_SID=${ORACLE_SID}">>$startinstanceecho "export ORAENV_ASK=NO">>$startinstanceecho ". /usr/local/bin/oraenv">>$startinstanceecho "export ORACLE_SID=${ORACLE_SID}">>$datapatchecho "export ORAENV_ASK=NO">>$datapatchecho ". /usr/local/bin/oraenv">>$datapatchif [ ${DB_NAME} == "BTCRPRD" -o ${DB_NAME} == "BTCRSTG" ]; thenecho "do nothing"elsefor PATCH_NUMBER in $PATCHES_LISTdoecho "$PATCH_LOCATION/$PATCH_NUMBER/datapatch.sh"echo "$PATCH_LOCATION/$PATCH_NUMBER/datapatch.sh">>$datapatchdonefiif [ ${RAC} == "y" -o ${RAC} == "Y" ]; thenif [ $ENV == "dev" -o $ENV == "tst" -o $ENV == "sit" ]; thenecho "srvctl stop database -d $DB_NAME" >> $stopinstanceecho "srvctl start database -d $DB_NAME" >> $startinstanceelseecho "/net/ACEDBA/ACEDBA/bge/scripts/stop_ace_services.sh $DB_NAME $ORACLE_SID" >> $stopinstanceif [ $VERSION == "12" ] ; thenecho "srvctl stop instance -d $DB_NAME -i $ORACLE_SID -stopoption transactional" >> $stopinstanceecho "srvctl start instance -d $DB_NAME -i $ORACLE_SID" >> $startinstanceelseecho "srvctl stop instance -d $DB_NAME -i $ORACLE_SID -o transactional" >> $stopinstanceecho "srvctl start instance -d $DB_NAME -i $ORACLE_SID" >> $startinstancefiecho "/net/ACEDBA/ACEDBA/bge/scripts/start_ace_services.sh $DB_NAME $ORACLE_SID" >> $startinstancefielseecho "/net/ACEDBA/ACEDBA/bge/scripts/start_database.sh ${ORACLE_SID}" >>$startinstanceecho "/net/ACEDBA/ACEDBA/bge/scripts/stop_database.sh ${ORACLE_SID}" >> $stopinstancefichmod +x ${stopinstance}echo "nohup ${stopinstance}&">>${STOPDB}chmod +x ${startinstance}echo "nohup ${startinstance}&">>${STARTDB}chmod +x ${datapatch}echo "${datapatch}">>${DBPATCH}fifi;;esacdonechmod +x $STARTDBchmod +x $STOPDBchmod +x $DBPATCHcat $STARTDB >> $STARTALLDBcat $STOPDB >> $STOPALLDB
Comments
Post a Comment