Question:
> Help,
> We are trying to get a script working to do shutdown/startup for
backups
> of an 8i db.
>
> Have tried something like this for the shutdown (similar for startup):
>
> su - oracle -c "lsnrctl stop" >> /var/log/oracle
> rm -f /var/lock/subsys/oracle
> su - oracle -c dbshut >> /var/log/oracle
>
> The listener does stop (start), as seen from /var/log/oracle, but
I
> cannot get the
> dbshut (dbstart) to actually stop the database.
>
> We do have all instances defined in the oratab file, but I assume
that
> this file is only looked at if/when the server is rebooted. What
is the
> proper syntax to get the instance names in the dbshut (dbstart) command
> line, or is there some other problem?
>
> Thanks!
>
> --
> Greg M. Silver <[email protected]>
> UofMN Cancer Center Computing
>
> --
> Greg M. Silver <[email protected]>
> UofMN Cancer Center Computing
>
>
Answer:
Hi,
First to start/stop the listener you have to specify the name of the
listener
su - oracle -c "lsnrctl start listener_prod"
You better write a small schell script to stop the db, because if there
is
a Oracle process
running the db will not shutdown until this process has ended unless
you do
a shutdown abort but
in this case you have to start/stop the database again with normal
shutdown
because taking a backup
after a shutdown abort will give you an unconsistent backup
exemple of shell script
#!/bin/ksh
#
# Author : DEBRUS Frederic
# Version : 2.0
# File : DbStop
# Param : dbname
#
error()
{
echo `date` " :: $*"
exit 2
}
usage()
{
echo "Usage : $0 dbname"
exit ${1:1}
}
wait_process()
{
Waited=0
echo `date` " : Wait $1 process for $2 to complete\c"
while [ $Waited -lt $2 ]
do
echo ".\c"
ps -p "$1" >/dev/null 2>&1 || break
sleep 20
Waited=`expr $Waited + 20`
done
echo "\n"
if [ $Waited -ge $2 ]
then
echo `date` " :: $3 Process failed to complete"
fail_process=1
else
echo `date` " : $3 Process complete"
fail_process=0
fi
}
set_database()
{
#
# Change the oratab location to reflect your installation
#
ORATAB=/var/opt/oracle/oratab
DBName="$1"
grep $DBName $ORATAB >/dev/null 2>&1 || error "$DBName is not a
valid
Database"
ORAENV_ASK=NO
ORACLE_SID=$DBName
export ORAENV_ASK ORACLE_SID
. oraenv
ORAENV_ASK=
}
start_database()
{
su oracle -c "svrmgrl <<EOF
connect internal
startup
exit
EOF"
}
stop_database()
{
su oracle -c "svrmgrl <<EOF
connect internal
shutdown $1
exit
EOF" > /dev/null 2>&1 &
wait_process $! $2 "Shutdown $1"
}
# Main
#
# Test if param is there
#
[ "$#" -lt 1 ] && usage
#
# Set the Oracle Instance to $1
#
set_database $1
#
# Try to shutdown with immediate option
#
echo `date` " : Trying to shutdown immediate"
stop_database immediate 600
#
# If shutdown fail
#
if [ "$fail_process" -eq "1" ]
then
#
# Try to shutdown with abort option
#
echo `date` " :: Shutdown immediate did not work, trying abort
now"
stop_database abort 400
[ "$fail_process" -eq "1" ] && error Failed to shutdown
abort
#
# Restart database
#
echo `date` " : Shutdown abort done, restart now"
start_database
#
# Try to shutdown with immediate option
#
echo `date` " : Database started, shutdown immediate now"
stop_database immediate 400
[ "$fail_process" -eq "1" ] && error Failed to shutdown
immediate
fi
echo `date` " : Shutdown immediate done"
Hope this help
Ciao