前段时间,做了一次nbu的同机恢复测试。

环境是这样的:
备份和还原都是在一个机器上,hostname是sg2as059。即备份的client是这个机器。数据库的实例名是test.
无catalog数据库,备份信息保留在控制文件中。
备份的master server和media server是同一台机器,hostname是sg2ts001。

前一天晚上设置nbu的policy进行备份,备份脚本在client上:

oracle@sg2as059:/usr/openv/netbackup/ext/db_ext/oracle/test> pwd
/usr/openv/netbackup/ext/db_ext/oracle/test
oracle@sg2as059:/usr/openv/netbackup/ext/db_ext/oracle/test> cat hot_database_backup.sh 
#!/bin/sh
# $Header: hot_database_backup.sh,v 1.2 2002/08/06 23:51:42 $
#
#bcpyrght
#***************************************************************************
#* $VRTScprght: Copyright 1993 - 2005 VERITAS Software Corporation, All Rights Reserved $ *
#***************************************************************************
#ecpyrght
#
# ---------------------------------------------------------------------------
#                       hot_database_backup.sh
# ---------------------------------------------------------------------------
#  This script uses Recovery Manager to take a hot (inconsistent) database
#  backup. A hot backup is inconsistent because portions of the database are
#  being modified and written to the disk while the backup is progressing.
#  You must run your database in ARCHIVELOG mode to make hot backups. It is
#  assumed that this script will be executed by user root. In order for RMAN
#  to work properly we switch user (su -) to the oracle dba account before
#  execution. If this script runs under a user account that has Oracle dba
#  privilege, it will be executed using this user's account.
# ---------------------------------------------------------------------------
 
# ---------------------------------------------------------------------------
# Determine the user which is executing this script.
# ---------------------------------------------------------------------------
 
CUSER=`id |cut -d"(" -f2 | cut -d ")" -f1`
 
# ---------------------------------------------------------------------------
# Put output in 
< this   file   name > .out. Change as desired.
# Note: output directory requires write permission.
# ---------------------------------------------------------------------------
 
RMAN_LOG_FILE=${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 "$RMAN_LOG_FILE" ]
then
        rm -f "$RMAN_LOG_FILE"
fi
 
# -----------------------------------------------------------------
# Initialize the log file.
# -----------------------------------------------------------------
 
echo >> $RMAN_LOG_FILE
chmod 666 $RMAN_LOG_FILE
 
# ---------------------------------------------------------------------------
# Log the start of this script.
# ---------------------------------------------------------------------------
 
echo Script $0 >> $RMAN_LOG_FILE
echo ==== started on `date` ==== >> $RMAN_LOG_FILE
echo >> $RMAN_LOG_FILE
 
# ---------------------------------------------------------------------------
# Replace /db/oracle/product/ora81, below, with the Oracle home path.
# ---------------------------------------------------------------------------
 
ORACLE_HOME=/u01/app/oracle/OraHome1
export ORACLE_HOME
 
# ---------------------------------------------------------------------------
# Replace ora81, below, with the Oracle SID of the target database.
# ---------------------------------------------------------------------------
 
ORACLE_SID=test
export ORACLE_SID
 
# ---------------------------------------------------------------------------
# Replace ora81, below, with the Oracle DBA user id (account).
# ---------------------------------------------------------------------------
 
ORACLE_USER=oracle
 
# ---------------------------------------------------------------------------
# Set the target connect string.
# Replace "sys/manager", below, with the target connect string.
# ---------------------------------------------------------------------------
 
TARGET_CONNECT_STR=/
 
# ---------------------------------------------------------------------------
# Set the Oracle Recovery Manager name.
# ---------------------------------------------------------------------------
 
RMAN=$ORACLE_HOME/bin/rman
 
# ---------------------------------------------------------------------------
# Print out the value of the variables set by this script.
# ---------------------------------------------------------------------------
 
echo >> $RMAN_LOG_FILE
echo   "RMAN: $RMAN" >> $RMAN_LOG_FILE
echo   "ORACLE_SID: $ORACLE_SID" >> $RMAN_LOG_FILE
echo   "ORACLE_USER: $ORACLE_USER" >> $RMAN_LOG_FILE
echo   "ORACLE_HOME: $ORACLE_HOME" >> $RMAN_LOG_FILE
 
# ---------------------------------------------------------------------------
# Print out the value of the variables set by bphdb.
# ---------------------------------------------------------------------------
 
echo  >> $RMAN_LOG_FILE
echo   "NB_ORA_FULL: $NB_ORA_FULL" >> $RMAN_LOG_FILE
echo   "NB_ORA_INCR: $NB_ORA_INCR" >> $RMAN_LOG_FILE
echo   "NB_ORA_CINC: $NB_ORA_CINC" >> $RMAN_LOG_FILE
echo   "NB_ORA_SERV: $NB_ORA_SERV" >> $RMAN_LOG_FILE
echo   "NB_ORA_POLICY: $NB_ORA_POLICY" >> $RMAN_LOG_FILE
 
# ---------------------------------------------------------------------------
# NOTE: This script assumes that the database is properly opened. If desired,
# this would be the place to verify that.
# ---------------------------------------------------------------------------
 
echo >> $RMAN_LOG_FILE
# ---------------------------------------------------------------------------
# If this script is executed from a NetBackup schedule, NetBackup
# sets an NB_ORA environment variable based on the schedule type.
# The NB_ORA variable is then used to dynamically set BACKUP_TYPE
# For example, when:
#     schedule type is                BACKUP_TYPE is
#     ----------------                --------------
# Automatic Full                     INCREMENTAL LEVEL=0
# Automatic Differential Incremental INCREMENTAL LEVEL=1
# Automatic Cumulative Incremental   INCREMENTAL LEVEL=1 CUMULATIVE

# For user initiated backups, BACKUP_TYPE defaults to incremental
# level 0 (full).  To change the default for a user initiated
# backup to incremental or incremental cumulative, uncomment
# one of the following two lines.
# BACKUP_TYPE="INCREMENTAL LEVEL=1"
# BACKUP_TYPE="INCREMENTAL LEVEL=1 CUMULATIVE"

# Note that we use incremental level 0 to specify full backups.
# That is because, although they are identical in content, only
# the incremental level 0 backup can have incremental backups of
# level > 0 applied to it.
# ---------------------------------------------------------------------------
 
if [ "$NB_ORA_FULL" = "1" ]
then
        echo "Full backup requested" >> $RMAN_LOG_FILE
        BACKUP_TYPE="INCREMENTAL LEVEL=0"
 
elif [ "$NB_ORA_INCR" = "1" ]
then
        echo "Differential incremental backup requested" >> $RMAN_LOG_FILE
        BACKUP_TYPE="INCREMENTAL LEVEL=1"
 
elif [ "$NB_ORA_CINC" = "1" ]
then
        echo "Cumulative incremental backup requested" >> $RMAN_LOG_FILE
        BACKUP_TYPE="INCREMENTAL LEVEL=1 CUMULATIVE"
 
elif [ "$BACKUP_TYPE" = "" ]
then
        echo "Default - Full backup requested" >> $RMAN_LOG_FILE
        BACKUP_TYPE="INCREMENTAL LEVEL=0"
fi
 
 
# ---------------------------------------------------------------------------
# Call Recovery Manager to initiate the backup. This example does not use a
# Recovery Catalog. If you choose to use one, replace the option 'nocatalog'
# from the rman command line below with the 
# 'rcvcat 
< userid > / < passwd > @ < tns   alias > ' statement.
#
# Note: Any environment variables needed at run time by RMAN 
#       must be set and exported within the switch user (su) command.
# ---------------------------------------------------------------------------
#  Backs up the whole database.  This backup is part of the incremental
#  strategy (this means it can have incremental backups of levels > 0
#  applied to it).
#
#  We do not need to explicitly request the control file to be included
#  in this backup, as it is automatically included each time file 1 of
#  the system tablespace is backed up (the inference: as it is a whole
#  database backup, file 1 of the system tablespace will be backed up,
#  hence the controlfile will also be included automatically).
#
#  Typically, a level 0 backup would be done at least once a week.
#
#  The scenario assumes:
#     o you are backing your database up to two tape drives
#     o you want each backup set to include a maximum of 5 files
#     o you wish to include offline datafiles, and read-only tablespaces,
#       in the backup
#     o you want the backup to continue if any files are inaccessible.
#     o you are not using a Recovery Catalog
#     o you are explicitly backing up the control file.  Since you are
#       specifying nocatalog, the controlfile backup that occurs
#       automatically as the result of backing up the system file is
#       not sufficient; it will not contain records for the backup that
#       is currently in progress.
#     o you want to archive the current log, back up all the
#       archive logs using two channels, putting a maximum of 20 logs
#       in a backup set, and deleting them once the backup is complete.
#
#  Note that the format string is constructed to guarantee uniqueness and
#  to enhance NetBackup for Oracle backup and restore performance.
#
#
#  NOTE WHEN USING TNS ALIAS: When connecting to a database
#  using a TNS alias, you must use a send command or a parms operand to 
#  specify environment variables.  In other words, when accessing a database
#  through a listener, the environment variables set at the system level are not 
#  visible when RMAN is running.  For more information on the environment
#  variables, please refer to the NetBackup for Oracle Admin. Guide.
#
# ---------------------------------------------------------------------------
 
CMD_STR="
ORACLE_HOME=$ORACLE_HOME
export ORACLE_HOME
ORACLE_SID=$ORACLE_SID
export ORACLE_SID
$RMAN target $TARGET_CONNECT_STR nocatalog msglog $RMAN_LOG_FILE append 
< EOF
RUN  {
ALLOCATE   CHANNEL   ch00   TYPE  ' SBT_TAPE ';
ALLOCATE   CHANNEL   ch01   TYPE  ' SBT_TAPE ';
BACKUP
    $
BACKUP_TYPE
    
SKIP   INACCESSIBLE
    
TAG   hot_db_bk_level0
    
FILESPERSET   5
    # 
recommended   format
    
FORMAT  ' bk_ % s_ % p_ % t '
    
DATABASE ;
    
sql  ' alter   system   archive   log   current ';
RELEASE   CHANNEL   ch00 ;
RELEASE   CHANNEL   ch01 ;
backup   all   archive   logs
ALLOCATE   CHANNEL   ch00   TYPE  ' SBT_TAPE ';
ALLOCATE   CHANNEL   ch01   TYPE  ' SBT_TAPE ';
BACKUP
   
filesperset   20
   
FORMAT  ' al_ % s_ % p_ % t '
   
ARCHIVELOG   ALL   DELETE   INPUT ;
RELEASE   CHANNEL   ch00 ;
RELEASE   CHANNEL   ch01 ;
#
Note:   During   the   process   of   backing   up   the   database RMAN   also   backs   up   the
control   file .   This   version   of   the   control   file   does   not   contain   the
information   about   the   current   backup   because   " nocatalog "   has   been   specified .
To   include   the   information   about   the   current   backup the   control   file   should
be   backed   up   as   the   last   step   of   the   RMAN   section .   This   step   would   not   be
necessary   if   we   were   using   a   recovery   catalog .
#
ALLOCATE   CHANNEL   ch00   TYPE  ' SBT_TAPE ';
BACKUP
    # 
recommended   format
    
FORMAT  ' cntrl_ % s_ % p_ % t '
    
CURRENT   CONTROLFILE ;
RELEASE   CHANNEL   ch00 ;
}
EOF
"
echo 
" $ CMD_STR "  >> $RMAN_LOG_FILE
# Initiate the command string
 
if [ 
" $ CUSER "  =  " root "  ]
then
    su - $ORACLE_USER -c 
" $ CMD_STR "  >> $RMAN_LOG_FILE
    RSTAT=$?
else
    /usr/bin/sh -c 
" $ CMD_STR "  >> $RMAN_LOG_FILE
    RSTAT=$?
fi
 
# ---------------------------------------------------------------------------
# Log the completion of this script.
# ---------------------------------------------------------------------------
 
if [ 
" $ RSTAT "  =  " 0 "  ]
then
    LOGMSG=
" ended   successfully "
else
    LOGMSG=
" ended   in   error "
fi
 
echo >> $RMAN_LOG_FILE
echo Script $0 >> $RMAN_LOG_FILE
echo ==== $LOGMSG on `date` ==== >> $RMAN_LOG_FILE
echo >> $RMAN_LOG_FILE
 
exit $RSTAT
oracle@sg2as059:/usr/openv/netbackup/ext/db_ext/oracle/test>

从备份脚本得知,备份的log是同目录下的,和备份脚本同名的.out文件。
因此我们可以检查一下备份的log,看看是否备份成功,以及获取其他还原时需要的信息:

oracle@sg2as059:/usr/openv/netbackup/ext/db_ext/oracle/test> cat hot_database_backup.sh.out
 
Script /usr/openv/netbackup/ext/db_ext/oracle/test/hot_database_backup.sh
==== started on Mon Jun 13 16:11:33 WAUST 2011 ====
 
 
RMAN: /u01/app/oracle/OraHome1/bin/rman
ORACLE_SID: test
ORACLE_USER: oracle
ORACLE_HOME: /u01/app/oracle/OraHome1
 
NB_ORA_FULL: 1
NB_ORA_INCR: 0
NB_ORA_CINC: 0
NB_ORA_SERV: sg2ts001
NB_ORA_POLICY: sg2as059_oracle_nbutest_backup
 
Full backup requested
 
ORACLE_HOME=/u01/app/oracle/OraHome1
export ORACLE_HOME
ORACLE_SID=test
export ORACLE_SID
/u01/app/oracle/OraHome1/bin/rman target / nocatalog msglog /usr/openv/netbackup/ext/db_ext/oracle/test/hot_database_backup.sh.out append 
< EOF
RUN  {
ALLOCATE   CHANNEL   ch00   TYPE  ' SBT_TAPE ';
ALLOCATE   CHANNEL   ch01   TYPE  ' SBT_TAPE ';
BACKUP
    
INCREMENTAL   LEVEL = 0
    
SKIP   INACCESSIBLE
    
TAG   hot_db_bk_level0
    
FILESPERSET   5
    # 
recommended   format
    
FORMAT  ' bk_ % s_ % p_ % t '
    
DATABASE ;
    
sql  ' alter   system   archive   log   current ';
RELEASE   CHANNEL   ch00 ;
RELEASE   CHANNEL   ch01 ;
backup   all   archive   logs
ALLOCATE   CHANNEL   ch00   TYPE  ' SBT_TAPE ';
ALLOCATE   CHANNEL   ch01   TYPE  ' SBT_TAPE ';
BACKUP
   
filesperset   20
   
FORMAT  ' al_ % s_ % p_ % t '
   
ARCHIVELOG   ALL   DELETE   INPUT ;
RELEASE   CHANNEL   ch00 ;
RELEASE   CHANNEL   ch01 ;
#
Note:   During   the   process   of   backing   up   the   database RMAN   also   backs   up   the
control   file .   This   version   of   the   control   file   does   not   contain   the
information   about   the   current   backup   because   nocatalog   has   been   specified .
To   include   the   information   about   the   current   backup the   control   file   should
be   backed   up   as   the   last   step   of   the   RMAN   section .   This   step   would   not   be
necessary   if   we   were   using   a   recovery   catalog .
#
ALLOCATE   CHANNEL   ch00   TYPE  ' SBT_TAPE ';
BACKUP
    # 
recommended   format
    
FORMAT  ' cntrl_ % s_ % p_ % t '
    
CURRENT   CONTROLFILE ;
RELEASE   CHANNEL   ch00 ;
}
EOF
 
 
SID           STATUS      ORACLE_HOME                               LISTENER_NAME              STATUS     
===         ======    ===========                             =============            ======    
sg2ora002     UP         / u01 / app / oracle / OraHome1                  LISTENER                   UP         
 
Use   " dbsw "   to   select   your   environment   from   a   list
or   use   " . dbset <ORACLE_SID> [<PERS_FILE>] "   to   set   the   environment   manually
 
[
YOU   HAVE   NEW   MAIL ]
 
Recovery   Manager:   Release   10 . 2 . 0 . 3 . 0   -   Production   on   Mon   Jun   13   16:11:35   2011
 
Copyright  ( c 1982 2005 Oracle .   All   rights   reserved .
 
connected   to   target   database:   TEST  ( DBID = 2051517555 )
using   target   database   control   file   instead   of   recovery   catalog
 
RMAN >  2> 3> 4> 5> 6> 7> 8> 9> 10> 11> 12> 13> 14> 15> 16> 17> 18> 19> 20> 21> 22> 23> 24> 25> 26> 27> 28> 29> 30> 31> 32> 33> 34> 35> 36> 37> 38> RMAN> 2> 3> 4> 5> 6> 7> 8> 9> 10> 11> 12> 13> 14> 15> 16> 17> 18> 19> 20> 21> 22> 23> 24> 25> 26> 27> 28> 29> 30> 31> 32> 33> 34> 35> 36> 37> 38> 
allocated channel: ch00
channel ch00: sid=28 devtype=SBT_TAPE
channel ch00: VERITAS NetBackup for Oracle - Release 6.0 (2006031019)
 
allocated channel: ch01
channel ch01: sid=32 devtype=SBT_TAPE
channel ch01: VERITAS NetBackup for Oracle - Release 6.0 (2006031019)
 
Starting backup at 13-JUN-11
channel ch00: starting incremental level 0 datafile backupset
channel ch00: specifying datafile(s) in backupset
input datafile fno=00003 name=/u07/test/oradata/sysaux01.dbf
input datafile fno=00002 name=/u07/test/oradata/undotbs01.dbf
channel ch00: starting piece 1 at 13-JUN-11
channel ch01: starting incremental level 0 datafile backupset
channel ch01: specifying datafile(s) in backupset
input datafile fno=00001 name=/u07/test/oradata/system01.dbf
input datafile fno=00004 name=/u07/test/oradata/tbs_1.dbf
channel ch01: starting piece 1 at 13-JUN-11
channel ch00: finished piece 1 at 13-JUN-11
piece handle=bk_9_1_753725520 tag=HOT_DB_BK_LEVEL0 comment=API Version 2.0,MMS Version 5.0.0.0
channel ch00: backup set complete, elapsed time: 00:02:56
channel ch00: starting incremental level 0 datafile backupset
channel ch00: specifying datafile(s) in backupset
including current control file in backupset
channel ch00: starting piece 1 at 13-JUN-11
channel ch01: finished piece 1 at 13-JUN-11
piece handle=bk_10_1_753725520 tag=HOT_DB_BK_LEVEL0 comment=API Version 2.0,MMS Version 5.0.0.0
channel ch01: backup set complete, elapsed time: 00:04:01
channel ch01: starting incremental level 0 datafile backupset
channel ch01: specifying datafile(s) in backupset
including current SPFILE in backupset
channel ch01: starting piece 1 at 13-JUN-11
channel ch00: finished piece 1 at 13-JUN-11
piece handle=bk_11_1_753725696 tag=HOT_DB_BK_LEVEL0 comment=API Version 2.0,MMS Version 5.0.0.0
channel ch00: backup set complete, elapsed time: 00:01:41
channel ch01: finished piece 1 at 13-JUN-11
piece handle=bk_12_1_753725761 tag=HOT_DB_BK_LEVEL0 comment=API Version 2.0,MMS Version 5.0.0.0
channel ch01: backup set complete, elapsed time: 00:01:21
Finished backup at 13-JUN-11
 
sql statement: alter system archive log current
 
released channel: ch00
 
released channel: ch01
 
allocated channel: ch00
channel ch00: sid=28 devtype=SBT_TAPE
channel ch00: VERITAS NetBackup for Oracle - Release 6.0 (2006031019)
 
allocated channel: ch01
channel ch01: sid=32 devtype=SBT_TAPE
channel ch01: VERITAS NetBackup for Oracle - Release 6.0 (2006031019)
 
Starting backup at 13-JUN-11
current log archived
channel ch00: starting archive log backupset
channel ch00: specifying archive log(s) in backup set
input archive log thread=1 sequence=11 recid=6 stamp=753725855
channel ch00: starting piece 1 at 13-JUN-11
channel ch01: starting archive log backupset
channel ch01: specifying archive log(s) in backup set
input archive log thread=1 sequence=12 recid=7 stamp=753725856
channel ch01: starting piece 1 at 13-JUN-11
channel ch01: finished piece 1 at 13-JUN-11
piece handle=al_14_1_753725861 tag=TAG20110613T161737 comment=API Version 2.0,MMS Version 5.0.0.0
channel ch01: backup set complete, elapsed time: 00:01:06
channel ch01: deleting archive log(s)
archive log filename=/u07/test/arch/1_12_753371123.dbf recid=7 stamp=753725856
channel ch00: finished piece 1 at 13-JUN-11
piece handle=al_13_1_753725861 tag=TAG20110613T161737 comment=API Version 2.0,MMS Version 5.0.0.0
channel ch00: backup set complete, elapsed time: 00:01:51
channel ch00: deleting archive log(s)
archive log filename=/u07/test/arch/1_11_753371123.dbf recid=6 stamp=753725855
Finished backup at 13-JUN-11
 
released channel: ch00
 
released channel: ch01
 
allocated channel: ch00
channel ch00: sid=28 devtype=SBT_TAPE
channel ch00: VERITAS NetBackup for Oracle - Release 6.0 (2006031019)
 
Starting backup at 13-JUN-11
channel ch00: starting full datafile backupset
channel ch00: specifying datafile(s) in backupset
including current control file in backupset
channel ch00: starting piece 1 at 13-JUN-11
channel ch00: finished piece 1 at 13-JUN-11
piece handle=cntrl_15_1_753725973 tag=TAG20110613T161932 comment=API Version 2.0,MMS Version 5.0.0.0
channel ch00: backup set complete, elapsed time: 00:01:05
Finished backup at 13-JUN-11
 
released channel: ch00
 
RMAN> RMAN> 
 
Recovery Manager complete.
 
Script /usr/openv/netbackup/ext/db_ext/oracle/test/hot_database_backup.sh
==== ended successfully on Mon Jun 13 16:20:38 WAUST 2011 ====
 
oracle@sg2as059:/usr/openv/netbackup/ext/db_ext/oracle/test>

在这里面有大量一会我们还原数据库时所需要用到的信息,因此该log非常重要,建议也备份到磁带上。

另外,我们也可以通过bplist来看备份集:

sg2as059:/usr/openv/netbackup/ext/db_ext/oracle/test>/usr/openv/netbackup/bin/bplist -t 4 -l -R /

-rw------- oracle    oracle        5505024 Jun 13 16:20 /cntrl_15_1_753725973
-rw------- oracle    oracle       98041856 Jun 13 16:19 /al_13_1_753725861
-rw------- oracle    oracle         262144 Jun 13 16:18 /al_14_1_753725861
-rw------- oracle    oracle         262144 Jun 13 16:16 /bk_12_1_753725761
-rw------- oracle    oracle        5505024 Jun 13 16:16 /bk_11_1_753725696
-rw------- oracle    oracle      137101312 Jun 13 16:15 /bk_10_1_753725520
-rw------- oracle    oracle      153878528 Jun 13 16:14 /bk_9_1_753725520
......