#!/usr/bin/ksh
################################################################################
#
# @PRODUCT@ update scripts for Single or RAC database V1.0
#
# Upgrade Oracle from 10.1.0.4.0 to 10.1.0.5.0
# Upgrade Oracle OPatch from 1.0.0.0.55 to 1.0.0.0.57
# Install Oracle CPU October 2008 (7375686)
#
# @COPYRIGHT@
#
################################################################################
export ORACLE_HOME=/opt/oracle/server/10.1
export CRS_HOME=/opt/oracle/crs/10.1
SOURCE_DIR=`dirname $0`
SOURCE_DIR=`cd $SOURCE_DIR && pwd`
export SOURCE_DIR
INSTALL_LOG_DIR=/var/tmp/prof6_install
export INSTALL_LOG_DIR
HISTORY_LOG=$INSTALL_LOG_DIR/install_history.log
export HISTORY_LOG
CLUSTER=false
export CLUSTER
CLUSTER_NODE_ID=0
export CLUSTER_NODE_ID
SKIP_PATCHSET=false
SKIP_OPATCH=false
SKIP_CPU=false
export SKIP_PATCHSET
export SKIP_OPATCH
export SKIP_CPU
test ! -d $INSTALL_LOG_DIR && mkdir -p $INSTALL_LOG_DIR && chown root:other $INSTALL_LOG_DIR && chmod 777 $INSTALL_LOG_DIR
test -f $HISTORY_LOG && rm -f $HISTORY_LOG
touch $HISTORY_LOG
chown root:other $HISTORY_LOG
chmod 777 $HISTORY_LOG
# Copy all screen output to install_history.log file
# Thus all output can be found also from log file
tee -a $HISTORY_LOG >/dev/tty |&
exec 1>&p
# Redirect errout to stdout
exec 2>&1
echo "Script Started at `date /"+%Y-%m-%d %H:%M:%S/"`" >>$HISTORY_LOG
HOSTNAME=`uname -n`
if [ "$HOSTNAME" = "" ];then
echo "ERROR: Could not resolve hostname with command /"uname -n/"...please restart the setup"
exit 1
fi
###############################################################################
#
# Functions
#
###############################################################################
#
# Test RSH connection in clustered installations.
#
test_rsh_connection() {
echo "Testing RSH connection.../c"
rsh clnode2 "ls -la" >> /dev/null
if [ $? -eq 0 ]; then
echo "Done"
return 0
else
echo "ERROR: RSH connection to clnode2 is not working."
echo "ERROR: Please check /.rhosts and /etc/inet/inetd.conf files from clnode2."
exit 1
fi
}
###############################################################################
#
# Check OS, Set CLUSTER & CLUSTER_NODE_ID variables
#
###############################################################################
/usr/sbin/clinfo > /dev/null 2>&1
if [ $? -eq 0 ]; then
CLUSTER=true
PATH=$PATH:/usr/cluster/bin
export PATH
CLUSTER_NODE_ID=`/usr/sbin/clinfo -n` > /dev/null
NODE_COUNT=`/usr/cluster/bin/scha_cluster_get -O ALL_NODEIDS | wc -l` > /dev/null
if [ $NODE_COUNT -eq 4 ]; then
echo "ERROR: This installation does not support installations in multinode."
exit 1
elif [ $CLUSTER_NODE_ID -ne 1 ]; then
echo "ERROR: Installation must be started in node 1"
exit 1
fi
echo "Clustered Solaris detected with node id $CLUSTER_NODE_ID"
test_rsh_connection
else
echo "Non clustered Solaris detected"
fi
echo "Operating system check finished/n"
###############################################################################
#
# Pre-condition Check
#
###############################################################################
ORA_VER=`su - oracle -c "sqlplus -v"|grep .|awk '{print $3}'`
if [ "$ORA_VER" = "10.1.0.4.0" ];then
echo "Current Oracle Version $ORA_VER detected."
elif [ "$ORA_VER" = "10.1.0.5.0" ];then
echo "Current Oracle Version is already 10.1.0.5.0, Continue? Please answer Yes(Y) or No(N):/c"
while read answer
do
case $answer in
N|n)
echo "Cancelled by User."
exit 1
;;
Y|y)
SKIP_PATCHSET=true
break
;;
*)
echo "Please answer Yes(Y) or No(N):/c"
;;
esac
done
else
echo "Current Oracle Version is $ORA_VER, not 10.1.0.4.0. Can not upgrade to 10.1.0.5.0. Transaction exit !"
exit 1
fi
# Go on to check OPatch version
#OPATCH_VER=`su - oracle -c "$ORACLE_HOME/OPatch/opatch version"|grep "OPatch Version: "|awk '{print $3}'`
#if [ "$OPATCH_VER" = "1.0.0.0.55" ]; then
# echo "Current Oracle OPatch Version $OPATCH_VER detected."
#elif [ "$OPATCH_VER" = "1.0.0.0.57" ]; then
# echo "Current Oracle Opatch Version is already 1.0.0.0.57, Continue? Please answer Yes(Y) or No(N):/c"
# while read answer
# do
# case $answer in
# N|n)
# echo "Cancelled by User."
# exit 1
# ;;
# Y|y)
# SKIP_OPATCH=true
# break
# ;;
# *)
# echo "Please answer Yes(Y) or No(N):/c"
# ;;
# esac
# done
#else
# echo "Current Oracle OPatch Version is $OPATCH_VER, not 1.0.0.0.55. Can not upgrade to 1.0.0.0.57. Transaction exit !"
# exit 1
#fi
# Check cpu
su - oracle -c "$ORACLE_HOME/OPatch/opatch lsinventory"| grep 7375686 > /dev/null
if [ $? -eq 0 ]; then
echo "CPU Oct 2008 already installed. Continue? Please answer Yes(Y) or No(N):/c"
while read answer
do
case $answer in
N|n)
echo "Cancelled by User."
exit 1
;;
Y|y)
SKIP_CPU=true
break
;;
*)
echo "Please answer Yes(Y) or No(N):/c"
;;
esac
done
else
echo "CPU Oct 2008 not installed as expected."
fi
###############################################################################
#
#Free disk space check
#1. space for backup crs 800M
#2. space for backup database 1.8G
#3. space for unzip 10.1.0.5 patch 800M
#4. space for unzip cpuOct2008 100M
#
###############################################################################
if [ "$SKIP_PATCHSET" = "false" ];then
#Please specify BACKUP_DIR in a filesystem which has at least 2.5GB left free space.
#if this directory is shared by both nodes, free space should be doubled.
if [ "$BACKUP_DIR" = "" ];then
if [ "$CLUSTER" = "true" ];then
BACKUP_DIR=/global/clnode1/archive/backup
else
BACKUP_DIR=/var/tmp/backup
fi
export BACKUP_DIR
fi
ENOUGH_SPACE=true
BACKUP_DIR_ROOT=`echo $BACKUP_DIR|cut -d/ -f2`
if [ "$BACKUP_DIR_ROOT" = "global" ];then
FREE_SPACE=6291456
else
FREE_SPACE=3145728
fi
test ! -d $BACKUP_DIR && mkdir $BACKUP_DIR && chmod 666 $BACKUP_DIR
VAR_FREE1=`df -k $BACKUP_DIR|grep -v avail|awk '{print $4}'`
if [ "$CLUSTER" = "true" ];then
rsh clnode2 "test ! -d $BACKUP_DIR && mkdir $BACKUP_DIR && chmod 666 $BACKUP_DIR"
VAR_FREE2=`rsh clnode2 "df -k $BACKUP_DIR"|grep -v avail|awk '{print $4}'`
if [ $VAR_FREE1 -le $FREE_SPACE ] -o [ ]$VAR_FREE2 -le $FREE_SPACE ];then
echo "Not enough free space on $BACKUP_DIR, at least $FREE_SPACE KB, only $VAR_FREE1 KB on clnode1 and $VAR_FREE2 KB on clnode2 left."
ENOUGH_SPACE=false
else
echo "$BACKUP_DIR has $VAR_FREE1 KB on clnode1 and $VAR_FREE2 KB on clnode2 left."
fi
else
if [ $VAR_FREE1 -le $FREE_SPACE ];then
echo "Not enough free space on $BACKUP_DIR, at least $FREE_SPACE KB, only $VAR_FREE1 KB left."
ENOUGH_SPACE=false
else
echo "$BACKUP_DIR has $VAR_FREE1 KB left."
fi
fi
TMP_FREE=`df -k /tmp|grep -v avail|awk '{print $4}'`
if [ $TMP_FREE -le 1048576 ];then
echo "Not enough free space on /tmp, at least 1048576 KB, only $TMP_FREE KB left"
ENOUGH_SPACE=false
else
echo "/tmp has $TMP_FREE KB left."
fi
if [ "$ENOUGH_SPACE" = "false" ];then
echo "Please define BACKUP_DIR environment variable to specify the directory for backup that has enough freespace, and re-run the update script."
exit 1
fi
fi
#End of Free disk space check
echo "Environment Checking .... Passed! Ready to Update!"
echo "/nDebugging Informations:"
echo "SKIP_PATCHSET=$SKIP_PATCHSET"
echo "SKIP_OPATCH=$SKIP_OPATCH"
echo "SKIP_CPU=$SKIP_CPU"
echo "ENOUGH_SPACE=$ENOUGH_SPACE"
echo "INSTALL_LOG_DIR=$INSTALL_LOG_DIR"
echo "BACKUP_DIR=$BACKUP_DIR"
###############################################################################
#
# Oracle shutdown
#
###############################################################################
echo "/n**1** Shutting down Oracle"
if [ "$SKIP_PATCHSET" = "false" ];then
echo "Shutting down all oracle instances"
if [ "$CLUSTER" = "true" ]; then
echo "Stopping database.../c"
su - oracle -c "srvctl stop database -d nap3"
echo "Done."
echo "Stopping nodeapps.../c"
su - oracle -c "srvctl stop nodeapps -n clnode1"
echo ", clnode1 shutdown finished/c"
su - oracle -c "srvctl stop nodeapps -n clnode2"
echo ", clnode2 shutdown finished."
echo "Stopping crs daemon..."
/etc/init.d/init.crs stop
rsh clnode2 "/etc/init.d/init.crs stop"
else
/etc/init.d/dbora stop
fi
echo "Shutdown completed."
fi
###############################################################################
#
#Backup Oracle Software
#
###############################################################################
echo "/n**2** Backup Oracle Software"
if [ "$SKIP_PATCHSET" = "false" ]; then
if [ "$CLUSTER" = "true" ]; then
echo "Backup crs software on clnode1.../c"
tar -cvf $BACKUP_DIR/crs1.tar $CRS_HOME >>$HISTORY_LOG
if [ $? -eq 0 ]; then
echo "Done."
else
echo "Failed."
exit 1
fi
echo "Backup crs software on clnode2.../c"
rsh clnode2 "tar -cvf $BACKUP_DIR/crs2.tar $CRS_HOME" >>$HISTORY_LOG
if [ $? -eq 0 ]; then
echo "Done."
else
echo "Failed."
exit 1
fi
echo "Backup oracle software on clnode1.../c"
tar -cvf $BACKUP_DIR/server1.tar $ORACLE_HOME >>$HISTORY_LOG
if [ $? -eq 0 ]; then
echo "Done."
else
echo "Failed."
exit 1
fi
echo "Backup oracle software on clnode2.../c"
rsh clnode2 "tar -cvf $BACKUP_DIR/server2.tar $ORACLE_HOME" >>$HISTORY_LOG
if [ $? -eq 0 ]; then
echo "Done."
else
echo "Failed."
exit 1
fi
else
echo "Backup oracle software .../c"
tar -cvf $BACKUP_DIR/server10.1.tar $ORACLE_HOME >>$HISTORY_LOG
if [ $? -eq 0 ]; then
echo "Done."
else
echo "Failed."
exit 1
fi
fi
elif [ "$SKIP_PATCHSET" = "true" ]; then
echo "Skip Oracle software backup."
fi
#End of Backup Oracle Software
echo "/nOracle backup finished!"
#Backup old OPatch
echo "/n**3** Backup old OPatch tool"
if [ "$SKIP_OPATCH" = "false" ];then
OPATCH_VER=`su - oracle -c "$ORACLE_HOME/OPatch/opatch version"|grep "OPatch Version: "|awk '{print $3}'`
if [ "$CLUSTER" = "true" ]; then
cp -r $ORACLE_HOME/OPatch $ORACLE_HOME/OPatch_bak_$OPATCH_VER
echo "clonde1 OPatch $OPATCH_VER Backup completed successfully! "
rsh clnode2 "cp -r $ORACLE_HOME/OPatch $ORACLE_HOME/OPatch_bak_$OPATCH_VER"
echo "clonde2 OPatch $OPATCH_VER Backup completed successfully! "
else
# /etc/init.d/dbora stop
cp -r $ORACLE_HOME/OPatch $ORACLE_HOME/OPatch_bak_$OPATCH_VER
echo "OPatch $OPATCH_VER Backup completed successfully! "
fi
else
echo "Skip OPatch backup."
fi
###############################################################################
#
# 1. Oracle upgrade to 10.1.0.5.0
# 2. Oracle OPatch update to 10.0.0.0.57
# 3. Oracle cpuOct2008 apply
#
###############################################################################
# 1. Oracle upgrade to 10.1.0.5.0
#unpacking file and install patch
echo "/n**4** Upgrade Oracle Software"
if [ "$SKIP_PATCHSET" = "false" ];then
echo "Unpacking Oracle 10.1.0.5.0 patch..../c"
if [ "$CLUSTER" = "true" ]; then
su - oracle -c "cd /tmp; unzip -o $SOURCE_DIR/patchset/p4505133_10105_SOLARIS64.zip" >> $HISTORY_LOG
su - oracle -c "cd /tmp/Disk1/;./runInstaller -silent -responseFile $SOURCE_DIR/response/rac_crs.rsp"| tee -a /tmp/oracle10.1.0.5.log
echo "Starting to patch Oracle database home"
su - oracle -c "cd /tmp/Disk1/;./runInstaller -silent -responseFile $SOURCE_DIR/response/rac_db.rsp"| tee -a /tmp/oracle10.1.0.5.log
echo "Running db root.sh on clnode1"
$ORACLE_HOME/root.sh <<@EOF
Y
Y
Y
@EOF
echo "Running db root.sh on clnode2"
rsh clnode2 "$ORACLE_HOME/root.sh <<@EOF
Y
Y
Y
@EOF"
else
su - oracle -c "cd /tmp; unzip -o $SOURCE_DIR/patchset/p4505133_10105_SOLARIS64.zip" >> $HISTORY_LOG
su - oracle -c "cd /tmp/Disk1;./runInstaller -silent -responseFile $SOURCE_DIR/response/single.rsp"| tee -a /tmp/oracle10.1.0.5.log
echo "Running db root.sh"
$ORACLE_HOME/root.sh <<@EOF
Y
Y
Y
@EOF
fi
echo "Done"
#Verify if Oracle is updated successfully
ORA_VER=`su - oracle -c "sqlplus -v"|grep .|awk '{print $3}'`
if [ "$ORA_VER" != "10.1.0.5.0" ];then
echo "Oracle upgrade failed! Transaction abort !"
exit 1
else
echo "/nOracle database software updated successfully! Need executing sqls..."
fi
#Start Upgrade Oracle 10.1.0.5
if [ "$CLUSTER" = "true" ]; then
/etc/init.d/init.crs start
echo "Sleeping 300 seconds to wait crs startup"
sleep 300
su - oracle -c "srvctl start nodeapps -n clnode1"
su - oracle -c "srvctl start instance -d nap3 -i nap3x1"
su - oracle -c "sqlplus /nolog" <<@EOF
CONNECT / AS SYSDBA
ALTER SYSTEM SET CLUSTER_DATABASE=FALSE SCOPE=spfile;
SHUTDOWN IMMEDIATE
STARTUP UPGRADE
SPOOL patch.log
@$ORACLE_HOME/rdbms/admin/catpatch.sql
SPOOL OFF
SHUTDOWN IMMEDIATE
STARTUP
@$ORACLE_HOME/rdbms/admin/utlrp.sql
ALTER SYSTEM SET CLUSTER_DATABASE=TRUE SCOPE=spfile;
SHUTDOWN IMMEDIATE
STARTUP
@EOF
else
su - oracle -c "sqlplus /nolog" <<@EOF
CONNECT / AS SYSDBA
STARTUP UPGRADE
SPOOL patch.log
@$ORACLE_HOME/rdbms/admin/catpatch.sql
SPOOL OFF
SHUTDOWN IMMEDIATE
STARTUP
@$ORACLE_HOME/rdbms/admin/utlrp.sql
@EOF
fi
#Running changePerm.sh script on an Oracle database server home
su - oracle -c "cd $ORACLE_HOME/install;./changePerm.sh <<@EOF
y
@EOF"
if [ "$CLUSTER" = "true" ]; then
rsh clnode2 "su - oracle -c /"cd $ORACLE_HOME/install;./changePerm.sh <<@EOF
y
@EOF/""
fi
else
echo "Skip Oracle Patchset 10.1.0.5 installation."
fi
# 2. Oracle OPatch update to 10.0.0.0.57
echo "/n**5** Upgrade OPatch tool"
if [ "$SKIP_OPATCH" = "false" ];then
if [ "$CLUSTER" = "true" ]; then
su - oracle -c "srvctl stop database -d nap3"
su - oracle -c "srvctl stop nodeapps -n clnode1"
su - oracle -c "srvctl stop nodeapps -n clnode2"
/etc/init.d/init.crs stop
rsh clnode2 "/etc/init.d/init.crs stop"
cd $ORACLE_HOME && unzip -o $SOURCE_DIR/patchset/p2617419_10102_GENERIC.zip >> $HISTORY_LOG
#should check if clnode1 is already 1.0.0.0.57
echo "clonde1 OPatch Upgrade completed successfully! Current OPatch version is 1.0.0.0.57."
rcp $SOURCE_DIR/patchset/p2617419_10102_GENERIC.zip clnode2:/tmp
rsh clnode2 "cd $ORACLE_HOME && unzip -o /tmp/p2617419_10102_GENERIC.zip"
#should check if clnode2 is already 1.0.0.0.57
echo "clnode2 OPatch Upgrade completed successfully! Current OPatch version is 1.0.0.0.57."
else
/etc/init.d/dbora stop
mv $ORACLE_HOME/OPatch $ORACLE_HOME/OPatch_bak_1.0.0.0.55
#OPatch update
cd $ORACLE_HOME && unzip -o $SOURCE_DIR/patchset/p2617419_10102_GENERIC.zip >> $HISTORY_LOG
echo "OPatch Upgrade completed successfully! Current OPatch version is 1.0.0.0.57."
fi
else
echo "Skip OPatch installation."
fi
# 3. Oracle cpuOct2008 apply p7375686_10105_SOLARIS64.zip
echo "/n**6** Apply cpuOct2008"
if [ "$SKIP_CPU" = "false" ]; then
echo "Updating system with CPU Oct 2008"
echo "Unpacking patch.../c"
su - oracle -c "cd /tmp; unzip -o $SOURCE_DIR/patchset/p7375686_10105_SOLARIS64.zip" >> $HISTORY_LOG
echo "Done"
if [ "$CLUSTER" = "true" ]; then
su - oracle -c ". /etc/oracle_env.sh;cd /tmp/7375686; $ORACLE_HOME/OPatch/opatch apply -local <<@EOF
Y
@EOF"
su - oracle -c "/tmp/7375686/custom/scripts/post"
echo "/ncpuOct2008 applied successfully in clnode1! "
rcp $SOURCE_DIR/patchset/p7375686_10105_SOLARIS64.zip clnode2:/tmp
rsh clnode2 "su - oracle -c /"cd /tmp; unzip -o p7375686_10105_SOLARIS64.zip/""
rsh clnode2 "su - oracle -c /". /etc/oracle_env.sh;cd /tmp/7375686; $ORACLE_HOME/OPatch/opatch apply -local <<@EOF
Y
@EOF/""
rsh clnode2 "su - oracle -c /"/tmp/7375686/custom/scripts/post/""
echo "/ncpuOct2008 applied successfully in clnode1! "
else
su - oracle -c ". /etc/oracle_env.sh;cd /tmp/7375686; $ORACLE_HOME/OPatch/opatch apply <<@EOF
Y
@EOF"
. /etc/oracle_env.sh; sh /tmp/7375686/cpu_root.sh <<@EOF
Y
@EOF
echo "/ncpuOct2008 applied successfully in clnode1! "
fi
else
echo "Skip CPU 2008 October installation."
fi
###############################################################################
#
# Finalizing Oracle patching
#
###############################################################################
if [ "$SKIP_CPU" = "false" ];then
echo "/nFinalizing Oracle patching.../c"
if [ "$CLUSTER" = "true" ]; then
echo "/nStarting Oracle CRS in clnode1..."
/etc/init.d/init.crs start
echo "/nWaiting 300 seconds CRS startup..."
sleep 300
su - oracle -c "srvctl start nodeapps -n clnode1"
su - oracle -c "srvctl start instance -d nap3 -i nap3x1"
su - oracle -c ". /etc/oracle_env.sh;cd /$ORACLE_HOME/cpu/CPUOct2008; sqlplus /"/ as sysdba/" <<@EOF
@catcpu.sql
@$ORACLE_HOME/rdbms/admin/utlrp.sql
shutdown immediate
exit
@EOF"
echo "Finalizing done."
else
su - oracle -c ". /etc/oracle_env.sh;cd /$ORACLE_HOME/cpu/CPUOct2008; sqlplus /"/ as sysdba/" <<@EOF
startup
@catcpu.sql
@$ORACLE_HOME/rdbms/admin/utlrp.sql
shutdown
exit
@EOF"
echo "Finalizing done."
fi
fi
#Start All Oracle Service
if [ "$SKIP_PATCHSET" = "false" -o "$SKIP_CPU" = "false" ]; then
if [ "$CLUSTER" = "true" ]; then
su - oracle -c "srvctl start instance -d nap3 -i nap3x1"
rsh clnode2 "/etc/init.d/init.crs start"
echo "Waiting 300 seconds CRS startup..."
sleep 300
su - oracle -c "srvctl start nodeapps -n clnode2"
su - oracle -c "srvctl start instance -d nap3 -i nap3x2"
else
/etc/init.d/dbora start
fi
fi
echo "Oracle Update Finished."
su - oracle -c "/opt/oracle/crs/10.1/bin/crs_stat -t"
echo "Script Ended at `date /"+%Y-%m-%d %H:%M:%S/"`" >>$HISTORY_LOG