#!/bin/sh
#=============================================================================#
# #
# This script is used to fully delete Software of CRS/RAC for 10/11g #
# Delete CRS/RAC SW, CRS related socket/temp/init files #
# And change back ownership of OCR and VF #
# #
# Right now, it is only tested on AIX and Linux #
# #
# [email protected] #
#=============================================================================#
# ------------------------- Change Logs --------------------
#
# 12/13/2007 - Creation and Test for AIX Platform
# 01/03/2008 - Add Platform Variables for Linux/HP/SUN
# 01/05/2008 - Change and Test for Linux Platform
# 01/07/2008 - Delete SW on all cluster nodes if possible
#
# ----------------------------- End ------------------------
# System Dependent Variables
OS=`/bin/uname`;
HOST=`/bin/hostname`;
case $OS in
Linux)
INST_IN="/etc/oraInst.loc"
ORA_TAB="/etc/oratab"
ORA_LOC="/etc/oracle"
TEMP="/tmp"
CONF="/etc/init.d"
LOCALBIN="/usr/local/bin"
ID="/usr/bin/id "
PSEF="/bin/ps -ef "
AWK="/bin/awk "
GREP="/bin/grep "
EGREP="/bin/egrep "
CAT="/bin/cat "
CUT="/bin/cut "
CHOWN="/bin/chown "
LS="/bin/ls "
ECHO="/bin/echo "
RMRF="/bin/rm -rf "
MV="/bin/mv "
DD="/bin/dd "
RSH="/usr/bin/rsh "
SSH="/usr/bin/ssh "
;;
AIX)
INST_IN="/etc/oraInst.loc"
ORA_TAB="/etc/oratab"
ORA_LOC="/etc/oracle"
TEMP="/tmp"
CONF="/etc"
LOCALBIN="/usr/local/bin"
ID="/bin/id "
PSEF="/bin/ps -ef "
AWK="/bin/awk "
GREP="/bin/grep "
EGREP="/bin/egrep "
CAT="/bin/cat "
CUT="/bin/cut "
CHOWN="/bin/chown "
LS="/bin/ls "
ECHO="/bin/echo "
RMRF="/bin/rm -rf "
MV="/bin/mv "
DD="/bin/dd "
RSH="/bin/rsh "
SSH="/bin/ssh "
RMITAB="rmitab "
;;
SunOS)
INST_IN="/var/opt/oracle/oraInst.loc"
ORA_TAB="/var/opt/oracle/oratab"
ORA_LOC="/var/opt/oracle"
TEMP="/tmp"
CONF="/etc/init.d"
LOCALBIN="/usr/local/bin"
ID="/usr/bin/id "
PSEF="/usr/bin/ps -ef "
AWK="/usr/bin/awk "
GREP="/usr/bin/grep "
EGREP="/usr/bin/egrep "
CAT="/usr/bin/cat "
CUT="/usr/bin/cut "
CHOWN="/usr/bin/chown "
LS="/usr/bin/ls "
ECHO="/usr/bin/echo "
RMRF="/usr/bin/rm -rf "
MV="/usr/bin/mv "
DD="/usr/bin/dd "
RSH="/usr/bin/rsh "
SSH="/usr/bin/ssh "
;;
HP-UX)
INST_IN="/var/opt/oracle/oraInst.loc"
ORA_TAB="/var/opt/oracle/oratab"
ORA_LOC="/var/opt/oracle"
TEMP="/tmp"
CONF="/etc/init.d"
LOCALBIN="/usr/local/bin"
ID="/usr/bin/id "
PSEF="/usr/bin/ps -ef "
AWK="/usr/bin/awk "
GREP="/usr/bin/grep "
EGREP="/usr/bin/egrep "
CAT="/usr/bin/cat "
CUT="/usr/bin/cut "
CHOWN="/usr/bin/chown "
LS="/usr/bin/ls "
ECHO="/usr/bin/echo "
RMRF="/usr/bin/rm -rf "
MV="/usr/bin/mv "
DD="/usr/bin/dd "
RSH="/usr/bin/rsh "
SSH="/usr/bin/ssh "
;;
*)
echo
echo "Unknown OS system";
echo
exit 1;
;;
esac
#####################
#exit 0;
#####################
#================================ Debug =======================================
# Open following variabels for debug usage
#
# DD=$ECHO
# MV=$ECHO
# RMRF=$ECHO
# CHOWN=$ECHO
# RMITAB=$ECHO
#
#==============================================================================
# Function Caller Permission Check
USER=`$ID |$AWK -F= '{print $2}'|$AWK -F\( '{print $1}'`
if [ "X$USER" != "X0" ];
then
$ECHO "You need to run this script as root";
echo
exit 1
fi
# CRS/RAC Software Deletion Confirmation
echo
echo "========================================================================="
echo " Will delete CRS/RAC ....? Input your selection(yes|no) "
echo "========================================================================="
echo
read INPUT
if [ "X$INPUT" != "Xyes" ];
then
$ECHO "Deletion Refused. Quit!";
echo
exit 1;
fi
# Remote Shell Check
if $RSH $HOST $ECHO 2> /dev/null;
then
RH=$RSH
elif $SSH $HOST $ECHO 2> /dev/null;
then
RH=$SSH
else
echo
$ECHO "Remote SHELL is not configured";
$ECHO "Delete Local CRS/RAC Software only";
echo
fi
echo
echo "Start to delete ...";
echo
###########
#exit 0;
###########
# Get CRS_HOME and ORACLE_HOMEs
echo "Start to Get OraInventory Location ...";
if [ -f "$INST_IN" ];
then
ORAINST=`$CAT $INST_IN|$GREP "inventory_loc"|$CUT -d "=" -f2`;
$ECHO "Oracle Inventory is at \"$ORAINST\"";
if [ "X$ORAINST" != "X" -a -d "$ORAINST" ];
then
O_USER=`$LS -ld $ORAINST|$AWK '{print \$3}'`;
[ -n "$1" ] && $ECHO "Oracle User: $O_USER";
O_GROUP=`$LS -ld $ORAINST|$AWK '{print \$4}'`;
[ -n "$1" ] && $ECHO "Oracle Group: $O_GROUP";
if [ -f "$ORAINST/ContentsXML/inventory.xml" ];
then
ORACRS=`$CAT $ORAINST/ContentsXML/inventory.xml|$GREP "IDX=\"1\""|$CUT -d '"' -f4`;
ORAHOME=`$CAT $ORAINST/ContentsXML/inventory.xml|$GREP "IDX=\"2\""|$CUT -d '"' -f4`;
ORAHOME2=`$CAT $ORAINST/ContentsXML/inventory.xml|$GREP "IDX=\"3\""|$CUT -d '"' -f4`;
fi
fi
fi
echo
if [ "X$ORACRS" = "X" ];
then
$ECHO "Can not get CRS directory from Oracle Inventory";
$ECHO "Quit!";
exit 1;
fi
# Get Cluster Node Information
NODE_LIST=`$ORACRS/bin/olsnodes`;
if [ "X$NODE_LIST" = "X" ];
then
echo
$ECHO "Can not get cluster nodes information";
$ECHO "Quit!"
exit 1
fi
echo
$ECHO "CRS is installed at \"$ORACRS\"";
echo
$ECHO "Start to stop CRS Stack ...";
echo
# Get CSS Vote Files and Change back their Ownerships
for CSSVD in `$ORACRS/bin/crsctl query css votedisk`;
do
if [ `$ECHO $CSSVD|$EGREP '^\/'` ]; then
[ -n "$1" ] && $ECHO "Voting File: $CSSVD";
if [ "X$RH" = "X" ];
then
$CHOWN $O_USER:$O_GROUP $CSSVD;
else
for node in $NODE_LIST;
do
$RH $node "$CHOWN $O_USER:$O_GROUP $CSSVD;";
done
fi
fi
done
# Delete CRS/RAC Installation Temp Files
echo "Delete CRS Installation Temp Files"
if [ "X$RH" = "X" ];
then
TempFile=`$LS $TEMP|$GREP OraInstall`
if [ "X$TempFile" != "X" ];
then
for I in $TempFile;
do
[ -n "$1" ] && $ECHO "Delete Installation Temp File: $TEMP/$I";
$RMRF $TEMP/$I
done
fi
else
for node in $NODE_LIST;
do
TempFile=`$RH $node "$LS $TEMP|$GREP OraInstall"`
if [ "X$TempFile" != "X" ];
then
for I in $TempFile;
do
[ -n "$1" ] && $ECHO "Delete Temp File on \"$node: $TEMP/$I\"";
$RH $node "$RMRF $TEMP/$I"
done
fi
done
fi
echo
###########
#exit 0;
###########
# Stop CRS Stack First
if [ "X$RH" != "X" ];
then
for node in $NODE_LIST;
do
$ECHO "Stop CRS stack on node \"$node\"";
if [ "X$node" != "X$HOST" ];
then
$RH $node "$ORACRS/bin/crsctl stop crs"
sleep 10
$RH $node "$PSEF|$GREP -v grep|$EGREP 'c[s|r]sd.bin'" > /tmp/ocssd_ps
else
$ORACRS/bin/crsctl stop crs
sleep 2
$PSEF|$GREP -v grep|$GREP 'c[s|r]sd.bin' > /tmp/ocssd_ps
fi
PROCESS=`$CAT /tmp/ocssd_ps`
if [ "X$PROCESS" != "X" ];
then
echo
$ECHO "Stop CRS stack failed on node \"$node\"";
echo
$RMRF /tmp/ocssd_ps
exit 1;
fi
done
else
$ORACRS/bin/crsctl stop crs
sleep 2
$PSEF|$GREP -v grep|$GREP 'ocssd.bin|crsd.bin' > /tmp/ocssd_ps
PROCESS=`$CAT /tmp/ocssd_ps`
if [ "X$PROCESS" != "X" ];
then
echo
$ECHO "Stop CRS stack failed on node \"$HOST\"";
echo
$RMRF /tmp/.ocssd
exit 1;
fi
fi
echo "CRS Stack Stopped";
echo
###########
#exit 0
###########
# Get OCR Disks, Change back their Ownerships
if [ -f "$ORA_LOC/ocr.loc" ];
then
BASEOCR=`$CAT "$ORA_LOC/ocr.loc"|$GREP 'ocrconfig_loc'|$CUT -d '=' -f2`;
MIRROCR=`$CAT "$ORA_LOC/ocr.loc"|$GREP 'ocrmirrorconfig_loc'|$CUT -d '=' -f2`;
if [ "X$BASEOCR" != "X" ];
then
[ -n "$1" ] && $ECHO "Base OCR: $BASEOCR";
if [ "X$RH" = "X" ];
then
$CHOWN $O_USER:$O_GROUP $BASEOCR;
else
for node in $NODE_LIST;
do
$RH $node "$CHOWN $O_USER:$O_GROUP $BASEOCR";
done
fi
if [ "X$MIRROCR" != "X" ];
then
[ -n "$1" ] && $ECHO "Mirror OCR: $MIRROCR";
if [ "X$RH" = "X" ];
then
$CHOWN $O_USER:$O_GROUP $MIRROCR;
else
for node in $NODE_LIST;
do
$RH $node "$CHOWN $O_USER:$O_GROUP $MIRROCR";
done
fi
fi
fi
fi
##########
#exit 0;
##########
# Delete Oralce Inventory
echo "Remove Oracle Inventory $ORAINST ..."
if [ -d $ORAINST ];
then
if [ "X$RH" != "X" ];
then
for node in $NODE_LIST;
do
$ECHO "Delete Oracle Inventory on \"$node\"";
$RH $node "$RMRF $ORAINST; $RMRF $INST_IN";
echo
done
else
$RMRF $ORAINST
$RMRF $INST_IN
fi
fi
echo
# Delete CRS Software
echo "Remove CRS Software ..."
if [ -d "$ORACRS" ];
then
if [ "X$RH" != "X" ];
then
for node in $NODE_LIST;
do
$ECHO "Delete CRS Software on \"$node\"";
$RH $node "$RMRF $ORACRS"
echo
done
else
$RMRF $ORACRS
fi
fi
echo
# Get CRS related Init Files
L_EVMD=`$CAT /etc/inittab|$GREP "init.evmd"|$CUT -d ":" -f1|$GREP -v "#"`;
L_CSSD=`$CAT /etc/inittab|$GREP "init.cssd"|$CUT -d ":" -f1|$GREP -v "#"`;
L_CRSD=`$CAT /etc/inittab|$GREP "init.crsd"|$CUT -d ":" -f1|$GREP -v "#"`;
# Use "rmitab" to remove these items from inittab file on AIX
if [ "X$OS" = "XAIX" ];
then
$ECHO "Remove CRS related items from /etc/inittab file ...";
if [ "X$RH" = "X" ];
then
[ -n "$L_EVMD" ] && $RMITAB $L_EVMD;
[ -n "$L_CSSD" ] && $RMITAB $L_CSSD;
[ -n "$L_CRSD" ] && $RMITAB $L_CRSD;
else
for node in $NODE_LIST;
do
$RH $node "[ -n \"$L_EVMD\" ] && $RMITAB $L_EVMD; \
[ -n \"$L_CSSD\" ] && $RMITAB $L_CSSD; \
[ -n \"$L_CRSD\" ] && $RMITAB $L_CRSD; "
done
fi
echo
fi
#add by ricky
sed '/init.evmd/,/init.crsd/d' /etc/inittab > /tmp/inittab.tmp
mv /etc/inittab /etc/inittab.org
mv /tmp/inittab.tmp /etc/inittab
# Remove CRS Autostart Init Files
echo "Remove CRS related init files ...";
if [ "X$RH" = "X" ];
then
[ -f "$CONF/init.crsd" ] && $RMRF $CONF/init.crsd ;
[ -f "$CONF/init.crs" ] && $RMRF $CONF/init.crs ;
[ -f "$CONF/init.cssd" ] && $RMRF $CONF/init.cssd ;
[ -f "$CONF/init.evmd" ] && $RMRF $CONF/init.evmd ;
else
for node in $NODE_LIST;
do
$RH $node "[ -f \"$CONF/init.crsd\" ] && $RMRF $CONF/init.crsd; \
[ -f \"$CONF/init.crs\" ] && $RMRF $CONF/init.crs ; \
[ -f \"$CONF/init.cssd\" ] && $RMRF $CONF/init.cssd; \
[ -f \"$CONF/init.evmd\" ] && $RMRF $CONF/init.evmd; "
done
fi
echo
# Backup Platform depended Cluster Libraries
#if [ "X$RH" = "X" ];
#then
# [ -d /opt/ORCLcluster ] && $MV /opt/ORCLcluster /opt/ORCLbackup0
#else
# for node in $NODE_LIST;
# do
# $RH $node "[ -d /opt/ORCLcluster ] && $MV /opt/ORCLcluster /opt/ORCLbackup0"
# done
#fi
# Remove CSS/CRS Socket Files
echo "Remove CSS/CRS socket files ...";
if [ "X$RH" = "X" ];
then
[ -d /usr/tmp/.oracle ] && $RMRF /usr/tmp/.oracle ;
[ -d /tmp/.oracle ] && $RMRF /tmp/.oracle ;
[ -d /var/tmp/.oracle ] && $RMRF /var/tmp/.oracle ;
else
for node in $NODE_LIST;
do
$RH $node "[ -d /usr/tmp/.oracle ] && $RMRF /usr/tmp/.oracle; \
[ -d /tmp/.oracle ] && $RMRF /tmp/.oracle; \
[ -d /var/tmp/.oracle ] && $RMRF /var/tmp/.oracle; "
done
fi
echo
# Delete oratab and other files
echo "Remove other oracle related files ..."
if [ "X$RH" = "X" ];
then
[ -f "$ORA_TAB" ] && $RMRF $ORA_TAB;
[ -d "$ORA_LOC" ] && $RMRF $ORA_LOC;
[ -f "$LOCALBIN/coraenv" ] && $RMRF $LOCALBIN/coraenv ;
[ -f "$LOCALBIN/oraenv" ] && $RMRF $LOCALBIN/oraenv ;
[ -f "$LOCALBIN/dbhome" ] && $RMRF $LOCALBIN/dbhome ;
else
for node in $NODE_LIST;
do
$RH $node "[ -f \"$ORA_TAB\" ] && $RMRF $ORA_TAB; \
[ -d \"$ORA_LOC\" ] && $RMRF $ORA_LOC; \
[ -f \"$LOCALBIN/coraenv\" ] && $RMRF $LOCALBIN/coraenv; \
[ -f \"$LOCALBIN/oraenv\" ] && $RMRF $LOCALBIN/oraenv ; \
[ -f \"$LOCALBIN/dbhome\" ] && $RMRF $LOCALBIN/dbhome ; "
done
fi
echo
# Clear OCR Files if CRS SW (No RAC) deleted on all cluster nodes
if [ "X$ORAHOME" = "X" ];
then
$ECHO "Oracle RAC does not installed, and CRS delete finished";
echo
if [ "X$BASEOCR" != "X" ];
then
if [ "X$RH" != "X" ];
then
$ECHO "Clear OCR BASE: $BASEOCR";
$DD if=/dev/zero of=$BASEOCR bs=1024k count=200
if [ "X$MIRROCR" != "X" ];
then
$ECHO "Clear OCR MIRROR: $MIRROCR";
$DD if=/dev/zero of=$MIRROCR bs=1024k count=200
fi
fi
else
$ECHO "Do not forget to clear the OCR after deletion on the last node";
[ -n "$BASEOCR" ] && $ECHO "BASE OCR: $BASEOCR";
[ -n "$MIRROCR" ] && $ECHO "MIRR OCR: $MIRROCR";
fi
echo
exit 0
fi
# Delete RAC software
echo "ORACLE RAC installed at \"$ORAHOME\"";
echo
echo "Remove ORALCE RAC ...";
if [ -d "$ORAHOME" ];
then
if [ "X$RH" != "X" ];
then
for node in $NODE_LIST;
do
$ECHO "Delete RAC Software on \"$node\"";
$RH $node "$RMRF $ORAHOME"
echo
done
else
$RMRF $ORAHOME
fi
if [ -d "ORAHOME2" ];
then
echo
$ECHO "Another ORACLE RAC installed at \"$ORAHOME2\"";
if [ "X$RH" != "X" ];
then
for node in $NODE_LIST;
do
$ECHO "Removing from \"$node\"";
$RH $node "$RMRF $ORAHOME2"
echo
done
else
$ECHO "Removing ..."
$RMRF $ORAHOME2
fi
fi
fi
echo
echo "CRS/RAC Delete finished";
echo
echo
# Cleare the OCR Content after deletion
if [ "X$RH" != "X" ];
then
$ECHO "Start clear the OCR device ...";
if [ "X$BASEOCR" != "X" ];
then
$ECHO "Clear OCR BASE: $BASEOCR";
$DD if=/dev/zero of=$BASEOCR bs=1024k count=200
if [ "X$MIRROCR" != "X" ];
then
$ECHO "Clear OCR MIRROR: $MIRROCR";
$DD if=/dev/zero of=$MIRROCR bs=1024k count=200
fi
fi
else
$ECHO "Do not forget to clear the OCR after deletion of the last node"
[ -n "$BASEOCR" ] && $ECHO "BASE OCR: $BASEOCR";
[ -n "$MIRROCR" ] && $ECHO "MIRR OCR: $MIRROCR";
fi
echo
# Can Add Directory Check Here
exit 0