06 May 2011

RMAN Important commands

Examples:

Assuming you have configured automatic channels:

RMAN> SHOW ALL;

SHOW RETENTION POLICY;
SHOW DEVICE TYPE;
SHOW DEFAULT DEVICE TYPE;
SHOW CHANNEL;
SHOW MAXSETSIZE;

RMAN> CROSSCHECK BACKUP;
RMAN> CROSSCHECK COPY;
RMAN> CROSSCHECK backup of database;
RMAN> CROSSCHECK backup of controlfile;
RMAN> CROSSCHECK archivelog all;

Query the media manager for the status of backup sets in a given date range:

RMAN> ALLOCATE CHANNEL FOR MAINTENANCE DEVICE TYPE sbt;
RMAN> CROSSCHECK BACKUP DEVICE TYPE sbt COMPLETED BETWEEN '01-AUG-04' AND '31-DEC-04';


RMAN> LIST BACKUP;
RMAN> LIST BACKUP OF DATABASE;
RMAN> LIST BACKUP SUMMARY;
RMAN> LIST INCARNATION;
RMAN> LIST BACKUP BY FILE;
RMAN> LIST COPY OF DATABASE ARCHIVELOG ALL;
RMAN> LIST COPY OF DATAFILE 1, 2, 3;
RMAN> LIST BACKUP OF DATAFILE 11 SUMMARY;
RMAN> LIST BACKUP OF ARCHIVELOG FROM SEQUENCE 1437;
RMAN> LIST CONTROLFILECOPY "/tmp/cntrlfile.copy";
RMAN> LIST BACKUPSET OF DATAFILE 1;


Backup

Back up the database, and then the control file:
 (which contains a record of the backup)
 RMAN> BACKUP DATABASE; RMAN> BACKUP CURRENT CONTROLFILE;

Backup datafiles:
 RMAN> BACKUP AS BACKUPSET DATAFILE
        'ORACLE_HOME/oradata/trgt/users01.dbf',
        'ORACLE_HOME/oradata/trgt/tools01.dbf';

Backup all datafiles in the database:
  (bit-for-bit copies, created on disk)
 RMAN> BACKUP AS COPY DATABASE;

Backup archive logs:
 RMAN> BACKUP ARCHIVELOG COMPLETION TIME BETWEEN  'SYSDATE-28' AND 'SYSDATE-7';

Backup tablespace:
 RMAN> BACKUP TABLESPACE system, users, tools;

Backup controlfile:
 RMAN> BACKUP CURRENT CONTROLFILE TO '/backup/cntrlfile.copy';

Backup parameter file:
 RMAN> BACKUP SPFILE;

Backup everything:
 RMAN> BACKUP BACKUPSET ALL;

Create a consistent backup and keep the backup for 1 year:
 (exempt from the retention policy)
 RMAN> SHUTDOWN; RMAN> STARTUP MOUNT; RMAN> BACKUP DATABASE UNTIL 'SYSDATE+365' NOLOGS;
Backup Validation confirms that a backup could be run, by confirming that all database files exist and are free of physical and logical corruption, this does not generate any output.
Example:

 RMAN> BACKUP VALIDATE DATABASE ARCHIVELOG ALL;

   RMAN>SHOW ALL;Write disk backups to the /tmp directory:
 (%U will be replaced with unique filenames)

   RMAN> CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/tmp/%U';Backup using a flash recovery area rather than disk

   RMAN> CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT CLEAR;Configure RMAN to back up the control file after each backup

    RMAN> CONFIGURE CONTROLFILE AUTOBACKUP ON; By default, RMAN automatically names control file backups and stores them in the flash recovery area.
 To configure RMAN to write control file backups to the /cfilebackups directory:
 ( %F will generate a unique filename)

 RMAN> CONFIGURE CONTROLFILE AUTOBACKUP FORMAT
          FOR DEVICE TYPE DISK TO '/cfilebackups/cf%F';Ensure that RMAN retains all backups needed to recover the database to any point in time in the last 7 days:

   RMAN> CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;Retain three backups of each datafile:

   RMAN> CONFIGURE RETENTION POLICY TO REDUNDANCY 3;Delete backups no longer required by the retention policy:

   RMAN> DELETE OBSOLETETo override the configured retention policy for individual backups - use BACKUP.. KEEP (or CHANGE.. KEEP)

 Configure backups to run in parallel by assigning two sbt channels:

   RMAN> CONFIGURE DEVICE TYPE sbt PARALLELISM 2;Reset any CONFIGURE setting to its default by running the command with the CLEAR option

   RMAN> CONFIGURE CHANNEL DEVICE TYPE sbt CLEAR;
  RMAN> CONFIGURE RETENTION POLICY CLEAR;
 
 Point in time recovery - Full Example (restoring to the same machine / different date/time)

 Restore and recover the whole Database:

  RMAN> STARTUP FORCE MOUNT;
  RMAN> RESTORE DATABASE;
  RMAN> RECOVER DATABASE;
  RMAN> ALTER DATABASE OPEN;
 Restore and recover a Tablespace:

  RMAN> SQL 'ALTER TABLESPACE users OFFLINE';
  RMAN> RESTORE TABLESPACE users;
  RMAN> RECOVER TABLESPACE users;
  RMAN> SQL 'ALTER TABLESPACE users ONLINE';
 Restore and recover a Datafile:

  RMAN> SQL 'ALTER DATABASE DATAFILE 64 OFFLINE';
  RMAN> RESTORE DATAFILE 64;
  RMAN> RECOVER DATAFILE 64;
  RMAN> SQL 'ALTER DATABASE DATAFILE 64 ONLINE';Restore the Control file, (to all locations specified in the parameter file) then restore the database, using that control file:

 Steps for media recovery:

 1. Mount or open the database.
 Mount the database when performing whole database recovery, or open the database when performing online tablespace recovery.
 2. To perform incomplete recovery, use the SET UNTIL command to specify the time, SCN, or log sequence number at which recovery terminates. Alternatively, specify the UNTIL clause on the RESTORE and RECOVER commands.
 3. Restore the necessary files with the RESTORE command.
 4. Recover the datafiles with the RECOVER command.
 5. Place the database in its normal state. For example, open it or bring recovered tablespaces online.

 STARTUP NOMOUNT;
 RUN
 {
 ALLOCATE CHANNEL c1 DEVICE TYPE sbt;
 RESTORE CONTROLFILE;
 ALTER DATABASE MOUNT;
 RESTORE DATABASE;
 }

 Restore Validation confirms that a restore could be run, by confirming that all database files exist and are free of physical and logical corruption, this does not generate any output.
 Example:

 RMAN> RESTORE DATABASE VALIDATE;


Example

RUN{  ALLOCATE CHANNEL dev1 DEVICE TYPE DISK FORMAT '/fs1/%U'; 
ALLOCATE CHANNEL dev2 DEVICE TYPE DISK FORMAT '/fs2/%U';   BACKUP     (TABLESPACE system,finance,marketing FILESPERSET 20)    (DATAFILE 62,63,64);}

Delete Old Backup
RMAN> crosscheck backupset;

crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=bk_1266_1_20080214 recid=1129 stamp=646628261
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=bk_1265_1_20080214 recid=1130 stamp=646628260
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=bk_1267_1_20080214 recid=1131 stamp=646631805
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=bk_1268_1_20080214 recid=1132 stamp=646631824

crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=c-1946273778-20080220-00 recid=1155
stamp=647153705
Crosschecked 27 objects

RMAN> list archivelog all;

RMAN> delete expired backup;

RMAN> delete expired backupset;

RMAN> delete obsolete;

RMAN> delete obsolete;

REASON: crosschecking will check that the catalog/controlfile matches the physical backups. If a backup is missing, it will set the piece to 'EXPIRED' so when a restore is started, that it will not be eligible, and an earlier backup will be used. To remove the expired backups from the catalog/controlfile use the delete expired command.

RMAN> crosscheck backup;
RMAN> delete expired backup;

No comments: