8i | 9i | 10g | 11g | 12c | 13c | 18c | 19c | 21c | 23c | Misc | PL/SQL | SQL | RAC | WebLogic | Linux

Home » Articles » 9i » Here

Recovery Manager (RMAN)

Recovery manager is a platform independent utility for coordinating your backup and restoration procedures across multiple servers. The reporting features alone mean that you should never find yourself in a position where your data is in danger due to failed backups.

The functionality of RMAN is too diverse to be covered in this article so I shall focus on the basic backup and recovery functionality. I shall also assume you are planning to use a recovery catalog, but this is not necessary, although some recovery functionality is lost if you are not using one.

Related articles.

Create Recovery Catalog

Create a user to hold the recovery catalog. This should be on a separate server to any databases you are planning to backup.

CONNECT / AS SYSDBA

-- Create tablepsace to hold repository
CREATE TABLESPACE "RMAN" 
DATAFILE '/u02/oradata/orcl/rman01.dbf' SIZE 6208K REUSE
AUTOEXTEND ON NEXT 64K MAXSIZE 32767M
EXTENT MANAGEMENT LOCAL
SEGMENT SPACE MANAGEMENT AUTO;

-- Create rman schema owner
CREATE USER rman IDENTIFIED BY rman
TEMPORARY TABLESPACE temp 
DEFAULT TABLESPACE rman 
QUOTA UNLIMITED ON rman;

GRANT connect, resource, recovery_catalog_owner TO rman;

Create the recovery catalog.

$ rman catalog=rman/rman@catalog

Recovery Manager: Release 9.2.0.1.0 - Production

Copyright (c) 1995, 2002, Oracle Corporation.  All rights reserved.

connected to recovery catalog database
recovery catalog is not installed

RMAN> CREATE CATALOG TABLESPACE "RMAN";

recovery catalog created

RMAN> EXIT

Recovery Manager complete.

$

Register Database

Each database to be backed up by RMAN must be registered with the catalog.

$ rman target=/ catalog=rman/rman@catalog

Recovery Manager: Release 9.2.0.1.0 - Production

Copyright (c) 1995, 2002, Oracle Corporation.  All rights reserved.

connected to target database: orcl (DBID=1371963417)
connected to recovery catalog database

RMAN> REGISTER DATABASE;

database registered in recovery catalog
starting full resync of recovery catalog
full resync complete

RMAN>

Existing user-created backups can be added to the catalog using the CATALOG command.

RMAN> CATALOG DATAFILECOPY '/u02/oradata/orcl/TSH1.dbf';
RMAN> CATALOG ARCHIVELOG 'log1', 'log2', 'log3', ... 'logN';

Full Backup

Configure the relevant persistant parameters for this instance.

RMAN> CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
RMAN> CONFIGURE DEFAULT DEVICE TYPE TO DISK;
RMAN> CONFIGURE CONTROLFILE AUTOBACKUP ON;
RMAN> CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/u03/backup/orcl/backup%d_DB_%u_%s_%p';

Perform a complete database backup using a single command.

RUN {
  BACKUP DATABASE PLUS ARCHIVELOG;
  DELETE NOPROMPT OBSOLETE;
}

The recovery catalog should be resyncronized on a regular basis so that changes to the database structure and presence of new archive logs is recorded. Some commands perform partial and full resyncs implicitly, but if you are in doubt you can perform a full resync using the following command.

RMAN> RESYNC CATALOG;

Restore & Recover The Whole Database

If the controlfiles and online redo logs are still present a whole database recovery can be achieved by running the following script.

RUN {
  SHUTDOWN IMMEDIATE; # use abort if this fails
  STARTUP MOUNT;
  RESTORE DATABASE;
  RECOVER DATABASE;
  ALTER DATABASE OPEN;
}

This will result in all datafiles being restored then recovered. RMAN will apply archive logs as necessary until the recovery is complete. At that point the database is opened. If the tempfiles are still present you can issue a command like the following for each of them.

SQL "ALTER TABLESPACE temp ADD
     TEMPFILE ''/u02/oradata/orcl/temp01.dbf'' 
     REUSE";

If the tempfiles are missing they must be recreated as follows.

SQL "ALTER TABLESPACE temp ADD 
     TEMPFILE ''/u02/oradata/orcl/temp01.dbf'' 
     SIZE 100M 
     AUTOEXTEND ON NEXT 64K";

Restore & Recover A Subset Of The Database

A subset of the database can be restored in a similar fashion.

RUN {
  SQL 'ALTER TABLESPACE users OFFLINE IMMEDIATE';
  RESTORE TABLESPACE USERS;
  RECOVER TABLESPACE USERS;
  SQL 'ALTER TABLESPACE users ONLINE'; 
}

Incomplete Recovery

As you would expect, RMAN allows incomplete recovery to a specified time, SCN or sequence number.

RUN { 
  SHUTDOWN IMMEDIATE;
  STARTUP MOUNT;
  SET UNTIL TIME 'Nov 15 2000 09:00:00';
  SET UNTIL TIME  "TO_DATE('2000-11-15:09:00:00', 'YYYY-MM-DD:HH24:MI:SS')";
  # SET UNTIL SCN 1000;       # alternatively, you can specify SCN
  # SET UNTIL SEQUENCE 9923;  # alternatively, you can specify log sequence number
  RESTORE DATABASE;
  RECOVER DATABASE;
  ALTER DATABASE OPEN RESETLOGS;
}

The incomplete recovery requires the database to be opened using the RESETLOGS option.

Disaster Recovery (Catalog)

In a disaster situation where all files are lost you can only recover to the last SCN in the archived redo logs. Beyond this point the recovery would have to make reference to the online redo logs which are not present. Disaster recovery is therefore a type of incomplete recovery. To perform disaster recovery connect to RMAN.

C:>rman target=/ catalog=rman/rman@catalog

Once in RMAN do the following.

STARTUP NOMOUNT;
RESTORE CONTROLFILE;
ALTER DATABASE MOUNT;

From SQL*Plus as SYS get the last archived SCN using the following.

SQL> SELECT archivelog_change#-1 FROM v$database;

ARCHIVELOG_CHANGE#-1
--------------------
             1048438

1 row selected.

SQL>

Back in RMAN do the following.

RUN {
  SET UNTIL SCN 1048438;
  RESTORE DATABASE;
  RECOVER DATABASE;
  ALTER DATABASE OPEN RESETLOGS;
}

If the UNTIL SCN were not set the following type of error would be produced once a redo log was referenced.

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 03/18/2003 09:33:19
RMAN-06045: media recovery requesting unknown log: thread 1 scn 1048439

With the database open all missing tempfiles must be replaced.

SQL "ALTER TABLESPACE temp ADD 
     TEMPFILE ''/u02/oradata/orcl/temp01.dbf'' 
     SIZE 100M 
     AUTOEXTEND ON NEXT 64K";

Once the database is fully recovered a new backup should be performed.

The recovered database will be registered in the catalog as a new incarnation. The current incarnation can be listed and altered using the following commands.

LIST INCARNATION;
RESET DATABASE TO INCARNATION x;

Disaster Recovery (No Catalog)

Create a dummy PFILE.

export ORACLE_SID=orcl
echo "DB_NAME=orcl" > /tmp/pfile.txt

Start the database in NOMOUNT mode.

sqlplus / as sysdba <<EOF
startup nomount pfile='/tmp/pfile.txt'
EXIT;
EOF

Create a new PFILE from the backup SPFILE.

rman target=/ <<EOF

SET DBID 12345678;
SET CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/u03/backup/orcl/%F';

RESTORE SPFILE 
  TO PFILE '/u01/app/oracle/product/9.2.0/dbs/initorcl.ora'
  FROM AUTOBACKUP;

EXIT;
EOF

Edit the contents of the newly created "initorcl.ora" file if necessary.

Start the database using the new PFILE.

sqlplus / as sysdba <<EOF
SHUTDOWN IMMEDIATE;
STARTUP pfile='/u01/app/oracle/product/9.2.0/dbs/initorcl.ora' FORCE NOMOUNT;
EXIT;
EOF

Restore the controlfile and mount the database.

rman TARGET=/

SET DBID 12345678;
SET CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/u03/backup/orcl/%F';

RESTORE CONTROLFILE FROM AUTOBACKUP;
ALTER DATABASE MOUNT;

Restore and recover the database.

RUN
{
  # Rename datafiles if file location must change.
  #SET NEWNAME FOR DATAFILE 1 TO '/u02/oradata/orcl/system01.dbf';

  # Set UNTIL TIME/SCN for PITR.
  #SET UNTIL TIME="TO_DATE('2000-01-01 00:00:00','YYYY-MM-DD HH24:MI:SS')";
  #SET UNTIL SCN 1234567;
  
  RESTORE DATABASE;
  # If you used SET NEWNAME, uncomment the following line.
  #SWITCH DATAFILE ALL;
  RECOVER DATABASE;
  ALTER DATABASE OPEN RESETLOGS;
}

Lists And Reports

RMAN has extensive listing and reporting functionality allowing you to monitor you backups and maintain the recovery catalog. Here are a few useful commands.

# Show all backup details
LIST BACKUP;

# Show items that need 7 days worth of
# archivelogs to recover completely
REPORT NEED BACKUP DAYS = 7 DATABASE;  


# Show/Delete items not needed for recovery
REPORT OBSOLETE;
DELETE OBSOLETE;

# Show/Delete items not needed for point-in-time
# recovery within the last week
REPORT OBSOLETE RECOVERY WINDOW OF 7 DAYS; 
DELETE OBSOLETE RECOVERY WINDOW OF 7 DAYS;

# Show/Delete items with more than 2 newer copies available
REPORT OBSOLETE REDUNDANCY = 2 DEVICE TYPE DISK;
DELETE OBSOLETE REDUNDANCY = 2 DEVICE TYPE DISK;

# Show datafiles that connot currently be recovered
REPORT UNRECOVERABLE DATABASE;
REPORT UNRECOVERABLE TABLESPACE 'USERS';

It's worth spending some time looking at all the reporting capabilities whilst deciding whether you should switch from shell scripting to RMAN. It might just influence your decision.

For more information see:

Hope this helps. Regards Tim...

Back to the Top.