Physical Backups with a Storage Manager

A commercial backup utility, like those covered in Chapter 5 can actually deliver a completely integrated backup solution for all Oracle databases. That is, there is no need to first back up to an intermediate storage area such as a disk. The commercial utilities can back up to any storage media, then inventory these backups just as they do regular filesystem backups, allowing a “point-and-click” restore. Commercial utilities back up Oracle in one of two ways.

Vendor-Supplied Storage Managers

The first, and less common, method is to use the same basic Oracle commands that oraback.sh uses. Products that do this have simply written their own backup utility. Although most of these were developed before Oracle’s EBU and Recovery Manager (rman ) became widely available, some vendors continue to develop these products because they claim they are faster or more reliable than EBU or rman. One such product is BMC’s SQL Backtrack. Originally designed for Sybase, this product has been ported to both Oracle and Informix. As of this writing, it is a standalone product, since SQL Backtrack does not do volume management. It can, however, interface with other commercial storage managers, allowing them to provide volume management.

Oracle Storage Managers

The second commercial method of backing up Oracle is to use Oracle7’s EBU or Oracle8’s rman. EBU/rman are Oracle internal products that are designed to give a backup utility a stream (or many streams) of backup data from the database. The command that is run is called obackup or rman. After a onetime setup, the commercial backup software can communicate with Oracle at any time to initiate a backup. It tells Oracle that it wants to back up instance ORACLE_SID, and it is able to receive n threads of data. (See Chapter 5 for an explanation of how backup threads work.) EBU/rman then does all the internal communication that it needs to do to supply the backup utility with n threads of data. Both the utility and EBU/rman record the time of the backup for future reference. After things have been set up, it is also possible for a DBA to run the obackup or rman command from the command line. This command then calls the appropriate programs to connect with the backup utility. The commercial backup utility then responds to this as to any other backup request, loading volumes as necessary.

Since EBU is no longer supported in Oracle8, we do not cover it here. Recovery Manager is supported in Oracle8 and has a number of advantages over EBU. One of the main advantages is that it understands the structure of the database a lot better. It can be told, for example, to restorea tablespace. It knows what files are in that tablespace and then restores the most recent backup of those files. Once that is accomplished, it then can be told to recoverthat tablespace or apply media recovery to it. This is far better than having to find out what files to restore. rman is too complex to be covered in detail in a chapter of this size; consult Oracle’s Backup and Recovery Guide for an explanation of how rman works.

What I would like to include in this chapter, however, is what is not included in the documentation—how to use rman to completely automate the process of backing up all Oracle instances on a server rman. To completely automate such a process, you must start at the top, with the oratab file (the oratab file contains a list of all Oracle instances). A script should read the oratab file, then generate backup requests for rman based on that file. These backup requests could be used to back up both the databases and the archive logs. Such a script has to use rman scripts as well to be able to give rman all the commands that it needs. I have used rman and have written such scripts (they are included here for example only). Unlike oraback.sh, these scripts have not been extensively tested on multiple platforms, but they are short, and their principles can be used to automate the backups of any Unix database server.

Sample rman scripts

The three sample scripts are rman.sh, database.rman, and archivelog.rman. rman.sh is the “parent” script. It is called from cron with one required argument: database or archivelog. This tells rman.sh what it is supposed to do.

$ rman.sh [ database.full.rman | database.inc.rman ]

If called in this manner, rman.sh tells rman to use the command file database. level .rman. This command file tells rman to back up the entire database and switch log files when it is done. The level of the backup is determined by which rman script is called. (database.full does a level-0 backup, and database.inc does a level-1 backup.) If the PARALLELISM parameter at the top of the script is set to a number higher than 1, it backs up multiple instances at one time.

$ rman.sh [ archivelog.full.rman | archivelog.inc.rman ]

If called in this manner, rman.sh tells rman to use the command file archivelog. level .rman. This command file tells rman to back up all archive logs it finds but not to delete them when it is done. (There is an rman option to do this, but I believe it is better to leave the files around for a few days before they are deleted.) Again, the level is determined by which script is called.

The rman.sh Script

Here is the rman.sh script:

#!/bin/sh
#
#######################################################
##Site-specific section (change as appopriate)

PATH=/usr/bin:/usr/sbin:/usr/ucb:/oracle/app/oracle/product/8.0.4/bin:/oracle/opt/
bin:/oracle/opt/rcs:/oracle/app/oracle/olap/olap/bin:/oracle/backupbin
ORACLE_BASE=/oracle/app/oracle
DEBUG=Y                  # Set this to "Y" to turn on set -x for all functions
BINDIR=/oracle/backupbin # Location of this and related programs
ORACLE=oracle            # ID that script will run as
DBAGROUP=dba             # GROUP that should own backup directory
ORATAB=/var/opt/oracle/oratab
ORACLE_HOME=`grep -v '^#' $ORATAB|awk -F':' '{print $2}' |tail -1`
TMP=/var/tmp             # Where temporary and permanent logs are kept
PATH=$PATH:/usr/bin:/usr/sbin:/sbin:/usr/5bin:/bin:$BINDIR
GLOBAL_LOGIN_PASSWD=internal/manager
RMAN_LOGIN_PASSWD=rman/rman
RMAN_SID=admin
ORIG_PATH=$PATH

SID_PARALLELISM=2        # The number of instances to back up simultaneously.

LOGDIR=/oracle/backupbin

Preback() {             #Run prior to backup. 
[ "$DEBUG" = Y ] && set -x
}

Postback() {          #Run after entire backup finishes.
[ "$DEBUG" = Y ] && set -x
}

export BINDIR ORATAB ORACONF TMP PATH ORIG_PATH

##End site-specific configuration section
#######################################################

Usage()
{
echo "Usage: $0: cmdfile
(Substitute 'cmdfile' with an rman cmdfile script (located in $BINDIR)
that will be run by $0. ... e.g. database.rman)"
exit 1
}
 
[ "$DEBUG" = Y ] && set -x

ORACLE_SIDS=`grep -v '^#' $ORATAB|awk -F':' '{print $1}'|grep -v '*'`

[ $# -eq 1 ] || Usage

CMDFILE=$1

PSID=sodfwer98w7uo2krwer987wer

for ORACLE_SID in $ORACLE_SIDS ; do

 CT=`ps -ef|grep -c 'rman.target'`
 while [ $CT -gt $SID_PARALLELISM ] ; do
  # Give the last command a little time to get going and/or fail.
  sleep 15
 
  if [ `ps -ef|grep -c " $PSID "` -gt 1 ] ; then
   # If the command that we just backgrounded is now running, add it to the CT.
   CT=`ps -ef|grep -c 'rman.target'`
   sleep 30
  else
   # If not, break out of this loop cause we'll be here forever.
   break
  fi
 done

  rman cmdfile "${BINDIR}/$CMDFILE" > $LOGDIR/rman.$ORACLE_SID.$CMDFILE.log 2>&1 &
  PSID=$!

done

The database.full.rman command file (level-0 backup)

Here is the rman command file used to perform a level-0 backup:

Run {
target passwd@oracle_sid;
rcvcat passwd@rman_sid;

allocate channel t1 type 'sbt_tape';
allocate channel t2 type 'sbt_tape';
allocate channel t3 type 'sbt_tape';
allocate channel t4 type 'sbt_tape';
backup incremental level 0 format 'backup_test_%t_%s_%p' database ;
sql 'alter system archive log current';}

The archivelog.full.rman command file (level-0 archive logs)

Here is the rman command file used to back up all level-0 archive logs:

Run {
target passwd@oracle_sid;
rcvcat passwd@rman_sid;
allocate channel t1 type 'sbt_tape';
allocate channel t2 type 'sbt_tape';
allocate channel t3 type 'sbt_tape';
allocate channel t4 type 'sbt_tape';
backup incremental level 0 format 'backup_test_%t_%s_%p' archivelog all ;
sql 'alter system archive log current';}

The database.inc.rman command file (level-1 backups)

Here is the rman command file used to perform a level-1 backup:

Run {
target passwd@oracle_sid;
rcvcat passwd@rman_sid;
allocate channel t1 type 'sbt_tape';
allocate channel t2 type 'sbt_tape';
allocate channel t3 type 'sbt_tape';
allocate channel t4 type 'sbt_tape';
backup incremental level 1 format 'backup_test_%t_%s_%p' database ;
sql 'alter system archive log current';}

The archivelog.inc.rman command file (level-1 archive logs)

Here is the rman command file used to back up all level-1 archive logs:

Run {
target passwd@oracle_sid;
rcvcat passwd@rman_sid;
aenteringchannel t1 type 'sbt_tape';
allocate channel t2 type 'sbt_tape';
allocate channel t3 type 'sbt_tape';
allocate channel t4 type 'sbt_tape';
backup incremental level 1 format 'backup_test_%t_%s_%p' archivelog all ;
sql 'alter 
                     system archive log current';}

Difficulties with rman

Oracle has come a long way since alter tablespace begin backup. rman is a powerful, flexible tool, but it’s also a complex one with a large command set that must be learned in order to use it properly. (I wish they didn’t make it so hard.) The default documentation also tells you to enter the rman password on the command line. This makes it available to anyone who can enter ps -ef. (The preceding scripts do not do this, but you can see that it was done by manually entering the passwords into the script.) The Oracle Enterprise Manager is designed to make rman and other Oracle products easy to use. A DBA learning rman for the first time would do well to experiment with this tool.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.149.242