Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> RMAN DB startup/shutdown scripts

RMAN DB startup/shutdown scripts

From: Simon Waibale <waibals_at_mtn.co.ug>
Date: Thu, 04 Jul 2002 05:03:21 -0800
Message-ID: <F001.0048FC24.20020704050321@fatcity.com>


Hi Gurus,
Trying to automate cold backup of DB using rman/veritas. My DB shutdown/startup procedures in the *.sh script are broken. Below is the script and corresponding log. P'se advice on any breakages -thanking you all.

====================================*.sh=====================================


#!/bin/sh
# $Header: cold_rmandb_backup.sh,v 1.3 2000/02/17 21:39:42 integ Exp $
#
#bcpyrght
#***************************************************************************
#* $VRTScprght: Copyright 1993 - 2000 VERITAS Software Corporation, All
Rights Reserved $ *
#***************************************************************************
#ecpyrght
#
# ---------------------------------------------------------------------------
# cold_rmandb_backup.sh
# ---------------------------------------------------------------------------
# This script uses Recovery Manager to take a cold (consistent) database
# backup. A cold backup is one where the database is shutdown cleanly before
# performing the backup. It is assumed that this script will be executed
# by user root. In order for the Oracle utilities, SQLPLUSl and rman, to
# work properly we switch user (su -) to the oracle dba account before
# each execution. If this script runs under a user account that has Oracle
# dba privilege you should remove the switch user logic.
#
# Note: As written, this script will bring down the target database and
# open it when done.
# ---------------------------------------------------------------------------

# ---------------------------------------------------------------------------
# Put output in <this file name>.out. Change as desired.
# Note: output directory requires write permission.
# ---------------------------------------------------------------------------

OUTF=${0}.out

# ---------------------------------------------------------------------------
# You may want to delete the output file so that backup information does
# not accumulate. If not, delete the following lines.
# ---------------------------------------------------------------------------

if [ -f "$OUTF" ]
then

        rm -f "$OUTF"
fi

{ # output block

echo "`date` ----------------Beginning of Script------------"
echo "Script name: $0"

# ---------------------------------------------------------------------------
# Replace /db/oracle/product/8.0.5, below, with the Oracle home path.
# ---------------------------------------------------------------------------

ORACLE_HOME=/ops/product/817
export ORACLE_HOME

# ---------------------------------------------------------------------------
# Replace ORA805, below, with the Oracle SID of the target database.
# ---------------------------------------------------------------------------

ORACLE_SID=DEMO
export ORACLE_SID

# ---------------------------------------------------------------------------
# Replace ora805, below, with the Oracle DBA user id (account).
# ---------------------------------------------------------------------------

ORACLE_USER=oracle

# ---------------------------------------------------------------------------
# Replace ${ORACLE_HOME}/scripts with the NetBackup Oracle script path.
# Since subsequent installs or deinstalls will remove this file, you will
# want to move this script from its installed location before making updates.
# ---------------------------------------------------------------------------

NB_ORA_SCRIPTS=/usr/scripts/rman

# ---------------------------------------------------------------------------
# Set the Oracle Server Manager name.
# ---------------------------------------------------------------------------

SQLPLUS=sqlplus

# ---------------------------------------------------------------------------
# Set the Oracle Recovery Manager name.
# ---------------------------------------------------------------------------

RMAN=rman

# ---------------------------------------------------------------------------
# Print out the value of the variables set by this script.
# ---------------------------------------------------------------------------

echo

echo   "RMAN: $RMAN"
echo   "SQLPLUS: $SQLPLUS"
echo   "ORACLE_SID: $ORACLE_SID"
echo   "ORACLE_USER: $ORACLE_USER"
echo   "ORACLE_HOME: $ORACLE_HOME"
echo   "NB_ORA_SCRIPTS: $NB_ORA_SCRIPTS"


# ---------------------------------------------------------------------------
# Print out the value of the variables set by bphdb.
# ---------------------------------------------------------------------------

echo

echo   "NB_ORA_FULL: $NB_ORA_FULL"
echo   "NB_ORA_INCR: $NB_ORA_INCR"
echo   "NB_ORA_CINC: $NB_ORA_CINC"
echo   "NB_ORA_SERV: $NB_ORA_SERV"
echo   "NB_ORA_CLASS: $NB_ORA_CLASS"
echo   "NB_ORA_PC_SCHED: $NB_ORA_PC_SCHED"
echo   "NB_ORA_SCHEDULED: $NB_ORA_SCHEDULED"
echo   "NB_ORA_USER_INITIATED: $NB_ORA_USER_INITIATED"


# ---------------------------------------------------------------------------
# Call Server Manager to shutdown the target database in immediate priority.
# This lets current calls to the database complete, but prevents further
# logons or calls.
#
# The shutdown-startup logic of this script can be commented out if you know
# that the database will always be mounted and in a consistent state before
# this script is executed.
# ---------------------------------------------------------------------------

echo

echo "% ${ORACLE_HOME}/bin/$SQLPLUS"
echo "connect internal"
echo "shutdown immediate"
echo "exit"

echo

su -f $ORACLE_USER -c "
. /ops/setenv demo
ORACLE_SID=$ORACLE_SID
export ORACLE_SID
${ORACLE_HOME}/bin/$SQLPLUS '/as sysdba' <<! shutdown immediate
exit
!
"

# ---------------------------------------------------------------------------
# Startup the database in case it had crashed or was not shutdown cleanly
# prior to starting this script. This will perform a crash recover if
# it is needed. Use the RESTRICT option because we are going to shutdown
# again right away and we don't want to let users in during the short
# interval. The default init<SID>.ora file will be used by startup. If it was
# moved or the name was changed use the pfile= option on the startup command.
# ---------------------------------------------------------------------------

echo

echo "% ${ORACLE_HOME}/bin/$SQLPLUS"
echo "connect internal"
echo "startup restrict open"
echo "shutdown immediate"
echo "exit"

echo

#su -f $ORACLE_USER -c "
#. /ops/setenv demo
#ORACLE_SID=$ORACLE_SID
#export ORACLE_SID
#${ORACLE_HOME}/bin/$SQLPLUS '/as sysdba' <<!
##startup pfile='${ORACLE_HOME}/admin/rmandb/pfile/initrmandb.ora' restrict
open
#startup pfile='${ORACLE_HOME}/admin/demo/pfile/initdemo1.ora' restrict open
#shutdown immediate
#exit
#!
#"

# ---------------------------------------------------------------------------
# Now we know that the database is cleanly closed and is ready for a
# cold backup. RMAN requires that the database be started and mounted
# to perform a backup.
# ---------------------------------------------------------------------------

echo

echo "% ${ORACLE_HOME}/bin/$SQLPLUS"
echo "connect internal"
echo "startup mount"
echo "exit"

echo

su -f $ORACLE_USER -c "
. /ops/setenv demo
ORACLE_SID=$ORACLE_SID
export ORACLE_SID
${ORACLE_HOME}/bin/$SQLPLUS '/as sysdba' <<! startup mount pfile='${ORACLE_HOME}/admin/demo/pfile/initdemo1.ora' exit
!
"

echo

if [ "$NB_ORA_INCR" = "1" ]
then

        echo "cold database differential incremental backup requested"         

CMDFILE=${NB_ORA_SCRIPTS}/cold_database_backup_level1_differential.rcv

elif [ "$NB_ORA_CINC" = "1" ]
then

	echo "cold database cumulative incremental backup requested"
	CMDFILE=${NB_ORA_SCRIPTS}/cold_database_backup_level1_cumulative.rcv

else # default
	echo "cold database backup requested (incremental level 0)"
	CMDFILE=${NB_ORA_SCRIPTS}/cold_rmandb_backup_level0.rcv
fi

# ---------------------------------------------------------------------------
# Call Recovery Manager to initiate the backup. This example does not use a
# Recovery Catalog. If you chose to use one, remove the option, nocatalog,
# from the rman command line below and add a 'connect rcvcat' statement to
# the corresponding command file ($CMDFILE). An alternative to putting the
# connect statements in the command file would be to add them to the rman
# command line.
#
# Note: Any environment variables needed at run time by RMAN or $CMDFILE
# must be set and exported within the switch user (su) command.
# ---------------------------------------------------------------------------

echo
echo "% ${ORACLE_HOME}/bin/$RMAN nocatalog cmdfile '$CMDFILE'" echo

su -f $ORACLE_USER -c "
. /ops/setenv demo
ORACLE_SID=$ORACLE_SID
export ORACLE_SID
#${ORACLE_HOME}/bin/$RMAN catalog 'rman_db1/rman_db1_at_testdb' cmdfile
"$CMDFILE"
${ORACLE_HOME}/bin/$RMAN nocatalog cmdfile "$CMDFILE" "
RETURN_STATUS=$? echo

echo "`date` ----------------End of Script------------------"
echo
echo "exit $RETURN_STATUS"
exit $RETURN_STATUS

} >> $OUTF

=================================EOF(*.sh)===================================

=================================*.sh.out====================================

Wed Jul  3 15:54:33 EAT 2002 ----------------Beginning of Script------------
Script name: ./cold_rmandb_backup.sh

RMAN: rman
SQLPLUS: sqlplus

ORACLE_SID: DEMO
ORACLE_USER: oracle
ORACLE_HOME: /ops/product/817
NB_ORA_SCRIPTS: /usr/scripts/rman

NB_ORA_FULL: 
NB_ORA_INCR: 
NB_ORA_CINC: 
NB_ORA_SERV: 
NB_ORA_CLASS: 
NB_ORA_PC_SCHED: 

NB_ORA_SCHEDULED:
NB_ORA_USER_INITIATED: % /ops/product/817/bin/sqlplus
connect internal
shutdown immediate
exit

SQL*Plus: Release 8.1.7.0.0 - Production on Wed Jul 3 15:54:33 2002

(c) Copyright 2000 Oracle Corporation. All rights reserved.

Connected to an idle instance.

SQL> ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist Compaq Tru64 UNIX Error: 2: No such file or directory SQL> Disconnected

% /ops/product/817/bin/sqlplus
connect internal
startup restrict open
shutdown immediate
exit

% /ops/product/817/bin/sqlplus
connect internal
startup mount
exit

SQL*Plus: Release 8.1.7.0.0 - Production on Wed Jul 3 15:54:34 2002

(c) Copyright 2000 Oracle Corporation. All rights reserved.

Connected to an idle instance.

SQL> ORACLE instance started.

Total System Global Area 216716260 bytes

Fixed Size		     103396 bytes
Variable Size		  114589696 bytes
Database Buffers	  101842944 bytes
Redo Buffers		     180224 bytes

ORA-01619: thread 1 is mounted by another instance

SQL> Disconnected

cold database backup requested (incremental level 0)

% /ops/product/817/bin/rman nocatalog cmdfile '/usr/scripts/rman/cold_rmandb_backup_level0.rcv'

Recovery Manager: Release 8.1.7.0.0 - Production

RMAN> # $Header: cold_database_backup_level0.rcv,v 1.5 2000/02/17 21:39:45 integ Exp $

2> #
3> #bcpyrght
4>

#***************************************************************************
5> #* $VRTScprght: Copyright 1993 - 2000 VERITAS Software Corporation, All Rights Reserved $ *
6>
#***************************************************************************
7> #ecpyrght
8> #
9> #
---------------------------------------------------------------------------
10> #  		cold_rmandb_backup_level0.rcv

11> #
12> #
13> #  Backs up the whole database.  This backup is part of the incremental
14> #  strategy (this means it can have incremental backups of levels > 0
15> #  applied to it).
16> #
17> #  We do not need to explicitly request the control file to be included
18> #  in this backup, as it is automatically included each time file 1 of
19> #  the system tablespace is backed up (the inference: as it is a whole
20> #  database backup, file 1 of the system tablespace will be backed up,
21> #  hence the controlfile will also be included automatically).
22> #
23> #  Typically, a level 0 backup would be done at least once a week.
24> #
25> #  The scenario assumes:
26> #     o you want to perform a level 0 backup
27> #     o you are backing your database up to two tape drives
28> #     o you want each backup set to include a maximum of 5 files
29> #     o you wish to include offline datafiles, and read-only tablespaces,
30> #       in the backup
31> #     o you want the backup to terminate if any files are not
32> #       accessible
33> #     o you want to open the database after the backup completes
34> #     o you are not using a Recovery Catalog
35> #     o you are using a TNS alias name for the target database
36> #
37> #  Note that the format string is constructed to guarantee uniqueness and
38> #  to enhance NetBackup for Oracle backup and restore performance. 
39> #
40> #  The connect statements could be part of the rman command line in the
41> #  Oracle script file that calls this script. They were put here so that
42> #  the passwords could be protected by setting file permissions to only
43> #  allow the Oracle dba access.
44> #
45> #  Add the following connect statement if using a Recovery Catalog.
46> #      connect rcvcat '<user>/<passwd>@<TNS alias>'
47> #
48> #  Modify the target connect statement according to the following syntax:
49> #      connect target '<user>/<passwd>@<TNS alias>'
50> #
51> #  Script run by:
52> #      rman nocatalog cmdfile cold_database_backup_level0.rcv
53> #
54> #
---------------------------------------------------------------------------
55> 
56> connect target 'internal/oracle_at_demo'
57> 
58> run {
59> # Cold database level 0 backup 
60> allocate channel t2 type 'SBT_TAPE';
61> backup
62>   incremental level 0
63>   tag cold_rmandb_bk_level0
64>   filesperset 5
65>   # Recommended format
66>   format 'db_%s_rmandb_%p_%t'
67>     (database);
68> 
69> # now that the backup is complete, open the db.
70> sql 'alter database open';

71> }
72>
RMAN-06005: connected to target database: DEMO (DBID=3158995415) RMAN-06009: using target database controlfile instead of recovery catalog
RMAN-03022: compiling command: allocate
RMAN-03023: executing command: allocate
RMAN-08030: allocated channel: t2
RMAN-08500: channel t2: sid=11 devtype=SBT_TAPE
RMAN-08526: channel t2: VERITAS NetBackup for Oracle8 - Release 3.4GA
(030800)
RMAN-03022: compiling command: backup
RMAN-03023: executing command: backup
RMAN-08008: channel t2: starting incremental level 0 datafile backupset
RMAN-08502: set_count=168 set_stamp=466271699 creation_time=03/07/2002
15:54:59
RMAN-08010: channel t2: specifying datafile(s) in backupset
RMAN-08522: input datafile fno=00001 name=/data1/oradata/demo/system1.dbf
RMAN-08011: including current controlfile in backupset
RMAN-08522: input datafile fno=00005 name=/data1/oradata/demo/users1.dbf
RMAN-08522: input datafile fno=00004 name=/data1/oradata/demo/temp1.dbf
RMAN-08522: input datafile fno=00007

name=/data1/oradata/demo/oem_repository.dbf RMAN-08013: channel t2: piece 1 created
RMAN-08503: piece handle=db_168_rmandb_1_466271699 comment=API Version 2.0,MMS Version 3.2.0.0
RMAN-08525: backup set complete, elapsed time: 00:03:06
RMAN-08008: channel t2: starting incremental level 0 datafile backupset
RMAN-08502: set_count=169 set_stamp=466271885 creation_time=03/07/2002
15:58:05
RMAN-08010: channel t2: specifying datafile(s) in backupset
RMAN-08522: input datafile fno=00003 name=/data1/oradata/demo/rbs1.dbf
RMAN-08522: input datafile fno=00002 name=/data1/oradata/demo/tools1.dbf
RMAN-08522: input datafile fno=00006 name=/data1/oradata/demo/indx1.dbf
RMAN-08013: channel t2: piece 1 created
RMAN-08503: piece handle=db_169_rmandb_1_466271885 comment=API Version
2.0,MMS Version 3.2.0.0
RMAN-08525: backup set complete, elapsed time: 00:01:05
RMAN-03022: compiling command: sql
RMAN-06162: sql statement: alter database open
RMAN-03023: executing command: sql
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03006: non-retryable error occurred during execution of command: sql
RMAN-07004: unhandled exception during command execution on channel default
RMAN-20000: abnormal termination of job step
RMAN-11003: failure during parse/execution of SQL statement: alter database
open
RMAN-11001: Oracle Error: ORA-01531: a database already open by the instance

Recovery Manager complete.

Wed Jul  3 15:59:10 EAT 2002 ----------------End of Script------------------

exit 1

=======================================EOF(*.sh.out)=========================

-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.com
-- 
Author: Simon Waibale
  INET: waibals_at_mtn.co.ug

Fat City Network Services    -- (858) 538-5051  FAX: (858) 538-5051
San Diego, California        -- Public Internet access / Mailing Lists
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).
Received on Thu Jul 04 2002 - 08:03:21 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US