Monday, November 22, 2010

Examples in RMAN



Restoring a Tablespace: Example

This example takes a tablespace offline, restores it, then performs media recovery:
SQL "ALTER TABLESPACE users OFFLINE IMMEDIATE"; 
RESTORE TABLESPACE users; 
RECOVER TABLESPACE users;  
SQL "ALTER TABLESPACE users ONLINE";

Restoring the Control File When Using a Recovery Catalog: Example

This example restores the control file to its default location, replicates it automatically to all CONTROL_FILES locations, and mounts the database:
RUN
{ # SET DBID is not necessary when connected to a recovery catalog
  STARTUP FORCE NOMOUNT;
  RESTORE CONTROLFILE;
  ALTER DATABASE MOUNT;
}

Restoring the Control File with a Tag: Example

This NOCATALOG example restores the control file specified by a tag, and then mounts the database:
CONNECT TARGET /
STARTUP NOMOUNT;
SET DBID 320066378;  # required when restoring control file in NOCATALOG mode
RESTORE CONTROLFILE FROM TAG 'monday_cf_backup';
ALTER DATABASE MOUNT;

Restoring the Database with a Backup Control File: Example

This example restores the control file to a temporary location, replicates it to all control file locations specified in the CONTROL_FILES initialization parameter, and then restores and recovers the database:
CONNECT TARGET /
STARTUP NOMOUNT;
SET DBID 320066378;  # required when restoring control file in NOCATALOG mode
RUN
{
  ALLOCATE CHANNEL c1 DEVICE TYPE sbt;
  RESTORE CONTROLFILE TO '/tmp/control01.ctl' FROM AUTOBACKUP;
  RESTORE CONTROLFILE FROM '/tmp/control01.ctl'; # restores to all CONTROL_FILES locations
  ALTER DATABASE MOUNT;
  RESTORE DATABASE;
  RECOVER DATABASE;
}
ALTER DATABASE OPEN RESETLOGS;
# if the database uses locally-managed temporary tablespaces, then add new tempfiles
# to these tablespaces after the RESETLOGS
SQL "ALTER TABLESPACE temp ADD TEMPFILE ''?/oradata/trgt/temp01.dbf'' REUSE";

Restoring Archived Redo Logs to a New Location: Example

This example restores all archived redo logs to the /oracle/temp_restore directory:
RMAN> RUN
{ 
  SET ARCHIVELOG DESTINATION TO '/oracle/temp_restore';
  RESTORE ARCHIVELOG ALL;
}

Restoring a Control File Autobackup to a Nondefault Location: Example

This example restores the latest control file autobackup made on or before June 23, 2000 with a nondefault format of PROD_CF_AUTOBACKUP_%F. It starts searching for backups with a sequence number of 20, and searches backward for 5 months:
RMAN> SET DBID 320066378;  # required when restoring control file in NOCATALOG mode
RMAN> RUN
{
  SET UNTIL TIME '23-JUN-2001 00:00:00';
  SET CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE sbt TO 'prod_cf_autobackup_%F';
  ALLOCATE CHANNEL CHANNEL_1 DEVICE TYPE sbt;
  RESTORE CONTROLFILE TO '/tmp/autobackup_20001002.dbf' FROM AUTOBACKUP 
    MAXSEQ 20 MAXDAYS 150;
}

Restoring the Server Parameter File to Current Location: Example

The following series of commands restores the current server parameter file in NOCATALOG mode:
rman TARGET /
RMAN> SET DBID 1447326980 # set dbid to dbid of target database
RMAN> STARTUP FORCE NOMOUNT; # start instance with dummy SPFILE
RMAN> RUN
{
  ALLOCATE CHANNEL c1 DEVICE TYPE sbt;
  RESTORE SPFILE FROM AUTOBACKUP; # FROM AUTOBACKUP needed in NOCATALOG mode
}
RMAN> STARTUP FORCE; # start with restored SPFILE and open database

Previewing a Restore with RESTORE PREVIEW: Example

'The following example shows the results of a RESTORE PREVIEW, which identifies the backupsets to use in restoring datafile 1 of a database:
RMAN> restore datafile 1 preview;

Starting restore at 10-OCT-03
using target database controlfile instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=18 devtype=DISK


List of Backup Sets
===================

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
25      Full    264M       DISK        00:00:42     10-OCT-03 
        BP Key: 25 Status: AVAILABLE Compressed: NO Tag: FOURTH_INC
        Piece Name: /ade/banand_hosted5/oracle/work/v1/0pf3hr3o_1
   List of Datafiles in backup set 25
   File LV Type Ckp SCN    Ckp Time  Name
   ---- -- ---- ---------- --------- ----
   1       Full 228006     10-OCT-03 /disk1/oracle/dbs/tbs_01.f
Finished restore at 10-OCT-03

Validating a Restore with RESTORE VALIDATE: Example

The following example illustrates using RESTORE VALIDATE for the restore of datafile 1, as in the previous example:
RMAN> RESTORE DATAFILE 1 VALIDATE;

Starting restore at 10-OCT-03
using channel ORA_DISK_1

channel ORA_DISK_1: starting validation of datafile backupset
channel ORA_DISK_1: restored backup piece 1
piece handle=/disk1/oracle/work/v1/0pf3hr3o_1 tag=FOURTH_INC
channel ORA_DISK_1: validation complete
Finished restore at 10-OCT-03