oracle-consulting.net

Oracle Recovery Manager — backup and restore

With RMAN, Oracle provides a reliable and practical tool for backup, restore and recovery. Its scripting capabilities make it well suited to automation.

Overview

Recovery Manager (RMAN) is suitable for every backup and recovery scenario. Despite its relatively simple configuration and good scripting support, some DBAs are still reluctant to use it — even though RMAN offers a number of advantages:

  • incremental backups
  • tablespaces do not have to be put into backup mode, and no additional redo is generated during the backup
  • block corruption detection
  • parallelised I/O operations
  • automatic logging of all backup and recovery operations
  • built-in housekeeping

RMAN can either use a catalog database (a separate Oracle database) as its repository, or write the repository information into the instance's local control file. To use RMAN the database has to run in archive log mode and no nologging operations should be carried out. The following example looks at backup and recovery with local repository information.

Example of a full backup

The first step is to write the necessary RMAN scripts. In this case the load generated on the machine is to be minimised, and the backup is stretched over up to two hours. It is essential that the backup location resides on physically separate disks or on physically separate servers.

SQL / PL/SQL
run {
   allocate channel d1 type disk;
   CONFIGURE COMPRESSION ALGORITHM 'BASIC';
   CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 3 DAYS;
   CONFIGURE CONTROLFILE AUTOBACKUP ON;
   CONFIGURE BACKUP OPTIMIZATION ON;

   crosscheck backup;
   crosscheck archivelog all;
   delete noprompt force obsolete;
   delete noprompt force expired backup;
   delete noprompt force expired archivelog all;
   configure controlfile autobackup format for device type disk to '/data/oracle/rman_backup/SID/autobackup_controlfile_%d_%F_ctl.bus';

   backup DURATION 2:00 MINIMIZE LOAD full database INCLUDE CURRENT CONTROLFILE  format '/data/oracle/rman_backup/SID/rman_%n_%T_%s_%p.bus';
   backup  CURRENT CONTROLFILE  for standby format '/data/oracle/rman_backup/SID/rman_controlfile_%n_%T_%s_%p.bus';

}

The RMAN script is then invoked from a shell script through cron:

SQL / PL/SQL
rman nocatalog target / cmdfile='/data/oracle/rman_backup/backup_full.rman' log='/data/oracle/rman_backup/log/rman.log'

Example of an archive log backup

The archive logs that accumulate have to be backed up regularly as well, to protect against physical failures:

SQL / PL/SQL
run {
   allocate channel d1 type disk;
   backup ARCHIVELOG ALL format '/data/oracle/rman_backup/orapp/arch_%n_%T_%s_%p.bus';
}