 |
|
Oracle Recovery Manager
Facility Oracle Tips by Burleson
|
Oracle8 introduced the recovery manager, rman,
which can be thought of as the Enterprise Backup Utility on steroids.
Oracle8i and Oracle have improved the usability and stability of
rman. rman allows the backup of database files at the block level and
automatically performs datafile compression by only backing up blocks
that have been used or altered. In incremental mode, the rman only
backs up blocks that have been altered or added in the database,
greatly reducing the size of required backups.
rman also allows the following:
* Scripting with rman script language, backup,
and restore operations
* Reports on backup status and backup file
status
* Use of a recovery catalog to facilitate
backup and restore operations
* Parallelization of backup and restore
operations
* Backup based on specified limits (i.e.,
amount of redo generated against a file)
* Backup of database, tablespace, or
individual datafiles
* Batch backup operations
rman uses a recovery catalog. However, you can
use rman without a catalog from just the data stored in the control
files, but you are restricted to a subset of rman’s capabilities in
this mode. The catalog contains information on the following:
* Datafile and archive log backup sets and
pieces
* Datafile copies
* Archived redo logs and copies of them
* Tablespaces and datafiles at the target
database
* Named, user-created sequences of commands
called stored scripts
It is a good practice to maintain a small
database strictly for the recovery catalog and perhaps the Enterprise
Manager catalog files. The catalog should be resynchronized with all
remote databases on a periodic basis. If you don’t use a catalog, you
cannot do the following:
* Point-in-time recovery
* Use stored scripts
* Recovery if a control file is not available
rman creates backup sets that consist of
backup pieces. Backup pieces are parts of the backup set at a size
that is predetermined and usually based on the backup media capacity
of operating system file-size limitations. Backup sets can be written
to disk or secondary storage, can include a backup control file, and
can span multiple OS files (pieces). Backup devices that are supported
on your system are cataloged in the v$backup_device dynamic
performance table.
rman backup sets that contain archive logs are
called, appropriately enough, archivelog backup sets. With Oracle8,
you cannot write archive logs directly to tape, but a job can be
scheduled using rman to back archive log backup sets to tape or other
storage.
rman produces either full or incremental
backups. A full backup is a backup of one or more datafiles that
contains all blocks of the datafile(s) that have been modified or
changed. Full backups can be created out of:
* Datafiles
* Datafile copies
* Tablespaces (all datafiles for a tablespace)
* Archive logs
* Control files (current or backups)
* Entire databases
An incremental backup is a backup of one or
more files and contains only blocks that have been modified. However,
only complete control files are backed up in either incremental or
full backups. Incremental backups can be made of:
* Datafiles
* Tablespaces
* Databases
The incremental backup allows the leveling of
backups. Each level is denoted by an integer value, with the level of
backup meaning that any blocks changed since the last incremental
backup at this level will be backed up the next time this level is
specified. This allows levels to be set based on timeframes; for
example, 0 being a monthly full, 1 being a once-a-week incremental,
and 2 being a daily incremental. Of course, this also leads to
complicated rotation of tapes or backup media, taking us back to the
good old towers-of-Hanoi backup scenario nightmares.
rman also allows for image copies of
datafiles, archive logs, or control files. Image copies can only be
made to disk and cannot contain multiple files.
rman allows report generation. Reports can be
generated based on:
* Which files need backup
* Which files haven’t been backed up recently
* Which backup files can be deleted
Each backup set can be associated with a tag
that can be used to identify it in subsequent operations. The tag
doesn’t have to be unique. rman selects the most recent backup set in
the case of backup sets with duplicate tags.
rman works against running or shutdown
databases whether they are in archive log mode or not. However, if the
database is not in archive log mode, the entire database can only be
backed up if it was shut down cleanly. Tablespaces can only be backed
up in NOARCHIVELOG mode if they are offline normal. There are no
restrictions of this type on databases in ARCHIVELOG mode.
rman automatically detects corruptions and
logs these in v$backup_corruption and v$copy_corruption dynamic
performance tables. Corrupt blocks are still backed up.
Installing the rman Catalog
The catalog should be owned by a user with the
resource role grant. I suggest a user in a small database dedicated to
system administration functions such as the rman catalog and
Enterprise Manager catalog. Create a tablespace for use by the rman user
and assign that as the user’s default tablespace with unlimited quota.
For example, if we wanted our user to be named rman_dba, the steps
would be as follows:
sqlplus
system/manager
SQL>CREATE TABLESPACE rman_data DATAFILE 'file_spec' DEFAULT STORAGE
(clause);
SQL>CREATE USER rman_dba IDENTIFIED BY rman_dba
2: DEFAULT TABLESPACE rman_data
3: TEMPORARY TABLESPACE temp
4: QUOTA UNLIMITED ON rman_data;
SQL>GRANT RESOURCE,CONNECT TO rman_dba;
SQL>CONNECT rman_dba/rman_dba
SQL> CREATE CATALOG
Once the catalog has been built, the Recovery
Manager can be utilized. The command is rman, rman80, or RMAN80,
depending on your Oracle version and operating system (beginning with
8i, it will be only rman with no version identifier.) There are
literally dozens of commands for use with the rman facility. I suggest
reviewing the Oracle Backup and Recovery Concepts
Release 1 (9.0.1), Part Number A90133-02 (or
most current release) (Oracle Corporation, June 2001) and Oracle
Recovery Manager User's Guide Release 1 (9.0.1), Part Number A90135-01
(or most current release) (Oracle Corporation, June 2001) before using
RMAN. In the remainder of this section I provide a sample scenario
showing how the commands can be made into scripts.
Connection to RMAN in UNIX on early versions
can be tricky. On some UNICES, the double quotation (“) character has
to be escaped, and you need to use the double quotation to log in to
rman (at least on early versions). Assuming that the database to
be backed up is ORTEST1 with a TNS alias of ORTEST1, the user is as
specified earlier, and the catalog database is ORRMAN, the connection
to RMAN for the user SYSTEM password MANAGER would look like this:
$ rman
target ORTEST1 system/manager@ORTEST1 catalog rman_dbo/rman_dbo@ORRMAN
The target database service name in the
tnsnames.ora file is ORTEST1. The recovery catalog database service
name in the tnsnames.ora file is ORRMAN.
% cd $ORACLE_HOME/rdbms/admin
% sqlplus
sys/change_on_install@ORRMAN
SQL> grant connect, resource to RMAN_DBA identified by RMAN_DBA;Grant
succeeded.
SQL> connect
rman/rman@ORRMAN
Connected.
SQL> CREATE CATALOG
SQL> exit
%
% rman target sys/change_on_install@ORTEST1 catalog rman/rman@ORRMAN
Recovery
Manager: Release 8.0.2.0.0 - Beta
RMAN-06005: connected to target database: ORTEST1
RMAN-06008: connected to recovery catalog database
RMAN> register database;
RMAN-08006: database registered in recovery catalog
RMAN-08002: starting full resync of recovery catalog
RMAN-08004: full resync complete
RMAN> run
2> {
3> allocate channel c1 type disk;
4> backup full format '/oracle16/ORTEST1/amin/backup/backup%s%p'
(database);
5> }
RMAN-08030: allocated channel: c1
RMAN-08500: channel c1: sid=12 devtype=DISK
RMAN-08008: channel c1: started datafile backupset
RMAN-08502: set_count=9 set_stamp=280246639
RMAN-08011: channel c1: including current controlfile in backupset
RMAN-08010: channel c1: including datafile number 1 in backupset
RMAN-08010: channel c1: including datafile number 2 in backupset
RMAN-08010: channel c1: including datafile number 11 in backupset
RMAN-08010: channel c1: including datafile number 12 in backupset
RMAN-08013: channel c1: piece 1 created
RMAN-08503: piece handle=/oracle16/ORTEST1/admin/backup/backup91
comment=NONE
RMAN-08003: starting partial resync of recovery catalog
RMAN-08005: partial resync complete
RMAN-10030: RPC call appears to have failed to start on channel
default
RMAN-10036: RPC call ok on channel default
RMAN-08031: released channel: c1
RMAN> exit
Incomplete Restore Scenario
The following shows the scenario for an
incomplete recovery. The following scenario assumes that:
* You wish to do an incomplete recovery due to
an application error that was made at a specific time.
* There are three tape drives.
* You are using a recovery catalog.
TIP: It is highly advisable to
back up the database immediately after opening the database resetlogs.
The following script restores and recovers the
database to the time immediately before the user error occurred. The
script does the following:
1. Starts the database mount and restricts
connections to DBA-only users.
2. Restores the database files (to the
original locations).
3. Recovers the datafiles either by using a
combination of incremental backups and redo or just redo. Recovery
Manager will complete the recovery when it reaches the transaction
from the time specified.
4. Opens the database resetlogs.
Oracle recommends that you back up your
database after the resetlogs (this is not shown in the example).
Ensure that you set your NLS_LANG and
NLS_DATE_FORMAT environment variables. You can set these to whatever
you wish—the date format of the following example is the standard date
format used for recovery; for example, for UNIX (csh):
> setenv
NLS_LANG AMERICAN
> setenv NLS_DATE_FORMAT 'YYYY-MM-DD:hh24:mi:ss'
Next, start up SQLPLUS:
Sqlplus> connect sys as sysdba
password: xxxxxxx
Connected.
SVRMGR> startup mount restrict
SVRMGR>exit
# rman
target internal/knl@prod1 catalog rman/rman@rcat cmdfile case2.rcv
run {
# The 'set until time' command is for all commands executed
# between the { and } braces. Means both restore and recover
# will both be relative to that point in time.
# Note that Recovery Manager uses the Recovery Catalog to,
# determine the structure of the database at that time, and
# restore it.
#
set until time '1997-06-23:15:45:00';
#
allocate channel t1 type 'SBT_TAPE';
allocate channel t2 type 'SBT_TAPE';
allocate channel t3 type 'SBT_TAPE';
#
restore
(database);
#
# There is no need to manually catalog logs before recovery,
# as Recovery Manager does catalog resync from the current
# control file.
#
recover
database;
#
sql 'alter database open resetlogs';
The preceding scenario is just an example of
how to use the Recovery Manager. Please consult your manual before
attempting to use the facility for production work. The RMAN readme
file contains valuable insights into RMAN use and has several
additional scenarios.
See
Code Depot for Full Scripts
 |
This is an excerpt
from Mike Ault, bestselling author of "Oracle
10g Grid and Real Application Clusters".
You can buy it direct from the publisher for 30%-off and get
instant access to the code depot of Oracle tuning scripts. |
|