Vincent Prouillet

Hey, it made my day !

RMAN

RMAN (Recovery Manager) is the the backup and recovery tool recommended by Oracle.

There are several ways to create RMAN jobs : EM interface, command-line and scripts.Before the technical stuff, we should learn the backup vocabulary.

First of all, there is 2 types of backup : user-managed (using OS commands) and server-managed (using database tools like RMAN).

This article will only deal with backup of the second type.

There are 3 choices to make :

  • closed (database is shutdown) or open (database is running, but needs to be in archivelog mode)
  • whole (backup of all the datafiles and control files) or partial (only a part of it)
  • full (backup of all the files) or incremental (backup of only the blocks that changed since the last backup)

RMAN can backup datafile, archive redo log, SPFILE and control file and offers 3 types of backup type : backup set (oracle format which needs to be restored before use), compressed backup set (same as backup set but compressed) and image copy (immediatly interchangeable with the source).

The backup and recovery operations are done using processes known as channels (disk or tape).

The RMAN repository contains metadata about the target database and its backup (name, location) and is stored in the controlfile of the target database.

Optionnaly, you can store it in a catalog database.

You can also use an auxiliary database, created from a backup from the target database.

Consistent backups

We can do that in command line or with EM.

EM 10g version : Maintenance > Schedule Backup > choose customized as backup strategy
EM 11g version : Availabilty > Schedule Backup > choose customized as backup strategy
Select Offline Backup and follow instructions

Command line version : create a script backup_full_offline.rman

run {
shutdown immediate;
startup mount;
allocate channel c1 type disk;
backup as backupset database
format 'd:\backup\offline_full_whole.bus';
alter database open;
}

and run it with :

 rman target sys/oracle@orcl11g @offline_full_whole.rman

Or run each command separately in the rman appli.

Open backups

This backup is of course also reliable (database must be in archivelog mode).
Same as before.
Example of a script :

run {
allocate channel c1 type disk; #2 channels for parallelisation
allocate channel c2 type disk;
backup
format '/home/oracle/%d_t%t_s%s_p%p' #d = database_id, s = backup set number, p = piece number
(database); #save everything including archivelog files
release channel c1;
release channel c2;
}

You can also assign a tag to a backupset (a logical name).

To check if the database can be restored, use:

 restore database validate

Incremental backups

Incremental backups relies on a first full backup of the database, known as level 0.

backup as backupset incremental level 0 database plus archivelog;

When the level 0 backup is done, we will perform level 1 backup that will backup only the block that have changed since the last level 0 backup.

backup as backupset incremental level 1 database plus archivelog;

You can specify if you want the incremental backup to be cumulative (quicker) or differential (default value).
Not necessarily faster than full backup because you have to scan the whole backup to look for changes.
There’s a process to speed this up : Change Tracking Writer which will write the address of each block that has changed in a file.

Copy images

Make an identical copy of datafiles/controlfile/archivelog

backup as copy database; #backup datafile and controlfile to the flash area
backup as copy archivelog all delete all input; #backup archivelog files to the flash area

Backup of backups

If you use tapes you can use these commands :

backup recovery area;
backup recovery files;

which will backup the flash area and files related to recovery to tape.

Managing backups

You can check the backup sets, copies or other files using list :

LIST backup;
LIST copy;
LIST backup of archivelog all;

You can also ask what needs to be backed up or obsolete files :

REPORT need backup;
REPORT obsolete;

LIST and REPORT commands use the rman repository for information and thus we can’t be sure if the files really exist. To check, use this command :

CROSSCHECK backup of database;

If there is data in rman repository but there isn’t corresponding files, use this :

DELETE EXPIRED backup;
DELETE obsolete will delete the files and the info in the repository.

Recover and restore

The DRA (Data Recovery Advisor) is a new tool in 11g used for diagnosing and repairing databases.
Commands :

list failure;
advise failure; #generate script to repaire the failure
repair failure; #start the script

To restore a database, use :

#optional : set until time | to recover the database until that ime
restore database;
recover database; #use the archive logs to repeat the queries
alter database open resetlogs; #reset the online redo logs

If you want to restore only a tablespace or a datafile :

restore datafile '/disk/something.dbf';
restore tablespace example;

You also have to ensure the controlfile (vital for the database) will be have an autobackup :

configure controlfile autobackup on;

This command will enable an automatic backup of controlfile during every RMAN operation that can be easily restored :

restore controlfile from autobackup;

If you want to restore a database that has a copy image :

switch database to copy;

Leave a Reply