Sunteți pe pagina 1din 112

Using RMAN

For Backup and Recovery


UKOUG - 2004

About Me...
Robert G. Freeman
Burleson Consulting
dbaoracle@aol.com or robertgfreeman@yahoo.com
Books:
Portable DBA: Oracle
Oracle10g Database New Features
RMAN Backup and Recovery - Oracle Press
Oracle9i New Features - Oracle Press
Oracle 7.3 to 8 Upgrade Exam Cram - Coriolis
Oracle 8 to 8i Upgrade Exam Cram Coriolis
Mastering Oracle8i Database Administration - Sybex

What are the DBAs


Most Important Jobs?
Backup and recovery

Backup and Recovery


The Question
Oracle wants to outfit you with a
number of possible solutions to the
following question:
How can I keep my database up and
available, recoverable, and make it
disaster proof?

Some Oracle Solutions To


The Question
Real Application Clusters (RAC)
Oracle Data Guard (Stand-by
Database)
Replication
Recovery Manager (RMAN)
RAID and other hardware high
availability technologies

Recoverability
Oracle offers Recovery Manager
(RMAN) as a solution to backing up
your database.

Why use RMAN?


Why use RMAN?
Its FREE.
RMAN is supported by Oracle
RMAN Supports online or offline backup and
recovery.
RMAN provides features that other backup and
recovery software, or home grown scripts, can not.
Hot backups without putting tablespaces in hot backup
mode.
Automatic tracking of new tablespaces/datafiles.
Compression of RMAN backups is provided (much
better in 10g!.
Detection of corrupted blocks, and online correction of
block level corruption.
Easy, automated backup and restore and recovery of
your database.

Why use RMAN?


More good reasons.
Seamless integration with many 3rd party media
management products (MML layer).
Incremental backups
Test your backups without restoring them!
A facility for enterprise wide, centralized, backup
status reporting.
Compression of backups.
After you get over the Newness learning curve,
its actually very easy to use.

Can You Use RMAN?


Compatibility issues:
Still on Oracle 7, RMAN isnt available
for you.
Oracle 8.x, 8i, 9i and 10g are all
supported.
Various compatibility issues to deal with
in multiple database environments.

RMAN Architecture

Source Oracle Recovery Manager Users Guide

RMAN Architectural Terms


Channel
A database server process.
One or more channels can be established for each
backup or recovery operation. This allows parallelism
of the backup process.

Backup Set Piece


Physical operating system files that backups are
written to.
Sizes can be limited.

Backup Sets
Consist of one or more backup set pieces.
Each channel creates a different backup set.
A given channel can create more than one backup
sets
Overall size of a backup set can be limited.

RMAN Architectural Terms


Snapshot Control File
A consistent image of the control file used
by RMAN.
A location other than the default location
($ORACLE_HOME/dbs) can be configured
with the configure command in 9i and
later.

The Recovery Catalog


A central repository for database backup
and recovery information.

The Multi-Media Management Layer


Oracle developed API that allows backup
device vendors to interface with RMAN.

Principle RMAN Packages


RMAN uses packages that are built into
the Oracle kernel to perform backup and
recovery operations.
These packages are available whenever
the instance is started. Thus the packages
can be accessed with the database in
almost any state.
Though it can be much more complex,
you can restore any backup directly using
these packages.

Principle RMAN Packages


Package #1 - Sys.dbms_rcvman
Used by RMAN to access the control
file.
Used to set TIME operators.
Used to verify checkpoint information
and datafile headers.
Checks file locations and sizes.
Used to provide load-balancing
functionality of RMAN.

Principle RMAN Packages


Package #2 Sys.dbms_backup_restore
Used by RMAN to provide backup and
recovery functionality.
Creates system calls to backup
datafiles, control file and archived redo
logs.

Other Components of RMAN


The recovery catalog
The auxiliary database
OEM
MML Layer

The Recovery Catalog


Optional Component, but very handy to have.
Created in its own schema. Use the RMAN
create catalog command. Then register your
database with the register database
command
A repository for RMAN metadata about
backups.
Provides centralized reporting facility for RMAN
backups.
Generally should be contained in its own
database, which gets backed up. You can
backup the recovery catalog with RMAN.

The Recovery Catalog


Required if you want to store RMAN scripts.
Makes recovering to previous incarnations, or
recovering the control file much easier.
Oracle uses two packages to manage the
recovery catalog: dbms_rcvman and
dbms_rcvcat. These are owned by the
recovery catalog schema.
Refer to the Oracle compatibility matrix in the
Oracle documentation to make sure your
database versions are compatible with the
version of the recovery catalog you are using.

The Auxiliary Database


Host for restored files during the
following operations:
Tablespace point-in-time recovery
operations.
Database duplication
Creation of a standby database with RMAN.

Prior to Oracle Database 10g, you must


create and start the auxiliary database
instance manually.
Automatically created in Oracle
Database 10g!

Oracle Enterprise Manager


Provides a GUI interface into
RMAN.
Allows you to schedule backup
jobs, and setup email notifications
for failures.

Where To Put Your Backups


Disk
RMAN supports backup to disk.
Flash Recovery Area (10g Only)

Tape
The Multi-Media Management Layer (MML) API allows
vendors to write interfaces between RMAN and their
products.
MML must be used to backup to tape or other backup
devices.
Several Vendors have written MML interfaces. Some
vendors include:
Veritas Netbackup, Legato Networker
Tivoli Storage Manager, HP OmniBack

Flash Recovery Area


(10g Only)
Optionally used.
The flash recovery area is a file system or ASM
location for files related to database recovery.
Files stored here include:

Multiplexed copies of Control Files


Multiplexed copies of Online Redo Logs
Archived redo logs
Flashback Logs
RMAN Backups to Disk
Files created by RMAN restore and recover
commands.

The Multi-Media
Management (MML) Layer
Oracle RMAN API that allows backups to various storage
devices.
Represented in the form of a library that you install in
$ORACLE_HOME/bin or the searchable path (generally
windows/system32 in a Windows environment).
Libobk.o (UNIX, name varies by OS)
orasbt.dll (Windows)
Oracle comes with Legato Single Server version (LSSV)
which allows you to backup to a local tape device.
No network storage, or OS backups are supported in
LSSV.

The Multi-Media
Management (MML) Layer
Once the MML is configured
On UNIX platforms you can use
sbttest to test RMAN and the MML
layer.
Loadsbt.exe is available from Oracle
support for Windows platforms.

Setting Up RMAN
RMAN doesn't require a great deal of setup (Unless you are
using the MML layer).
If you are using Shared Server (MTS) then you must
configure a dedicated connection.
Configure the database in ARCHIVELOG mode if online
backup and recovery is required.
You will need to configure your Multi-Media Management
Layer according to the vendors directions.
You can use a privileged account to perform backups (SYS or
SYSTEM) or create a special account.
Configure RMAN defaults (9i and later).

Setup RMAN

Configure ARCHIVELOG Mode

ARCHIVELOG Mode, allows you to perform


online backups and do online recovery.
To put the database in ARCHIVELOG mode, do
the following:

Set the required init.ora parameters


Shutdown the database
Mount the database
Put the database in ARCHIVELOG mode.
Open the database.
Test the successful archiving on the redo logs.

Lets look at an example.

Setup RMAN

Configure ARCHIVELOG Mode - Example

First, set the required database parameters:


Required Settings
Log_archive_start Enables the ARCH process
(obsolete in 10g)
Log_archive_dest_n Defined each individual
archivelog destinations
Log_archive_format - Defines the format of the
archived redo log names.
Optional Settings
Log_archive_state_n - Defines the state of the
archive log destination.
Log_archive_min_succeed_dest Defines the
number of archived redo log destinations that
must be successfully copied to.

Setup RMAN

Configure The Flash Recovery Area

New parameters to configure for the flash recovery area in


Oracle Database 10g:
db_recovery_file_dest Location of the flash recovery
area. Does not override any other set archive log destination
settings. Must also set the db_recovery_file_dest_size
parameter.
db_recovery_file_dest_size Defines how much storage
Oracle is allowed to consume in db_recovery_file_dest.
db_flashback_retention_target Defines the upper limit
of how far back the database must be able to be flashed back.
Used in association with Oracle Database 10gs Flashback
features including the RMAN Flashback command.

Setup RMAN

Configure ARCHIVELOG Mode - Example

Log_archive_start=TRUE
Log_archive_dest_1=
location=d:\oracle\oraarc\mydb mandatory
Log_archive_dest_2=
location=z:\oracle\oraarc\mydb optional
Log_archive_min_succeed_dest=1
Log_archive_format=robt_%s_%t.arc
Db_file_recovery_dest=z:\oracle\dbrecover
Db_file_recovery_dest_size=2GB

Setup RMAN

Configure ARCHIVELOG Mode - Example


SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.

Database mounted.
SQL> alter database archivelog;
Database altered.
SQL> alter database open;
Database altered.

Setup RMAN

Configure the MML Layer (Optional)

Each vendors setup requirements are different.


Generally you will need to work with your system
administrator and/or Tape administrator to setup the MML
layer.

Setup RMAN

Configure the MML Layer (Optional)


From the Oracle side, setup of MML generally involves the
following:
Installing the vendor supplied library (may require relinking
of Oracle).
Libobk.o (UNIX, name actually varies by OS)
orasbt.dll (Windows)
Configure vendor specific components
Configuration of storage devices and media.
Configuration of vendor backup catalogs.
Configuration of backup policies and the like.
Vendor specific RMAN script requirements
May require certain variables be used in RMAN scripts
such as NB_ORA_SERV, NB_ORA_CLIENT, etc

Setup RMAN
Setup a Privileged Account

You can use SYS or SYSTEM to perform RMAN Backups.


We recommend that you create an user account that is
designed just for RMAN backups. This allows for such
things as auditing, if you like.
Connect sys/password as sysdba
Create user rman_backup identified by rman_backup
default tablespace users;

Setup RMAN
Setup a Privileged Account

You must assign sysdba to this account. RMAN always


connects as sysdba.
Grant sysdba to rman_backup;
RMAN connects as sysdba. So you must create a
password file if you wish to use RMAN over net8. You must
also set the parameter remote_login_password_file.

Setup RMAN
Using RMAN

You can start RMAN by simply issuing the


command rman at the command prompt.
C:\>rman
Recovery Manager: Release 9.2.0.1.0 Production
Copyright (c) 1995, 2002, Oracle Corporation.
All rights reserved.
RMAN>

Setup RMAN
Using RMAN

RMAN has several command line parameters


that you can use. The most commonly used:
Target The connect string for the target database
that you are going to backup or recover
Catalog The connect string for the RMAN recovery
catalog schema.
Nocatalog indicates that RMAN will not connect to a
recovery catalog. Required in 8i if not connecting to a
recovery catalog, optional in 9i.

Setup RMAN
Using RMAN

You can have RMAN will show you a list of valid parameters,
just use an incorrect command line parameter:
C:>rman ?
Argument
Value
Description
-------------------------------------------------------------target
quoted-string connect-string for target database
catalog
quoted-string connect-string for recovery catalog
nocatalog
none
if specified, then no recovery catalog
cmdfile
quoted-string name of input command file
log
quoted-string name of output message log file
.
.
.
.

Setup RMAN

Using RMAN Good Documentation

Oracle has three different RMAN manuals for 9iR2:


Recovery Manager Quick Reference
Recovery Manager Reference
Recovery Manager Users Guide

Oracle has four different RMAN manuals for 10g:


Recovery Manager Quick Start Guide
Recovery Manager Reference
Backup and Recovery Basics
Backup and Recovery Advanced Users Guide

Setup RMAN

Using RMAN Better Documentation


Unexpected Crass Commercial Plug
Best selling RMAN
book!

Setup RMAN

Configuring The Recovery Catalog

The recovery catalog allows you to easily:


Store RMAN scripts, and execute them from
the recovery catalog.
Restore a control file
Restore the database to a previous
incarnation
Generate reports on backups from various
enterprise databases

Setup RMAN

Configuring The Recovery Catalog


Configuring the recovery catalog (RC) is easy
Create a database for the recovery catalog. A single RC
database for your enterprise is typical.
Careful of contention issues if you have many
databases and a single RC.
Create a schema to store the RC objects. Assign the
schema to a separate RC catalog tablespace.
Create the recovery catalog from RMAN.
Make sure you add the RC to the Oracle NET configuration
files (tnsnames.ora and sqlnet.ora).

Setup RMAN

Configuring The Recovery Catalog

Here is an example of the creation of a recovery


catalog.
C:> set oracle_sid=backup
C:> sqlplus system
SQL> Create user rcat_user identified by rcat_user
Default tablespace rcatalog_tbs
Quota unlimited on rcatalog_tbs;
SQL> grant recovery_catalog_owner, connect, resource
to rcat_user;
SQL> quit
C:\> rman catalog=rcat_user/rcat_user
recovery catalog is not installed
RMAN> create catalog;

Setup RMAN

Configuring The Recovery Catalog

Once the recovery catalog is created, each database


must be registered.
Set oracle_sid=testdb
C:\> rman target=sys/robert
catalog=rcat_user/rcat_user@rcatdb
RMAN> register database;

Note that you have to use Oracle Net (or NET8) for at
least one of the connections. You can use it for both if
you prefer.
Once this step is complete, the recovery catalog is ready
for use.

Setup RMAN

Configuring RMAN defaults (Oracle9i+ Only)

Oracle9i and later allows you to configure default


values for many RMAN settings.
Removes the need for run blocks in many cases.
Helps standardize operations.
Use the RMAN configure command.

Some of the defaults you can configure:


The device type (sbt or disk)
The number of channels to be allocated during
backup or restore jobs.
Specific tablespace exclusion policies.
The maximum size of any backup set piece or
backup set.
Set default values for backup optimization. This
eliminates redundant backups of read-only
tablespace datafiles and archived redo logs.

Setup RMAN

Configuring RMAN defaults (Oracle9i+ Only)

More defaults you can configure:


The default filename and location of the
snapshot control file.
The automated backup of the control file
during backups and any DDL activity.
The location to backup the control files to if
automated backup of the control file is
enabled.
A default retention policy for backups. This
determines when backups are to be marked
for delete.

Setup RMAN

Configuring RMAN defaults (Oracle9i+ Only)

Configuration Examples:

Configure the default device type


Configure default device type to disk;

Configure default channel assignments


Configure channel 1 device type disk format
c:\oracle\orabackup\mydb\mydb_backup_%U;
Configure channel 1 device type disk clear;

Configure a max backup piece size


Configure channel device type disk maxpiecesize 100m;

Configure the maximum backup set size


Configure maxsetsize to 7500k;
Configure maxsetsize clear;

Excluse a read only tablespace from backups.


Configure exclude for tablespace read_only_one;

Setup RMAN

Configuring RMAN defaults (Oracle9i+ Only)

Configuration Examples:

Enable/Disable control file automated


backups
Configure controlfile autobackup on;
Configure controlfile autobackup off;

Setup RMAN

Configuring RMAN defaults (Oracle9i+ Only)

Configure Retention Policies

Oracle offers you the ability to configure retention policies via


the configure command.
Retention policies apply to database backups and archived redo
log backups.
Two types of retention policies:

Based on a recovery window. This policy ensures that


at least one backup remains valid that will allow the
database to be recovered to that point in time. All
backups older than the most recent backup that meets
this criteria are marked as obsolete.
Based on a redundancy of backups. Insures that you
have n of the most current backups available.

The default retention policy is a redundancy of 1.

Setup RMAN

Configuring RMAN defaults (Oracle9i+ Only)

Configure Retention Policies

Configure retention policies with the configure command.


Backup sets that are expired via the retention policy are
marked obsolete.
You can see which backup sets are obsolete via the
report obsolete command.
Mark obsolete backup sets as deleted via the delete
obsolete command.
You will need to physically remove any backup sets that
are obsolete. Usually this is controlled via the backup
software retention criteria.

Setup RMAN

Configuring RMAN defaults (Oracle9i Only)

Configure Retention Policies Examples

RMAN> Configure retention policy to recovery window of 3 days;


RMAN> Configure retention policy to redundancy 3;
RMAN> Configure retention policy clear;
RMAN> report obsolete;
RMAN retention policy will be applied to the command
RMAN retention policy is set to recovery window of 3 days
Report of obsolete backups and copies
Type
-------------------Backup Set
Backup Piece
Backup Piece
Backup Set

Key
-----4
4
5
5

Completion Time
-----------------02-JUN-02
02-JUN-02
02-JUN-02
02-JUN-02

Filename/Handle
-------------------D:\ORACLE\O912\DBASE\0ADQ1RV0_1_1
D:\ORACLE\O912\DBASE\0ADQ1RV0_1_2

Setup RMAN

Configuring RMAN defaults (Oracle9i Only)

Configure Retention Policies Examples

RMAN> delete obsolete;


RMAN retention policy will be applied to the command
RMAN retention policy is set to recovery window of 3 days
using channel ORA_DISK_1
using channel ORA_DISK_2
Deleting the following obsolete backups and copies:
Type
Key
Completion Time
Filename/Handle
-------------------- ------ ------------------ -------------------Backup Set
4
02-JUN-02
Backup Piece
4
02-JUN-02
D:\ORACLE\O912\DBASE\0ADQ1RV0_1_1
Backup Piece
5
02-JUN-02
D:\ORACLE\O912\DBASE\0ADQ1RV0_1_2
Backup Set
5
02-JUN-02

Setup RMAN

Configuring RMAN defaults (Oracle9i Only)

Configure Retention Policies


Examples

Do you really want to delete the above objects (enter YES or NO)? yes
deleted backup piece
backup piece handle=D:\BACKUP\ROBT\BACKUP_05DQ1NJ7_1_1 recid=1 stamp=463527534
deleted backup piece
backup piece handle=D:\ORACLE\O912\DATABASE\08DQ1P0T_1_1 recid=2 stamp=463529047
deleted backup piece
backup piece handle=D:\ORACLE\O912\DATABASE\07DQ1P0R_1_1 recid=3 stamp=463528990
deleted backup piece
backup piece handle=D:\ORACLE\O912\DATABASE\0ADQ1RV0_1_1 recid=4 stamp=463532002

Backing Up With RMAN


RMANs main role is to provide backup
and recovery of your Oracle database.
Backups are supported when the database
is in either ARCHIVELOG or
NOARCHIVELOG mode.
Backups can be taken online or offline,
however the database must be mounted at
a minimum.
Backups can be made to tape via the MML
layer or to disk.

Backing Up With RMAN


Offline Backups

RMAN Supports offline backups


They are supported in ARCHIVELOG
or NOARCHIVELOG mode.
The database must be mounted.
Databases in ARCHIVELOG mode can
be recovered point in time from an
offline backup or an online backup.
Databases in NOARCHIVELOG mode
can only be recovered to the point of
the backup.

Backing Up With RMAN


Offline Backups

If we are using Oracle 9i or later, we should first have


configured RMAN default settings. In this case, we will
be backing up to disk.
RMAN> configure default device type to disk;
RMAN> configure device type disk parallelism 2;
RMAN> configure channel 1 device type disk
format d:\backup\robt\backup_%U;
RMAN> configure channel 2 device type disk
format e:\backup\robt\backup_%U;

Backing Up With RMAN


Offline Backups

An Offline Backup (9i and later)


RMAN>
RMAN>
RMAN>
RMAN>
the

shutdown
startup mount
backup database;
alter database open;
backup

Shutdown the database


Mount the database
Backup the database
Open the database after

Backing Up With RMAN


Offline Backups

An Offline Backup not using configured settings.


RMAN> shutdown
RMAN> startup mount
Run {
Allocate channel c1 device type disk
format d:\backup\robt\robt_%U;
Allocate channel c2 device type disk
format d:\backup\robt\robt_%U;
Backup database;
Backup current controlfile;
}
RMAN> alter database open;

Shutdown the database


Mount the database
Start a run block
Allocate channel c1 for
a backup to disk
Allocate channel c2 for
a backup to disk
Backup the database
Backup the control file.
End the run block.
Open the database.

Backing Up With RMAN


Online Backups

We will assume that the database is


in ARCHIVELOG mode
In Oracle 9i and later, we should
have configured RMAN default
settings just as we did for the offline
backups.

Backing Up With RMAN


Online Backups

Now, in 9i and later, its simple to execute the backup.


RMAN> backup database;

Without configured settings it is a bit more complex:


Run {
Allocate channel c1 device type disk format
d:\backup\robt\robt_%U;
Allocate channel c2 device type disk format
d:\backup\robt\robt_%U;
Backup database;
Backup current controlfile; }

Backing Up With RMAN


Online Backups

You can also backup tablespaces and datafiles:


backup tablespace users;
backup datafile 4;
In Oracle9i and later, Backup sets can be backed up!
backup backupset all format
d:\backups\sets\%U.bak;
Backup just archived redo logs
backup archivelog all;
Backup archivelog all delete input;
Oracle9i and later provides for automated backups of
the control file and the database parameter file.
RMAN also supports the creation of copies of datafiles,
control file copies and archived redo log copies.

Backing Up With RMAN


Online Backups Oracle Database 10g

You can now backup the database using image


copies rather than backup sets!
Backup as copy database;
Backup as copy tablespace data_01;
Backup as copy datafile 10;

Oracle Database 10g also allows you to


managed the duration of the backup. In this
case, the backup will fail if It runs more than
two hours.
Backup duration 2:00 database plus archivelog;

Backing Up With RMAN


Online Backups Oracle Database 10g

Oracle Database 10g supports real


compression!
Compression is similar to GZIP or PKZIP type compression.
Backup as compressed backupset database plus
archivelog;
You can also configure a device for compression:
Configure device type disk backup type to compressed
backupset;

Backing Up With RMAN


Reading the Output Im often asked

Note that by default, the output from


RMAN commands contains only the
date. Im often asked, How do you get
the time component?
Starting Control File and SPFILE Autobackup
at 28-APR-03
Note only the date appears
Lets set the NLS_DATE_FORMAT:
set NLS_DATE_FORMAT=Mon DD YYYY HH24:MI:SS
And here is the result
Starting Control File and SPFILE Autobackup
at Apr 28 2003 07:35:17

Backing Up With RMAN


Incremental Backups

RMAN started to support incremental backups in Oracle9i.


Oracle Database 10g improves greatly on incremental
backups.
Benefits of incremental backups:
Less overall tape and disk usage
Less network bandwidth required
Overall quicker backup times
The downside to incremental backups is the potential for
longer recovery times.
Incremental backups supported in ARCHIVELOG or
NOARCHIVELOG mode.
Incremental backups of tablespaces and datafiles are
supported.

Backing Up With RMAN


Incremental Backups Oracle Database 10g

Oracle Database 10g offers faster incremental backups.


New change tracking file tracks database related changes. It
is used by RMAN to backup only blocks that have changed.
Must enable change tracking for the database:
Alter database enable block change tracking;
Alter database disable block change tracking;
The change tracking file begins at 10M in size. Grows in 10M
increments.
The change tracking file is about 1/30,000 of the size of the
database, but this can vary wildly.
The process of doing incremental backups is no different
otherwise.

Backing Up With RMAN


Incremental Backups

Two types of incremental backups are


supported:
Differential The default form of an RMAN
incremental backup. Backs up all blocks
changed since the last incremental backup
at the same or lower differential level.
Example

Mon
0

Tue
2

Wed
2

Thr
1

Fri
2

Sat
2

Sun
2

Backing Up With RMAN


Incremental Backups

Two types of incremental backups are


supported:
Cumulative An optional form of
incremental backup available in Oracle9i.
The backups are cumulative to the previous
backup at the next lower level.
Example

Mon
0

Tue
2

Wed
2

Thr
1

Fri
2

Sat
2

Sun
2

Backing Up With RMAN


Incremental Backups

Examples of incremental backups


Differential Backups
Backup incremental level=0 database;
Backup incremental level=1 database;
Backup incremental level=2 database;

Cumulative Backups
Backup incremental level=0 cumulative database;
Backup incremental level=1 cumulative database;
Backup incremental level=2 cumulative database;

Recovering With RMAN


RMAN makes recovery of your database easy. You can recover:
The control file and the SPFILE (9i)
The entire database
A specific tablespace
A specific datafile
Archived redo logs
Corrupted data blocks online
Flash recovery Features in Oracle Database 10g
RMAN supports online or offline recoveries.
Note that you still need to plan to recover your OS, your Oracle
Home, and your parameter file if you are not using SPFILES.

Recovering With RMAN


Recovering the SPFILE and the Control File

Recovery of the SPFILE (9i+) and control file is supported


through the recover spfile or recover controlfile
command.
In 8i, control file recovery is much easier with a recovery
catalog.
In 9i+, automated backups of the control file make
recovery of the control file without a recovery catalog
much easier. You will need to use the autobackup
parameter to facilitate recovery from these backups.
In extreme cases you may need to manually recover the
control file/SPFILE with the dbms_backup_restore
package.
In Oracle9i+, it is possible to start an Oracle instance
without any parameter file. This allows you to start the
Oracle instance to recover the SPFILE.

Recovering With RMAN


Recovering the SPFILE and the Control File
Example of SPFILE recovery from automatic backups:
set oracle_sid=recover
rman target sys/password
set DBID = 2539725638;
startup nomount;
restore spfile from autobackup;
shutdown immediate;
Note the need for the database DBID.
The database DBID is part of the backup set piece name. For
example: c-2539725638-20030428-00 is one example of backup
set piece name. You can find the backup set pieces on your backup
media.
The DBID is also available in the DBID column of the v$database
view.

Recovering With RMAN


Recovering the SPFILE and the Control File

Examples of Control File recovery from


automatic backups:
set oracle_sid=recover
rman target sys/password
set DBID = 2539725638;
startup nomount;
restore controlfile from autobackup;
Recover database;
Alter database open resetlogs;

Note, again, the need for the database DBID.

Recovering With RMAN


Recovering the SPFILE and the Control File

Examples of Control File recovery if using a


recovery catalog:
set oracle_sid=recover
rman target sys/password
startup nomount;
restore controlfile;
Recover database;
Alter database open resetlogs;

Restore the control file to another location:


restore controlfile to d:\controlf\backup;

Recovering With RMAN


Recovering the Database

You can use RMAN to restore and recover the


entire database.
The database must be mounted before you can
issue a recovery command.
You must first have recovered the control file and
SPFILE, if required.
Two step process
Restore the database datafiles. Performed via
the restore database command.
Recover the database. Performed via the
recover database command.
Test test test.

Recovering With RMAN


Recovering the Database

If the database is in NOARCHIVELOG mode,


the recovery will be to the point of the backup
(and any subsequent incrementals) that you
are restoring.
If the database is in ARCHIVELOG mode, the
recovery will be to the point of failure as long
as the archived redo log and the online redo
logs are available. If the redo is not available,
an error will be generated.
Incrementals will be automatically applied as
required.

Recovering With RMAN


Recovering the Database

Restore and Recovery process is dependent on the type


of failure.
Generally RMAN automates much of the process. There
are still some times that you might have to perform
some manual intervention.
Generally the commands you will use are:
Startup mount Mount the database
Restore database Restores datafiles
Recover database Recovers database, also restores
archived redo logs as required.
Alter database open {resetlogs} Opens the
database.

Recovering With RMAN


Recovering the Database - Examples

Recovering your NOARCHIVELOG database


d:>set oracle_sid=recover
d:>rman target sys/robert
RMAN> startup mount;
database mounted
RMAN> restore database;
Starting restore at 17-JUN-02 allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=11 devtype=DISK
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup
set
restoring datafile 00001 to D:\ORACLE\ORADATA\RECOVER\SYSTEM01.DBF
restoring datafile 00003 to D:\ORACLE\ORADATA\RECOVER\INDX01.DBF
restoring datafile 00004 to D:\ORACLE\ORADATA\RECOVER\TOOLS01.DBF
restoring datafile 00005 to D:\ORACLE\ORADATA\RECOVER\USERS01.DBF

Recovering With RMAN


Recovering the Database - Examples

Recovering your NOARCHIVELOG database


channel ORA_DISK_1: restored backup piece 1
piece handle=D:\ORACLE\ORA912\DATABASE\06DR6T5C_1_1
tag=TAG20020 params=NULL
channel ORA_DISK_1: restore complete
Finished restore at 17-JUN-02
RMAN> recover database noredo;
Starting recover at 17-JUN-02
using channel ORA_DISK_1
starting media recovery
media recovery complete
Finished recover at 17-JUN-02
RMAN> alter database open resetlogs;

Recovering With RMAN


Recovering the Database - Examples

Recovering your ARCHIVELOG


database
RMAN> restore database;
Starting restore at 27-JUN-02
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=11 devtype=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: sid=12 devtype=DISK
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00002 to
D:\ORACLE\ORADATA\RECOVER\RECOVER_UNDOTBS_01.DBF
channel ORA_DISK_2: starting datafile backupset restore
channel ORA_DISK_2: specifying datafile(s) to restore from backup set

Recovering With RMAN


Recovering the Database - Examples

Recovering your ARCHIVELOG


database
restoring datafile 00001 to D:\ORACLE\ORADATA\RECOVER\SYSTEM01.DBF
restoring datafile 00003 to D:\ORACLE\ORADATA\RECOVER\INDX01.DBF
channel ORA_DISK_1: restored backup piece 1
piece handle=D:\BACKUP\RECOVER\BACKUP_12DS0PJM_1_1 tag=TAG20932
params=NULL
channel ORA_DISK_1: restore complete
channel ORA_DISK_2: restored backup piece 1
piece handle=D:\BACKUP\RECOVER\BACKUP_13DS0PJO_1_1 tag=TAG20022
params=NULL
channel ORA_DISK_2: restore complete
Finished restore at 27-JUN-02

Recovering With RMAN


Recovering the Database - Examples

Recovering your ARCHIVELOG database


RMAN> recover database;
Starting recover at 27-JUN-02
using channel ORA_DISK_1
using channel ORA_DISK_2
starting media recovery
media recovery complete
Finished recover at 27-JUN-02
RMAN> alter database open;
database opened
Warning!! In 9i and earlier, a failed database restore will cause
all restored files to be removed.

Recovering With RMAN

Recovering the Database Oracle Database 10g Notes

Oracle Database 10g offers restore and channel failover


Oracle Database 10g will look for other backup sets or image
copies to restore datafiles from if the image it is trying to
recover is corrupt or inaccessible. Also, if a channel fails in
10g, Oracle will retry any incomplete operations on that
channel on other allocated channels.
Oracle Database 10g will create missing datafiles. This is very
handy in cases where you created a datafile, and had not
backed it up yet.
Oracle Database 10g offers restore preview
Allows you to determine if all backups are available to
complete a specific restore operation.

Recovering With RMAN


Recovering Datafiles - Examples

You can recover tablespaces with


RMAN if you are in ARCHIVELOG
mode.

RMAN> sql "alter tablespace users offline";


RMAN> sql "alter tablespace data offline";
RMAN> restore tablespace users, data;
RMAN> recover tablespace users, data;
RMAN> sql "alter tablespace users online";
RMAN> sql "alter tablespace data online";

Recovering With RMAN


Recovering Datafiles - Examples

You can recover datafiles with


RMAN if you are in ARCHIVELOG
mode.

RMAN> sql "alter database datafile 3 offline ";


RMAN> sql "alter database datafile 'd:\oracle\oradata\users01.dbf' offline ";
RMAN> restore datafile 3;
RMAN> restore datafile 'd:\oracle\oradata\users01.dbf';
RMAN> recover datafile 3;
RMAN> recover datafile 'd:\oracle\oradata\users01.dbf';
RMAN> sql "alter database datafile 3 online";
RMAN> sql "alter database datafile 'd:\oracle\oradata\users01.dbf' online ";

Recovering With RMAN

Recovering the Database to a Specific Point in Time

You can restore a database to a specific point


in time
There are two ways to define the time to
recover to:
Using the set until time command. This method
requires a run clause.
Using the until time clause of the restore and
recover commands.

Recovery based on log sequence number of


SCN number is also supported by RMAN.

Recovering With RMAN

Recovering the Database to a Specific Point in Time Example

Restoring/Recovering the database


to March 31st, 2003 at 3pm.
RMAN> Startup mount;
RMAN> run {
set until time to_date(03/31/2003 15:00:00,
mm/dd/yyyy hh24:mi:ss);
restore database;
recover database; }

Recovering With RMAN

Recovering the Database to a Specific Point in Time Example

Restoring/Recovering the database


to March 31st, 2003 at 3pm
(alternate method).

RMAN> Startup mount;


RMAN> Restore database until time to_date(03/31/2003
15:00:00, mm/dd/yyyy hh24:mi:ss);
RMAN> Recover database until time to_date(03/31/2003
15:00:00, mm/dd/yyyy hh24:mi:ss);
RMAN> Alter database open resetlogs;

Recovering With RMAN

Recovering the Database to a Specific Point in Time Example

Restore based on SCN or Log


Sequence Number
Incomplete Recovery based on
SCN
RMAN>
RMAN>
RMAN>
RMAN>

Startup mount;
Restore database until SCN 10000;
Recover database until SCN 10000;
Alter database open resetlogs;

Recovering With RMAN

Recovering the Database to a Specific Point in Time Example

Incomplete Recovery based


on Log Sequence Number
RMAN>
RMAN>
1;
RMAN>
1;
RMAN>

Startup mount;
Restore database until sequence 100 thread
Recover database until sequence 100 thread
Alter database open resetlogs;

Recovering With RMAN


Recovering Archived Redo Logs

Archived redo logs can be recovered.


This is handy for operations such log mining.
Example Syntax Restoring specific log files
to the current archive redo log directory.
Restore archivelog from logseq=20 thread=1;
Restore archivelog from logseq=30 until logseq=50 thread=1;

Example Syntax Restore archived redo


logs to an alternate directory
Run {
Set archivelog destination to d:\oracle\restore_archs;
Restore archivelog all;
}

Recovering With RMAN


Recovering Corrupted Data Blocks (9i+ Only)

Oracle9i and later allows you to recover


corrupted data blocks online. This is
known as block media recovery (BMR)
The operation is an online operation.
The datafile need not even be taken
offline!
Supported through the use of the
blockrecover command, new in 9i.

Recovering With RMAN


Recovering Corrupted Data Blocks (9i+ Only)

Example We get the following error


message
ORA-01578: ORACLE data block corrupted (file #
19, block # 44)
ORA-01110: data file 19:
d:\oracle\oradata\data\mydb_maintbs_01.dbf

Here is how we respond!


Block recover datafile 19 block 44;

Bada boom! Bada Bing, block is


recovered.

Recovering With RMAN


Flashback Database Recovery (10g Only)

Oracle Database 10g offers the ability to flashback the


entire database to a point in time in the past.
Requires only undo generated since the moment in time
you wish to flashback the database to.
Supported at the command line or in RMAN using the
flashback command.
Can flashback to SCN, log sequence number or a
specific timestamp (which is converted into the nearest
SCN).

Recovering With RMAN


Other recovery options

Other, more complex, RMAN


recovery operations:
Recovery to a previous incarnation, with or
without a recovery catalog (the later being
a bit more involved!)
Recovery past a resetlogs operation.
Oracle Database 10g Makes this really
easy!
Tablespace point-in-time recovery.
Creation of a stand-by database.
Duplication/Cloning of your database.

RMAN Care and Feeding


Taking Care of the Beast

RMAN requires some TLC from


time to time.
You need to maintain the proper status of
backups within the control file or the
recovery catalog.
Checking to make sure that backup set pieces
are still present.
Removing backups from the catalog that are no
longer available.
Marking obsolete or expired backup sets as
deleted.
Maintenance on the recovery catalog

RMAN Care and Feeding


The Crosscheck Command

The crosscheck command allows you to


verify the backup set pieces RMAN thinks
you have, and determine if they are
actually present.
Those that are not present are marked as expired.
Those that are present remain as available.
Any backup set pieces previously marked as expired
will be marked as available if they re-appear.
Does not effect the status of obsolete backups (those
subject to the current retention policy).

RMAN Care and Feeding


The Crosscheck Command

The crosscheck command


comes in different flavors:
Crosscheck backup checks all backup
pieces.
Crosscheck backup of datafile # - Checks
backup set pieces that contain the listed
datafile number.
Crosscheck backup of tablespace
tbs_name Check all backup set pieces that
contain backups of the tablespace tbs_name.

RMAN Care and Feeding


The Crosscheck Command

More crosscheck commands


Crosscheck backup of controlfile Checks
all control file backups.
Crosscheck backup of spfile Checks all
backups with spfiles.
Crosscheck backup completed after date
checks all backups made after the date listed
Crosscheck archivelog from sequence n
Check all archived redo log backups from log
sequence n.
Several other crosscheck options also are
available.

RMAN Care and Feeding


The Delete Command

The delete command:


Allows you to mark expired backup sets as
deleted.
Allows you to mark obsolete backup sets
(marked as such by the retention criteria set
in RMAN) as deleted.
RMAN will ask you to confirm the backup
sets to be marked as deleted.
Once marked as deleted, RMAN will no
longer be able to recover those backup sets.
The delete command does not physically
remove the backups from the backup media.

RMAN Care and Feeding


Backup of the Recovery Catalog

RMAN can backup the


recovery catalog for you.
Just use the recovery catalogs
control file.
Its probably a good practice to
create a backup control file for
the RC database after each
backup.

RMAN Reports and Lists


Information

RMAN Backup history and


status information is available
via the list and report
command.
Both commands will query the control file
or the recovery catalog for information.
The list command provides historical and
current database level information on:
Current and historical database
incarnation information
The status of current RMAN backups

RMAN Reports and Lists


Information

The report command provides information


on the current recoverable status of the
database. It provides such information as:
What datafiles need backups based on time
How many incrementals would need to be applied
for a given database restore.
Reports on redundant backups.
Reports on datafiles that have had unrecoverable
operations occur in them, which require that the
datafiles be backed up.
Information on the current database schema.
Information on obsolete backups.

RMAN Reports and Lists


Examples of the use of the list command

Some examples of the use of the list command:


This is an example of the list incarnation command.
This lists the current incarnation of the database, as
well as previous incarnations.
RMAN> list incarnation;
using target database controlfile instead of recovery catalog
List of
DB Key
------1
2
3
4

Database Incarnations
Inc Key DB Name DB ID
------- -------- ---------------1
RECOVER 2539725638
2
RECOVER 2539725638
3
RECOVER 2539725638
4
RECOVER 2539725638

CUR
--NO
NO
NO
YES

Reset SCN
---------1
315881
316061
316908

Reset Time
---------09-JUN-02
24-JUN-02
24-JUN-02
25-JUN-02

RMAN Reports and Lists


Examples of the use of the list command

Some examples of the use of the list command:


RMAN> list backup summary;
List of Backups
===============
Key
------33
35
36
37
38
39
43
44

TY
-B
B
B
B
B
B
B
B

LV
-F
A
F
F
A
F
F
A

S
A
A
A
A
A
A
A
A

Device Type
----------DISK
DISK
DISK
DISK
DISK
DISK
SBT_TAPE
DISK

Completion Time
--------------14-JUL-02
14-JUL-02
14-JUL-02
14-JUL-02
14-JUL-02
14-JUL-02
16-JUL-02
16-JUL-02

#Pieces
------1
1
1
1
1
1
1
1

#Copies
------1
1
1
1
1
1
1
1

Tag
--TAG20020714T202940
TAG20020714T203012
TAG20020714T203012
TAG20020714T203754

TAG20020716T160403

The list backup summary report provides a summary of all


current RMAN backups.

RMAN Reports and Lists


Examples of the use of the list command

Some examples of the use of the list


command:
RMAN> list backup;
List of Backup Sets
===================
BS Key Type LV Size
Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ --------------33
Full
1M
DISK
00:00:06
14-JUL-02
BP Key: 33
Status: AVAILABLE
Tag:
Piece Name: D:\ORACLE\ORA912\DATABASE\C-2539725638-20020714-00
SPFILE Included: Modification time: 26-JUN-02

RMAN Reports and Lists


Examples of the use of the list command

The list backup command provides more


detail about backups. We can also find
detailed information on specific datafile or
tablespace backups:
RMAN> list backup of datafile 3;
RMAN> list backup of tablespace users;

RMAN Reports and Lists


Examples of the use of the list command

Other backup reports


List expired backups
List backups of control files and
SPFILEs
List copies

RMAN Reports and Lists


Examples of the use of the report command

Use the report command to report on the current


recoverable state of the database.
You can use it to report on:
Database datafiles that would require more than n
days of redo application to recover
Report need backup days=3;

Database datafiles that would require more than n


incremental backups applied
Report need backup incremental = 4;

RMAN Reports and Lists


Examples of the use of the report command

More uses for the report command


Report on datafiles need to be backed up to meet the required
redundancy window

Report need backup redundancy=2;


Report on datafiles whos backups are older than the specified
recovery window

Report need backup recovery window of 2 days;


Report on datafiles that need backed up because unrecoverable
operations have been performed on them.
Report unrecoverable;

RMAN Reports and Lists


Examples of the use of the report command

More uses for the report


command
Report on backups marked
obsolete as the result of an
established retention policy
Report obsolete;

RMAN Summary
RMAN is a robust backup and recovery product
RMAN is free, and is supported by Oracle
RMAN can do offline or online backups and
recovery.
RMAN is feature rich.
RMAN is easy to use.
RMAN provides robust reporting facilities
The RMAN Recovery Catalog is a nice optional
addition.
RMAN is being used more and more.

RMAN Summary
If you are considering RMAN, my
book contains step by step
instructions on setup, backup and
recovery as well as other RMAN
operations.
Thanks for coming!
Please fill out your evaluations!

S-ar putea să vă placă și