常用RMAN 備份命令

renjixinchina發表於2012-09-25
---SHOW 

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

SHOW ALL;

---LIST
RMAN> LIST ARCHIVELOG ALL;
RMAN> LIST BACKUP OF ARCHIVELOG ALL;
RMAN> LIST BACKUP;
RMAN> LIST BACKUP OF DATABASE;
RMAN> LIST BACKUP OF DATAFILE 1;
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;
RMAN> LIST FAILURE;
RMAN> LIST FAILURE 641231 detail;
---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;
---CONFIGURE 

  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 OBSOLETE

To 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;
---CROSSCHECK 
RMAN> CROSSCHECK BACKUP;
RMAN> CROSSCHECK COPY;
RMAN> CROSSCHECK backup of database; 
RMAN> CROSSCHECK backup of controlfile;
RMAN> CROSSCHECK archivelog all;

---DELETE
 RMAN> CONFIGURE CHANNEL DEVICE TYPE sbt;
 RMAN> CROSSCHECK BACKUP OF TABLESPACE user_data COMPLETED BEFORE 'SYSDATE-14';
 RMAN> DELETE NOPROMPT EXPIRED BACKUP OF TABLESPACE user_data COMPLETED BEFORE 'SYSDATE-14';
 RMAN> DELETE BACKUP OF DATABASE LIKE '/tmp%';
 RMAN> DELETE ARCHIVELOG ALL BACKED UP 2 TIMES TO DEVICE TYPE sbt;
 RMAN> DELETE BACKUPSET 101, 102, 103;
 RMAN> DELETE CONTROLFILECOPY '/tmp/cntrlfile.copy';
 RMAN> DELETE BACKUP OF SPFILE TABLESPACE users DEVICE TYPE sbt;
---RESTORE AND RECOVER

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:

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;


參考文件:



來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/15747463/viewspace-744992/,如需轉載,請註明出處,否則將追究法律責任。

相關文章