You are on page 1of 47

Introduction to

Recovery Manager
Backup & Recovery Utility Oracle Corporation

March 22, 2014

What is Recovery Manager


Recovery Manager is a tool that:
manages the process of creating backups, and also manages the process of restoring and recovering from them. directs the Oracle server to back itself up, and restore and recover itself.

Many features of Recovery Manager are also available through the Oracle Enterprise Manager - Backup Wizard. Recovery Manager is a Command Line Interface.

March 22, 2014

Recovery Manager - 2

Features
Automation of Backup, Restore, and Recovery
e.g. addition of data file will be automatically detected, and included in the next backup

Incremental Backups (up to 4 levels. Level 0 and levels 1 to 4)


reduction in size of backup better performance during recovery possible reduction in time taken to perform backup

Corrupt block detection during


backup
v$backup_corruption, v$copy_corruption also reported in the databases alert log and trace files

restore: reported in RMAN log, as well as target database alert and trace

Easily manages distributing database backups, restores, and recoveries across clustered nodes in an Oracle Parallel Server/RAC.
March 22, 2014 Recovery Manager - 3

Features
Easy backup of Archived redo logs. Performance
Automatic Parallelization of backup, restore, and recovery. Multiplexing prevents flooding any one file with reads and writes while still keeping a tape drive streaming. No generation of extra redo during open database backups (also no worries about the database crashing with files in backup mode).

Can also limit:


Number of open files, to overcome O/S limits on concurrent files opened. Size of backup piece
This is important, as a backup piece size may easily be over the maximum file size allowed by the Operating System or Media Management software.

March 22, 2014

Recovery Manager - 4

Terminology
Backup Set A logical object, containing backups of one or more datafiles or archived logs. A backup set consists of one or more physical files called backup pieces. Backup Piece A file that contains the data for a backup set. If a backup set requires more bytes than can be supported by one file in the underlying media, then the backup set will be written to as many backup pieces as necessary. Media Manager A non-Oracle software product that knows how to manage tape drives, tape libraries, and other types of tertiary storage.

March 22, 2014

Recovery Manager - 5

Recovery Manager Components


Components of Recovery Manager:
Recovery Manager executable (rman) Target Database Recovery Catalog (or target databases control file) Server Processes (i.e. channels)

Recovery Manager executable (rman)


Translates Recovery Manager commands entered by the user into a sequence of steps which operate on physical files. Sends the Backup, Restore, and Recovery steps to the target database for execution. Coordinates and monitors the execution of these steps. Generates steps which update the Recovery Catalog (if a RC is used).

March 22, 2014

Recovery Manager - 6

Recovery Manager Architecture


Recovery Manager
server Recovery Catalog Recovery Catalog

CF

server (default)

SCF

SGA
server (polling) File 2

File 1

server
channel SBT_TAPE

File 3

MML

Target

File 4

Media Management Server


March 22, 2014 Recovery Manager - 7

Deciding Whether to Use a Recovery Catalog


It is possible for Recovery Manager to use just the target database's control file (i.e. without a Recovery Catalog). Implications:
+ There is no extra overhead of a Recovery Catalog - If you lose your control file and need to restore and recover the database, restore and recovery has to be followed in care by following the Metalink Note: 60545.1 - - Stored scripts are not available. - If the database uses a large number of data files (1000+), then backup and restore performance is better with a recovery catalog.

If not using a catalog, multiple backups of the control file should be kept in distinct locations (on different disks, tapes and/or machines). These backups must be restorable without Recovery Manager.

March 22, 2014

Recovery Manager - 8

Creating a Recovery Catalog


Choose whether to create a separate database for the Recovery Catalog, or install it in an existing database.
If you decide to create a separate database, then create it using the same procedures you would to create any Oracle database. Note:
Do not install the recovery catalog schema in the target database. Do not put the catalog on the same physical disks as the target database.

Decide whether to create a separate tablespace for the Recovery Catalog. e.g. To create a separate tablespace, start Server Manager, and:
SVRMGR> connect internal SVRMGR> create tablespace rcvcat 2> datafile /oracle/rcvcat/prod/rcvcat_1.dbf size 20m;

March 22, 2014

Recovery Manager - 9

Creating a Recovery Catalog


Create the schema owner (this example assumes there is a temp tablespace, and a separate Recovery Catalog tablespace), and grant the required privileges.
SVRMGR> connect internal SVRMGR> create user rman identified by rman 2> temporary tablespace temp 3> default tablespace rcvcat 4> quota unlimited on rcvcat; SVRMGR> grant recovery_catalog_owner to rman;

Create the Recovery Catalog Application in the new user:


SVRMGR> connect rman/rman SVRMGR> @?/rdbms/admin/catrman

Create the Recovery Catalog Application in the new user (8i/9i):


$ rman catalog rman/rman RMAN> create catalog

March 22, 2014

Recovery Manager - 10

Using a Recovery Catalog


If you use a Recovery Catalog, you must decide:
How, and how frequently, the Recovery Catalog will be backed up. Possible backup methods include:
Maintain two or more catalogs, and resync both (or use Replication) Use RMAN (switch target db and RC roles, or use no RC), export, or OS utilities

How to automate Catalog resyncs, and how often


use a utility such as cron to schedule regular resyncs resyncs happen automatically with each backup, which may be often enough

March 22, 2014

Recovery Manager - 11

Linking with a Media Manager

To be able to write to sequential devices such as Tape, you must link the Oracle server software with software which is written by a Media Management vendor. This software (usually known as the Media Management Library, or Media Management Layer) is called by Oracle when Oracle needs to write to, or read from devices supported by the Media Manager. An example of linking Oracle on Solaris, with an MML (the MML is libobk.so, and is located in /usr/lib): Shutdown all databases using that executable set before linking, then:
$ $ $ $ $ cd $ORACLE_HOME/lib mv libobk.so libobk.so.orig #if libobk.so already exists, rename it ln -s /usr/lib/libobk.so . cd $ORACLE_HOME/rdbms/lib make -f ins_rdbms.mk ioracle

In 8.1.5, no link is needed to install a media manager. Just point the symbolic link $ORACLE_HOME/lib/libobk.so to your MML library, and re-start the Oracle instance.

March 22, 2014

Recovery Manager - 12

Starting Recovery Manager


There are a number of ways to start Recovery Manager, depending on how you have configured it. Below are a few examples: Connecting to a local target instance
Without a Recovery Catalog, without specifying a username/password
$ setenv ORACLE_SID prod $ rman nocatalog RMAN> connect target #connects to SYS using SYSOPER

Without a Recovery Catalog, if user SCOTT has SYSDBA or SYSOPER


$ setenv ORACLE_SID prod $ rman target scott/tiger nocatalog

Using a Recovery Catalog


$ setenv ORACLE_SID prod $ rman rcvcat rman/rman@rcat RMAN> connect target #connects to SYS using SYSOPER

March 22, 2014

Recovery Manager - 13

Starting Recovery Manager


Connecting to a target instance (either locally or remotely) when using a password file, and specifying a TNS alias in the target connect string:
Without a Recovery Catalog:
$ rman target internal/secret@prod nocatalog

Without a Recovery Catalog, if SCOTT has SYSDBA or SYSOPER


$ rman target scott/tiger@prod nocatalog

Using a Recovery Catalog


$ rman target internal/secret@prod rcvcat rman/rman@rcat

March 22, 2014

Recovery Manager - 14

Registering a Database in a Recovery Catalog


If using a Recovery Catalog, before you use Recovery Manager to perform any backups, you must register the database with the Recovery Catalog. The target database you connect to will be the database registered in the catalog.
RMAN> register database;

The register database command identifies the database to the Recovery Catalog.
All information about the target databases structure is propagated to the Recovery Catalog from the target databases control file. The database must be mounted or open to perform this action.

March 22, 2014

Recovery Manager - 15

Backup Overview
The database can be Open or Closed during backup
If you are performing a closed backup, the database must be mounted, but not open.
SVRMGR> shutdown immediate SVRMGR> startup mount

If you are performing a backup while the database is open, the tablespaces should not be put in hot backup mode (i.e. you should not issue an alter tablespace begin backup command). Recovery Manager allows you to backup the whole database, or any of the following subsets, whether the database is open or closed (of course, as in v7, the database must be in archivelog mode to take an open backup):
database tablespace(s) datafile(s) and datafile copies control file, spfile

Archived logs may also be backed up

March 22, 2014

Recovery Manager - 16

Backup Overview
Backup Tags
Backups can be given a 30 character name called a Tag:
weekly_full daily_incremental

Tags do not need to be unique. Restore can override automatic backup selection by specifying a tag.

March 22, 2014

Recovery Manager - 17

Types of Backups
There are two types of Recovery Manager backups:
File Copies Backup Sets

Recovery Manager automatically propagates changes in database structure information to the Recovery Catalog (from the control file) before executing certain commands (e.g. backup)
The information propagated includes new datafiles, resized datafiles, dropped tablespaces, new archivelogs

March 22, 2014

Recovery Manager - 18

File Copy
A File Copy is created by the copy command and
Is an exact image copy of the original file Contains only a single input file (datafile, archivelog or controlfile) Is most like an Operating System backup (contains all blocks) Can be a part of an incremental strategy; but a file copy always includes all blocks, and hence can only be a level 0
run { allocate channel d1 type disk; copy level 0 datafile 1 to /oracle/prod/backup/file1.dbf; }

March 22, 2014

Recovery Manager - 19

Parallelization of File Copies


Parallelization of File Copies is achieved by copying multiple files within one copy command, as well as allocating multiple channels.
run { allocate channel d1 type disk; allocate channel d2 type disk; allocate channel d3 type disk; allocate channel d4 type disk; copy #first <- RMAN comment datafile 1 to /oracle/backup/prod1/d1/prd1.dbf, datafile 2 to /oracle/backup/prod1/d2/prd2.dbf, datafile 3 to /oracle/backup/prod1/d3/prd2.dbf; copy #second datafile 4 to /oracle/backup/prod1/d4/prd3.dbf; sql alter system archive log current; }

March 22, 2014

Recovery Manager - 20

Backup Set
A Backup Set is created by the backup command and
Usually contains multiple source files (multiplexed in the output) It is a logical entity, comprising one or more physical output files called backup pieces Can be written to disk or sbt_tape A restore operation is required to extract files from a backup set There are two types of Backup Sets
Datafile backup sets (can include control files) Archivelog backup sets (can only contain archivelogs)

Datafile backup sets


Can be Incremental or Full (are full, by default) Do not include empty blocks

March 22, 2014

Recovery Manager - 21

Backup Pieces
A Backup Set is a logical entity which is composed of one or more physical output files, called backup pieces A backup set usually has only one backup piece. When using sbt_tape the only time a backup set has more than one piece is when the maximum piece size is limited by the user: e.g. Tablespace backup to one tape drive, max. file size is 4Gb
run { allocate channel t1 type SBT_TAPE; set limit channel t1 kbytes 4194304; backup format df_%t_%s_%p tablespace user_data; }

If the output is < 4Gb, only one backup piece will be written. If the output size is > 4Gb, more than one backup piece will be written. Each backup piece will have blocks from all files belonging to the tablespace interspersed together.

In 8i, the media management layer can inform rman of its maximum backup piece size, which may cause multiple pieces to be created. March 22, 2014 Recovery Manager - 22

Incremental Datafile Backup


Is a backup of a datafile which only copies out Oracle blocks which have been modified since a previous incremental:
An incremental backup at level N (where N > 0) backs up all blocks modified since the previous incremental at a level < N-1

Are initially based on a Level 0 backup set, or a Level 0 File Copy Can be faster than performing full (or level 0) backups Write out fewer blocks than full (or level 0) backups Are by default non-cumulative Available only with Enterprise Edition
changed blocks all nonempty blocks

Level Day
March 22, 2014

0 Sun

2 Mon

2 Tue

1 Wed

2 Thu

2 Fri

2 Sat

0 Sun

Recovery Manager - 23

Cumulative Incremental Backups


A cumulative incremental backup at level N (where N > 0) backs up all blocks modified since the previous incremental at a level <= N Are provided for recovery speed Because cumulative Incrementals backup blocks previously backed up at the same level:
They may take longer and will write more blocks than non-cumulative. Fewer backups at each level must be applied when recovering.

changed blocks all nonempty blocks

Level Day
March 22, 2014

0 Sun

2 Mon

2C Tue

1 Wed

2 Thu

2C Fri

2C Sat

0 Sun

Recovery Manager - 24

Archivelog Backup Sets


Only include archivelogs Are always full backups As Recovery Manager has access to control file information, it knows which logs have been archived. This prevents a common problem experienced by users, of not knowing whether an archive log has been completely copied out to the archive log destination before attempting to back it up. Example:
run { allocate channel t1 type SBT_TAPE; allocate channel t2 type SBT_TAPE; backup format al_%t_%s_%p archivelog all delete input; }

As with datafile backup sets, archivelog backups are automatically distributed across the number of channels specified.
March 22, 2014 Recovery Manager - 25

Archivelog Backup Sets


Archivelogs may be specified for backup in many different ways:
by log sequence:
backup archivelog low logseq 20 high logseq 50 thread 1;

by SCN:
backup archivelog from scn 1 until scn 9999999;

by time:
backup archivelog from time 01-jan-98 until time 30-jun-98;

by name:
backup archivelog like /oracle/arc/dest/log%;

all archived logs:


backup archivelog all;

The delete input option can be used to delete logs from disk after they have been successfully backed up.

March 22, 2014

Recovery Manager - 26

Restore Concepts
To reconstruct, or bring back an original file from backup. Recovery Manager allows you to restore any logical unit of a database:
database tablespace datafile control file
restore database; restore tablespace <name>,..,<name>; restore datafile <name>,..,<name>; restore controlfile to <location>;

restore controlfile;

The controlfile will automatically be restored to all locations specified in the init.ora file (i.e. replicate controlfile will not be needed).

Archived logs may also be manually restored. Usually this is not needed, as Recovery Manager automatically restores all archivelogs which are needed during the Recovery phase. Use SET ARCHIVELOG DESTINATION to override the target database's LOG_ARCHIVE_DEST setting.
restore archivelog [all|like <filename>|<archivelog range>| etc);

March 22, 2014

Recovery Manager - 27

Restore Concepts
Recovery Manager:
Queries the Recovery Catalog to determine the configuration of the database, and to find out what backups are available for use. Decides which backups are the optimal ones to use to restore the specified files.

When compiling lists of files to restore, Recovery Manager takes into consideration:
Time Specifications (e.g. for a Point-In-Time Restore) Any tags specified by users The channel type (disk/sbt_tape) allocated. To ensure Recovery Manager will find the most recent backups, allocate the appropriate channel type. The from backupset/datafilecopy option, if specified. Note that Datafile Copies do not need to be restored, they can be used insitu by executing a switch command, which directs the database to use this file as the actual file in the database.
March 22, 2014 Recovery Manager - 28

Restore Example
Restore the whole database, including control file (to each files original location). As the whole database and control file are being restored, the database should be started, but not mounted. Start Server Manager, then:
SVRMGR> shutdown immediate SVRMGR> startup nomount

March 22, 2014

Recovery Manager - 29

Restore Example
Then start Recovery Manager:
rman target internal/secret@prod rcvcat rman/rman@rcat RMAN> run { 2> allocate channel t1 type sbt_tape; 3> restore controlfile to /tmp/cf; 4> replicate controlfile from /tmp/cf; 5> sql alter database mount; 6> restore database; 7> }

The database has been restored If the backup is consistent, and the DBA either does not want to, or cannot perform recovery, the database can be opened resetlogs, by adding the sql below to the script (a fake recovery is not required):
sql alter database open resetlogs;

March 22, 2014

Recovery Manager - 30

Recovery Concepts
Recovery is the process of using redo logs to re-play database changes to datafiles, to make the files current after they have been restored from a backup. If the database is in ARCHIVELOG mode, it is possible to either completely recover the database, or recover the database to any arbitrary point-in-time (incomplete recovery). For NOARCHIVELOG mode databases, recovery is not usually possible. The only option is to restore from a consistent whole database backup. If a database is closed during recovery, all files in that database must be consistent with each other before the database can be opened. If a database is open during a tablespace or datafile recovery, the tablespace or datafile must be consistent with the remaining datafiles before it can be brought online (implying that incomplete recovery is not possible in this scenario).
March 22, 2014 Recovery Manager - 31

Phases of RMAN Recovery


Recovery Manager performs recovery in 4 phases:
If a controlfile was restored, repair it. Apply any incremental backups that can make the files newer.
(Incremental backups are applied to a level 0 or full)

Apply redo which is currently on disk. If all redo required for recovery is not on disk, restore archivelogs, then apply them and any redo in the online redo logs needed for recovery.

March 22, 2014

Recovery Manager - 32

Tablespace Recovery: Example


This example shows the restoration and recovery of all files in the user_data tablespace. Assume the database is open.
$ rman target internal/secret@prod rcvcat rman/rman@rcat RMAN> run { 2> allocate channel t1 type sbt_tape; 3> sql alter tablespace user_data offline immediate; 4> restore tablespace user_data; 5> recover tablespace user_data; 6> sql alter tablespace user_data online; 7> }

The tablespace is now available for use.

March 22, 2014

Recovery Manager - 33

Point-In-Time Recovery: Example


Restore the whole database, including control file (to the original locations) until time '1998/02/23 16:00:00'.
SVRMGR> shutdown abort SVRMGR> startup nomount $ rman target internal/secret@prod rcvcat rman/rman@rcat RMAN> run { 2> set until time "to_date('1998/02/23 16:00:00', 3> 'YYYY/MM/DD HH14:MI:SS')"; 4> allocate channel t1 type 'SBT_TAPE'; 5> restore controlfile to '/tmp/cf'; 6> replicate controlfile from '/tmp/cf'; 7> sql 'alter database mount'; 8> restore database; 9> recover database; 10> }

In 8i, the shutdown and startup commands can be done from RMAN.

March 22, 2014

Recovery Manager - 34

Catalog Maintenance Commands


The CHANGE command is used to update the availability information in the Recovery Catalog:
To mark a backup piece, file copy or archivelog as unavailable or available for restore or recovery:
RMAN> change archivelog 2> '/disk1/archivelog/al_prd1_123.rdo' unavailable;

To delete a backup piece, file copy or archivelog which is no longer required from the controlfile, recovery catalog, and from the media it resides on:
RMAN> allocate channel t1 for delete type 'sbt_tape'; RMAN> change backuppiece <key> delete;

The keys are determined by using the list command. The 'allocate channel for delete' command is required when using the 'change delete' or 'crosscheck' commands.

To remove references to a backup piece, file copy or archivelog from the recovery catalog (e.g. if it was deleted by an O/S utility):
RMAN> change archivelog
2> /disk1/archivelog/al_prd1_123.rdo uncatalog;

March 22, 2014

Recovery Manager - 35

Catalog Maintenance Commands


If the DBA has deleted a large number of files on disk (e.g. archived logs), a more efficient method of reconciling the Recovery Catalog (and controlfile) with what is on disk, is to use change validate
RMAN> change archivelog all validate; - catalog/uncatalog RMAN> change archivelog all crosscheck; - available/unavailable

This verifies that the files the Recovery Catalog believes are on disk, are there. If they are not there, these files are identified as deleted in the catalog.

March 22, 2014

Recovery Manager - 36

Catalog Maintenance Commands


New for 8i is the 'crosscheck' command, which synchronizes backup pieces in the recovery catalog with their real-world files.
RMAN> allocate channel for maintenance type 'sbt_tape'; RMAN> crosscheck backup;

Use the DELETE EXPIRED BACKUP command to change all EXPIRED backups to DELETED.

March 22, 2014

Recovery Manager - 37

Catalog Maintenance Commands


The catalog command:
If there are archivelogs, datafiles copies etc. on disk which were created before Recovery Manager was used, it is possible to identify the existence of these to the Recovery Catalog:
RMAN> catalog archivelog '/disk1/archivelog/al_prd1_1234.rdo';

March 22, 2014

Recovery Manager - 38

Dropping the Recovery Catalog


In 8.0: SVRMGR> connect rman/rman@rcat SVRMGR> @?/rdbms/admin/catnormn In 8i: $ rman catalog rman/rman@rcat RMAN> drop catalog The 'drop catalog' command must be entered twice to confirm that is what you really want to do. All backups for all target databases managed by this catalog will become unusable.

March 22, 2014

Recovery Manager - 39

Running Recovery Manager commands


The commands can also be stored in the Recovery Catalog, with a name. It is then called a Stored Script. A stored script is only associated with one target database.
RMAN> create script 2> allocate channel 3> allocate channel 4> allocate channel 5> allocate channel 6> } alloc_channels { c1 type 'sbt_tape'; c2 type 'sbt_tape'; c3 type 'sbt_tape'; c4 type 'sbt_tape';

To execute the stored script:


RMAN> run { 2> execute script alloc_channels; 3> backup database; 4> }

March 22, 2014

Recovery Manager - 40

List Command
Displays the contents of the controlfile or recovery catalog:
All databases known to the recovery catalog or incarnations of a database
RMAN> list incarnation of database;

Backup Sets or File Copies containing a backup of a specified list of files


RMAN> list backupset of datafile 2; RMAN> list backupset of datafile /d3/dbf/user_prd1.dbf;

Backup Sets or File Copies containing a backup of any datafile which is a member of a list of tablespaces
RMAN> list copy of tablespace system;

Backup Sets or File Copies of the whole database, optionally restricted by time, datafile copy name, device name and tag Backup Sets containing Archivelogs restricted by name, or by range. For example, list which backup sets contain archivelogs between the sequence 123 and 145
RMAN> list backupset of archivelog 2> from logseq 123 until logseq 145 thread 1;

March 22, 2014

Recovery Manager - 41

Report Command
Analyzes the content of the recovery catalog in more detail than list Produces reports which can answer questions such as:
What files need a backup?
report need backup

What files are not recoverable due to unrecoverable operations?


report unrecoverable

What backups can be deleted (.e. are obsolete)?


report obsolete

What was the physical schema of the database at a previous point-in-time?


report schema

March 22, 2014

Recovery Manager - 42

Report Command

and report regular basis to ensure:


report need backup

unrecoverable

should be used on a

Recovery is possible
RMAN> report unrecoverable;

Recovery is possible within an acceptable time For Example, the following command reports all datafiles which would require the application of 3 or more incrementals to be recovered to their current state
RMAN> report need backup incremental 3 database;

The following command reports all datafiles belonging to the SYSTEM tablespace that havent had a backup (full or incremental) in 5 days or more.
RMAN> report need backup days 5 tablespace system;

March 22, 2014

Recovery Manager - 43

Duplicate Database
New command in 8i, DUPLICATE DATABASE, creates a duplicate copy of the target database:
restores backups to a second instance, on the same or a different machine recovers those backups to any desired point in time sets a new DBID in the duplicated database opens the database resetlogs

You must first create a second instance: net config files, init.ora. This is called the AUXILIARY instance. It should be started, but not mounted, before using the DUPLICATE command. The auxiliary instance does not have to be on the same machine as the target. If the duplicate database is on the same machine as the target, the filenames must be changed to avoid conflict with the target database files. Syntax: DUPLICATE TARGET DATABASE TO <newdbname>
March 22, 2014 Recovery Manager - 44

Tablespace Point-In-Time Recovery


Can recover one or more tablespaces to an earlier point in time. Typically used to recover from user error. Can be done without RMAN, but is complicated, and automated by RMAN. Requires an auxiliary instance, which must be on the same machine as the target. See the new TSPITR chapter of the 8i Backup and Recovery guide.

March 22, 2014

Recovery Manager - 45

Media Manager Problems


sbtio.log
This is the trace file which your media management product may use to write debugging/trace information can be found in the location specified by user_dump_dest (or by default on Unix systems in $ORACLE_HOME/rdbms/log)

March 22, 2014

Recovery Manager - 46

Questions

March 22, 2014

Recovery Manager - 47

You might also like