Oracle Database 11g Recovery Manager (RMAN)




You can perform Oracle database backup in one of two ways. The first is the traditional user-managed backup method, which consists simply of using the operating system commands to copy the relevant files to a different location and/or to a tape device. The other method is RMAN, which is bundled with the database itself. With RMAN, you backup the database files from within the database.

A comprehensive set of backup and recovery tools that can streamline the backup and recovery of a database.



Cold Backup
A database cold backup is most likely the simplest way to make a backup of a database. A cold backup consists of making copies of the datafile, the control files, and the initialization parameter files while the database is shutdown. A cold backup is also known as a closed backup.

Cold backup may be taken when running the database in either NOARCHIELOG or ARCHIVELOG mode.



Hot Backup

A hot backup is similar to a cold backup, except that the backup is performed while the database is open and available to users. A hot backup is also known as an open backup.

A hot backup can be performed only when operating the database in ARCHIVELOG mode.




Connecting To RMAN Through Database Authentication

You can log into the RMAN utility by using your database credentials. You need to have SYSDBA privileges to use RMAN. The following examples use the SYS user account to log into RMAN.



$ rman

RMAN> connect target sys/sys_password;



RMAN> exit;
Recovery Manager complete.




Connecting To RMAN Using O/S Authentication

You can also log into RMAN using Operating System authentication. In this case, you don’t need to use the SYS account and password. Here’s how you do this.



$ rman target /




Creating The Recovery Catalog Database



Step # 1

$ sqlplus /nolog



Step # 2

SQL> connect / as sysdba;



Step # 3

SQL> create user rmusr identified by rmusr default tablespace users temporary tablespace temp;



Step # 4

SQL> grant connect, resource, recovery_catalog_owner to rmusr;



Step # 5

SQL> exit;



Step # 6

$ rman

RMAN> connect catalog rmusr/rmusr
Connected to recovery catalog database.



Step # 7

RMAN> create catalog;
Recovery catalog created



Step # 8

RMAN> exit;

Connecting To The Target And Recovery Catalog Database




Set the Oracle System Identifier (ORACLE_SID) to the target database:

$ export ORACLE_SID=ORCL



Step # 1

$ rman
RMAN>



Step # 2

RMAN> connect target;
Connected to target database: ORCL (DBID:Nos.)



Step # 3

RMAN> connect catalog rmusr/rmusr;
Connected to RECOVERY CATALOG DATABASE.




Registering The Target Database



Step # 4

RMAN> register database;
Database registered in recovery catalog
Starting full resync to recovery catalog
Full resync complete



Configuring Channel Allocation

When a backup or restore operation is performed using RMAN it configures channels which in turn initiate one or more server processes on the instance of the target database. A channel represents a single stream of data of backup device. Multiple channels may be configured to speed up backup and recovery procedures. The server processes perform the actual backup, restore, and recovery operation.



Channels may be allocated manually using ALLOCATE CHANNEL command.



A channel may be configured to interact with tape device (SBT) or a disk (DISK). For example a channel called C1 that would access a disk is created using this command.

RMAN> run {allocate channel c1 type disk; }



Configure Default Device Type



Step # 5

RMAN> configure default device type to sbt;

Or

RMAN> configure default device type to disk;

SBT for tape device.



Step # 6

RMAN> show default device type;

If you want to clear default device type the following command is used for said purpose



RMAN> configure default device type clear;


Configuring Control File Autobackup



Step # 7

RMAN> configure controlfile autobackup on;



Step # 8

RMAN> configure controlfile autobackup format for device type disk to ‘/opt/oracle/backup/%F’;



Step # 9

RMAN> show controlfile autobackup;



Step # 10

RMAN> show controlfile autobackup format;

If you want to clear the above configuration use the following commands

RMAN> configure controlfile autobackup clear;
RMAN> configure controlfile autobackup format for device type disk clear;


Configuring The Default Backup Type




Step # 11

RMAN> configure device type disk backup to backupset;

or

RMAN> configure device type disk backup to copy;

or

RMAN> configure device type disk backup type to compressed backupset;



Step # 12

RMAN> show device type;

Configuring The Default Location And Naming Format



Step # 13

RMAN> configure channel device type disk format ‘/opt/oracle/backup/bks_%d_%s_%p_%T’;



Step # 14

RMAN> exit




Format
Description
%d
Name
%T
Specific backup set timestamp
%s
Specific backup set number
%p
Specific backup piece number
%U
System generated unique filename (This is the default)







BACKUP USING RMAN

You can backup datafiles, controlfiles, and archivelog files using Recovery Manager. Redo log files are not backup. To perform a backup using RMAN, the database must either be mounted or opened.

Using Recovery Manager, two types of backups may be crated. They are known as Backupsets and Image copies.



Backupsets

A backupsets is output of a backup, done using Recover Manager. A backupset is a logical object that stores the data that has been backup in an RMAN-specific format. Backupsets require additional task to be performed during restoration, but are more space efficient. Backupsets are made up of backup pieces. Backup pieces are the actual files that are created on the operating system.



By default, backupsets always contain only a single backup piece, unless the DBA specifies an option to create multiple smaller backup pieces. A signal backup piece can store data blocks from different datafiles in such a way that blocks on one datafiles may be interspersed with the blocks of another datafile. As a result, RMAN performs additional steps during restoration to make the backup usable. This feature is known as Multiplexing.



Backupsets are created using the BACKUP command of RMAN.



Using Recovery Manager, a DBA can create full or incremental backups. These options are only available with backupsets. A full backup is a backup of all the used blocks of the datafiles. Block that have never been used are not copied.



Incremental Backup

An incremental backup is one that contains all the blocks that were modified since the pervious incremental backup. The size of incremental backups is considerably smaller that full backup. If you wish to use the incremental backup strategy, a base backup or a level 0 backup must be created first.



Using RMAN you can create incremental backup of the database, tablespaces, or individual datafiles. When performing incremental backups, Oracle reads the entire datafile even if very few changes were made to it. This can take a considerable amount of time. Block Change Tracking is used to minimize the amount of time spent reading the datafile for modified blocks.



Incremental backups may be taken at two levels, level 0 and level 1. A level 0 backup is similar to a full backup in that all the used blocks of the datafile are backed up. A level 1 backup is taken against a level 0. In an incremental backup strategy the base backup cannot be a full backup. It should always be a level 0 backup. A level a backup can be either differential or cumulative.



Differential Incremental Backup is a level 1 backup that backups all block that have been modified since the most recent incremental level 0 or level 1 backup.



Cumulative Incremental Backup is a level 1 backup that backup all blocks that have been modified since the most recent incremental level 0 backup.

Cumulative backups are larger in size than incremental backups and take longer to complete.



Image Copies are identical to the actual physical file being backup. Images copies are easier to work with because they can be used directly during the restoration process.



For example, an image copy of a file USERS01.DBF with size a 2.5 GB will be an identical file with a size 2.5 GB. All the block of the input datafile, used or unused will be copied. Since this file is exactly like the original file, RMAN can use this file directly during the process of restoration. A image copy is created using the COPY or the BACKUP AS COPY command of RMAN.




Backing Up the Entire Database


Step # 1

$ rman



Step # 2

RMAN> connect target;



Step # 3

RMAN> connect catalog rmusr/rmusr;



Step # 4

RMAN> configure device type disk clear;



Step # 5

RMAN> backup database;

Backing up Tablespaces

RMAN> BACKUP TABLESPACE SYSTEM;

RMAN> BACKUP TABLESPACE USERS, SYSAUX;



RMAN> BACKUP TABLESPACE USERS FORMAT ‘/opt/oracle/backup/tb_%n_%t_%s_%p’;




Backing up a Datafile



RMAN> REPORT SCHEMA;



RMAN> BACKUP DATAFILE 3;



RMAN> BACKUP DATAFILE 2, 4;




Backing up the Current Controlfile



RMAN> BACKUP CURRENT CONTROLFILE;




Creating Compressed Backups



RMAN> BACKUP AS COMPRESSED BACKUPSET DATAFILE 3;



Backing up Archivelog Files



RMAN> BACKUP ARCHIVELOG ALL;



RMAN> BACKUP ARCHIVELOG ALL DELETE INPUT;



RMAN> BACKUP ARCHIVELOG FROM TIME ‘SYSDATE-2’ UNTIL TIME ‘SYSDATE’;



Performing Incremental Backups



RMAN> BACKUP INCREMENTAL LEVEL 0 DATABASE;



RMAN> BACKUP INCREMENTAL LEVEL 0 DATAFILE 2, 4;



RMAN> BACKUP INCREMENTAL LEVEL 0 TABLESPACE USERS;



RMAN> BACKUP INCREMENTAL LEVEL 1 TABLESPACE USERS;



RMAN> BACKUP INCREMENTAL LEVEL 1 CUMULATIVE TABLESPACE USERS;



Creating Image Copies



RMAN> BACKUP AS COPY DATABASE;



RMAN> BACKUP AS COPY TAG “USR_WKL_BKP” DATABASE;



RMAN> BACKUP AS COPY DATAFILE 4;





RMAN SCRIPTS

Scripts are a sequence of RMAN commands that are stored under a name and may be used repetitively. The ability to create and maintain scripts is possible only when using a Recovery Catalog. A script is created and stored in the Recovery Catalog using a CREATE SCRIPT command. It may be executed whenever required by the EXECUTE SCRIPT command.



1. $ rman

RMAN> connect target;
RMAN> connect catalog rmusr/rmusr;



2. RMAN> create script mon_bkp
{ backup database format ‘db_%d_%s_%u’
tag mon_bkp;
backup format ‘arch_%t_%s_%p’
( archivelog all ); }



3. RMAN> run { execute script mon_bkp; }




Block Change Tracking



Block Change Tracking reduces the amount of time taken for incremental backups. As you are already aware, during incremental backups only those blocks that were modified since the most recent incremental backup are backed up.



In block change tracking, the Oracle Database tracks the physical location of all database changes in a separate file called the Change Tracking File. When an incremental backup needs to be done, it reads this file to determine which blocks need to be backed up. This eliminated reading the entire datafile, which was a time consuming step.



When a change occurs to a block, the Change Tracking Writer (CTWR) background process writes the change to the tracking file. The minimum size of the change tracking file is 10 MB increments.



SQL> connect abc/xyz@orcl;



SQL> select * from v$block_change_tracking;



SQL> alter database enable block change tracking using file ‘/opt/oracle/oradata/bct_file.chg’



SQL> select * from v$block_change_tracking;


SQL> alter database disable block change tracking;



SQL> select * from v$block_change_tracking;




Monitoring RMAN Backups



A DBA can view RMAN metadata regarding backups and recoveries by querying various dynamic performance views on the target database. These views display information from the control file of the target database.


Data Directory View
Description
V$RMAN_OUTPUT
Display messages reported by an RMAN job in progress.
V$RMAN_STATUS
Display the status of the RMAN job, as to whether it was successful or unsuccessful.
V$SESSION_LONGOPS
Shows progress reports on RMAN backup and restores.




RMAN Commands



RMAN> list backup by backup;



RMAN> list backupset by backup;



RMAN> list backup by backup verbose;



RMAN> list backup by backup summary;



RMAN> list backup by file;



RMAN> list copy of database;



RMAN> list copy of tablespace users;



RMAN> list copy of tablespace users;



RMAN> list copy of datafile 3;



RMAN> list incarnation;



RMAN> report need backup;



RMAN> report need backup days = 7 database;
(Names of files in the database that need minimum of 7 days of log files to be applied in the event of recovery)



RMAN> report absolete;



RMAN> delete obsolete;



RMAN> report schema;



RMAN> report schema at time ‘SYSDATE - 7’ ;



RMAN> report schema at scn 90000;




Performing Complete Recovery Manually



RESTORE [ DATABASE | TABLESPACE tablespace_name | { DATAFILE number | name } ]



Complete Closed Database Recovery using RMAN when Operating the Database in Archivelog mode



RMAN> run {
Backup database;
Backup archivelog all;
}



Simulating the loss of a file belonging to the SYSTEM tablespace.



Shutdown the ORCL Database



SQL> shutdown immediate;



Delete SYSTEM01.DBF file in ORCL directory



SQL> startup;



Error occurs that SYSTEM01.DBF file is deleted. Read Error Carefully



Now again shutdown the database



RMAN> run {
Allocate channel t1 type disk;
Set new_name for datafile 1 to ‘/opt/oracle/oradata/orcl/system01.dbf’;
Restore datafile 1;
Switch datafile all;
Recover datafile 1;

}



SQL> startup;

Comments

Popular posts from this blog

Create Tables in Oracle Database using TOAD

How to create Oracle stored Procedures using TOAD for Oracle

How to Create Packages in Oracle Database using TOAD for Oracle