您的位置:首页 > 数据库 > Oracle

HA脚本

2016-04-18 17:20 483 查看
act_db.ksh
#!/bin/ksh
#Copyright (c) 2010, Oracle. All rights reserved.
#
# NAME
# act_db.ksh
#
# DESCRIPTION
# This shell script is the action script for start / stop / check
# the Oracle Instance in a cold failover configuration.
#
# Place this file in <CRS_HOME>/crs/public/
#
# MODIFIED (MM/DD/YY)
# swong 09/29/10 - Creation
# swong 11/09/10 - Modification
init_env () {
export ORACLE_SID=s112032
export ORACLE_HOME=`awk -F: '{if ($1 == "'$ORACLE_SID'") {print $2; exit}}' /etc/sf/shell/db_info.txt`
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib
export SQLPLUS=$ORACLE_HOME/bin/sqlplus
}

check_db () {
process="ora_pmon_$ORACLE_SID"
check_proc=`ps -ae -o args | grep -w "ora_pmon_$ORACLE_SID" | grep -v grep | head -n 1`
if [ "$process" == "$check_proc" ]; then
DB_STATUS=`$SQLPLUS -S / as sysdba <<EOF
set echo off
set feedback off
set heading off
set pagesize 0
set linesize 300
whenever sqlerror exit failure
select status from v\\$instance;
exit
EOF`
if [ $? -ne 0 ]; then
echo " [ERROR] Check the database $ORACLE_SID failed!"
return 1
else
if [ $DB_STATUS != 'MOUNTED' ]; then
echo " [ERROR] The database $ORACLE_SID is $DB_STATUS but NOT mounted!"
return 1
else
return 0
fi
fi
else
echo " [ERROR] The database $ORACLE_SID background process does NOT exist!"
return 1
fi
}

init_env

case $1 in
'start')
$SQLPLUS -S / as sysdba <<EOF
whenever sqlerror exit failure
startup nomount force
alter database mount standby database;
alter database recover managed standby database using current logfile disconnect from session;
exit
EOF
if [ $? -ne 0 ]; then
echo " [ERROR] Fail to start the database $ORACLE_SID!"
exit 1
else
exit 0
fi
;;
'stop')
$SQLPLUS -S / as sysdba <<EOF
shutdown immediate
exit
EOF
if [ $? -ne 0 ]; then
echo " [ERROR] Fail to shutdown the database $ORACLE_SID!"
exit 1
else
exit 0
fi
;;
'check')
check_db
if [ $? -ne 0 ]; then
exit 1
else
exit 0
fi
;;
'clean')
ps -aef | grep -w "ora_pmon_$ORACLE_SID" | grep -v grep | head -n 1 | awk '{print $2}'| xargs -i kill -9 {}
exit 0
;;
*)
echo "Usage $0 {start|stop|check|clean}"
exit 1
;;
esac

[oracle@cnsz22pl0076:/data01/tmp/llc]$cat act_db.ksh_pri
#!/bin/ksh
#Copyright (c) 2010, Oracle. All rights reserved.
#
# NAME
# act_db.ksh
#
# DESCRIPTION
# This shell script is the action script for start / stop / check
# the Oracle Instance in a cold failover configuration.
#
# Place this file in <CRS_HOME>/crs/public/
#
# MODIFIED (MM/DD/YY)
# swong 09/29/10 - Creation
# swong 11/09/10 - Modification
init_env () {
export ORACLE_SID=s112032
export ORACLE_HOME=`awk -F: '{if ($1 == "'$ORACLE_SID'") {print $2; exit}}' /etc/sf/shell/db_info.txt`
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib
export SQLPLUS=$ORACLE_HOME/bin/sqlplus
}

check_db () {
process="ora_pmon_$ORACLE_SID"
check_proc=`ps -ae -o args | grep -w "ora_pmon_$ORACLE_SID" | grep -v grep | head -n 1`
if [ "$process" == "$check_proc" ]; then
DB_STATUS=`$SQLPLUS -S / as sysdba <<EOF
set echo off
set feedback off
set heading off
set pagesize 0
set linesize 300
whenever sqlerror exit failure
select status from v\\$instance;
exit
EOF`
if [ $? -ne 0 ]; then
echo " [ERROR] Check the database $ORACLE_SID failed!"
return 1
else
if [ $DB_STATUS != 'OPEN' ]; then
echo " [ERROR] The database $ORACLE_SID is $DB_STATUS but NOT opened!"
return 1
else
return 0
fi
fi
else
echo " [ERROR] The database $ORACLE_SID background process does NOT exist!"
return 1
fi
}

init_env

case $1 in
'start')
$SQLPLUS -S / as sysdba <<EOF
whenever sqlerror exit failure
startup force
exit
EOF
if [ $? -ne 0 ]; then
echo " [ERROR] Fail to start the database $ORACLE_SID!"
exit 1
else
exit 0
fi
;;
'stop')
$SQLPLUS -S / as sysdba <<EOF
whenever sqlerror exit failure
shutdown immediate
exit
EOF
if [ $? -ne 0 ]; then
echo " [ERROR] Fail to shutdown the database $ORACLE_SID!"
exit 1
else
exit 0
fi
;;
'check')
check_db
if [ $? -ne 0 ]; then
exit 1
else
exit 0
fi
;;
'clean')
ps -aef | grep -w "ora_pmon_$ORACLE_SID" | grep -v grep | head -n 1 | awk '{print $2}'| xargs -i kill -9 {}
exit 0
;;
*)
echo "Usage $0 {start|stop|check|clean}"
exit 1
;;
esac
[oracle@cnsz22pl0076:/data01/tmp/llc]$cat act_lsnr.ksh

#!/bin/ksh
#Copyright (c) 2010, Oracle. All rights reserved.
#
# NAME
# act_lsnr.ksh
#
# DESCRIPTION
# This shell script is the action script for start / stop / check
# the Oracle Listener in a cold failover configuration.
#
# Place this file in <CRS_HOME>/crs/public/
#
# MODIFIED (MM/DD/YY)
# swong 09/27/10 - Creation
# swong 11/09/10 - Modification
init_env () {
export ORACLE_SID=s112032
export ORACLE_HOME=`awk -F: '{if ($1 == "'$ORACLE_SID'") {print $2; exit}}' /etc/sf/shell/db_info.txt`
export ORA_LISTENER_NAME=${ORACLE_SID}
}

check_listener () {
process_listener="$ORACLE_HOME/bin/tnslsnr $ORA_LISTENER_NAME -inherit"
check_proc_listener=`ps -ae -o args | grep -w "tnslsnr $ORA_LISTENER_NAME" | grep -v grep | head -n 1`
if [ "$process_listener" = "$check_proc_listener" ]; then
$ORACLE_HOME/bin/lsnrctl status $ORA_LISTENER_NAME
else
return 1
fi
}

init_env

case $1 in
'start')
$ORACLE_HOME/bin/lsnrctl start $ORA_LISTENER_NAME
if [ $? -ne 0 ]; then
echo " [ERROR] Fail to start the listener $ORA_LISTENER_NAME!"
exit 1
else
exit 0
fi
;;
'stop')
$ORACLE_HOME/bin/lsnrctl stop $ORA_LISTENER_NAME
if [ $? -ne 0 ]; then
echo " [ERROR] Fail to stop the listener $ORA_LISTENER_NAME!"
exit 1
else
exit 0
fi
;;
'check')
check_listener
if [ $? -ne 0 ]; then
exit 1
else
exit 0
fi
;;
'clean')
ps -aef | grep -w "tnslsnr $ORA_LISTENER_NAME" | grep -v grep | head -n 1 | awk '{print $2}' | xargs -i kill -9 {}
exit 0
;;
*)
echo "Usage $0 {start|stop|check|clean}"
exit 1
;;
esac

[oracle@cnsz22pl0076:/data01/tmp/llc]$cat act_rgb.ksh
#!/bin/ksh
# Copyright (c) 2010, Oracle. All rights reserved.
#
# NAME
# act_rgb.sh
#
# DESCRIPTION
# This shell script is the action script for start / stop / check
# the Oracle Instance in a cold failover configuration.
#
# Place this file in <CRS_HOME>/crs/public/$ORACLE_SID/. Make the directory readable/writable to the RDBMS owner.
# Also, create a invisible directory .run under <CRS_HOME>/crs/public/$ORACLE_SID/.
# This .run directory will be used to store the runtime files. Do NOT delete them!!!
#
# For particular database, please change ORACLE_SID value accordingly.
#
# MODIFIED (MM/DD/YY)
# swong 09/27/10 - Creation
# swong 11/09/10 - Add checking if the file exists
init_env () {
export ORACLE_SID=s112032
export ORACLE_HOME=`awk -F: '{if ($1 == "'$ORACLE_SID'") {print $2; exit}}' /etc/sf/shell/db_info.txt`
export SCRIPT_HOME=/dba/app/product/11.2.0/grid/crs/public/${ORACLE_SID}/.run
export FILENAME=$SCRIPT_HOME/.rgb_start_stop_check.${ORACLE_SID}
}

init_env

case $1 in
'start')
echo '0' > $FILENAME
;;
'stop')
echo '1' > $FILENAME
;;
'check')
read line < $FILENAME
if [ $? -ne 0 ]; then
exit 1
else
if [ $line -eq 0 ]; then
exit 0
else
exit 1
fi
fi
;;
'clean')
rm -f $FILENAME
exit 0
;;
*)
echo "Usage $0 {start|stop|check|clean}"
exit 1
;;
esac

[oracle@cnsz22pl0076:/data01/tmp/llc]$cat act_rgh.ksh
#!/bin/ksh
# Copyright (c) 2010, Oracle. All rights reserved.
#
# NAME
# act_rgh.sh
#
# DESCRIPTION
# This shell script is the action script for start / stop / check
# the Oracle Instance in a cold failover configuration.
#
# Place this file in <CRS_HOME>/crs/public/$ORACLE_SID/. Make the directory readable/writable to the RDBMS owner.
# Also, create a invisible directory .run under <CRS_HOME>/crs/public/$ORACLE_SID/.
# This .run directory will be used to store the runtime files. Do NOT delete them!!!
#
# For particular database, please change ORACLE_SID value accordingly.
#
# MODIFIED (MM/DD/YY)
# swong 09/27/10 - Creation
# swong 11/09/10 - Add checking if the file exists
init_env () {
export ORACLE_SID=s112032
export ORACLE_HOME=`awk -F: '{if ($1 == "'$ORACLE_SID'") {print $2; exit}}' /etc/sf/shell/db_info.txt`
export SCRIPT_HOME=/dba/app/product/11.2.0/grid/crs/public/${ORACLE_SID}/.run
export FILENAME=$SCRIPT_HOME/.rgh_start_stop_check.${ORACLE_SID}
}

init_env

case $1 in
'start')
echo '0' > $FILENAME
;;
'stop')
echo '1' > $FILENAME
;;
'check')
read line < $FILENAME
if [ $? -ne 0 ]; then
exit 1
else
if [ $line -eq 0 ]; then
exit 0
else
exit 1
fi
fi
;;
'clean')
rm -f $FILENAME
exit 0
;;
*)
echo "Usage $0 {start|stop|check|clean}"
exit 1
;;
esac
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  oracle