RMAN Backup and Restoration Guide


This guide covers the essential steps for taking RMAN backups and performing restorations, including handling archivelog modes and restoring to different locations.

Part 1: Taking an RMAN Backup

1. Preparation

First, create a directory to store the backups and generate a parameter file (pfile) from your current server parameter file (spfile).

Create the backup directory:

mkdir /u01/RMAN_BACKUP

Create the pfile backup: Connect to SQL*Plus and create the pfile in your new directory.

sqlplus / as sysdba
CREATE pfile='/u01/RMAN_BACKUP/init<db_name>.ora' FROM spfile;

2. Configure Archivelog Mode

To take a full online backup while the database is running, the database must be in Archivelog Mode.

Note: If you cannot change the mode, you can take an offline backup by mounting the database (where logs stop generating) and backing up just the database. However, the steps below assume we are switching to archivelog mode to capture both the database and archive logs.

Steps to enable Archivelog Mode:

-- Shut down the database
SHUTDOWN IMMEDIATE;

-- Mount the database
STARTUP MOUNT;

-- Enable archivelog mode
ALTER DATABASE ARCHIVELOG;

-- Open the database
ALTER DATABASE OPEN;

-- Verify the mode is enabled
ARCHIVE LOG LIST;

3. Execute the Backup

Connect to RMAN and execute the backup commands.

Standard Backup (Database + Logs):

RMAN target /

-- Backup database
BACKUP AS COMPRESSED BACKUPSET DATABASE FORMAT '/u01/RMAN_BACKUPS/<name_for_backup_file>_%U.bkp';

-- Backup archive logs
BACKUP AS COMPRESSED BACKUPSET ARCHIVELOG ALL FORMAT '/u01/RMAN_BACKUPS/<name_for_backup_file>_%U.bkp';

Backup Control File: Always perform this step last.

BACKUP CURRENT CONTROLFILE FORMAT '/u01/RMAN_BACKUPS/control_TESTDB.ctl';

4. Backup Variations

Option A: Single Command (Database + Archivelogs) You can combine the operations into a single command for efficiency.

BACKUP AS COMPRESSED BACKUPSET 
DATABASE FORMAT '/u01/RMAN_BACKUPS/<name_for_backup_file>_%U.bkp' 
PLUS ARCHIVELOG ALL FORMAT '/u01/RMAN_BACKUPS/<name_for_backup_file>_arch_%U.arc';

Option B: Parallel Channels (Faster Execution) Allocating multiple channels can reduce backup duration.

Warning: Be careful not to over-allocate channels as this can sometimes cause the backup to take longer or strain system resources.

RUN {
  ALLOCATE CHANNEL c1 DEVICE TYPE DISK FORMAT '/u01/RMAN_BACKUPS/%d_%U.bkp';
  ALLOCATE CHANNEL c2 DEVICE TYPE DISK FORMAT '/u01/RMAN_BACKUPS/%d_%U.bkp';
  BACKUP AS COMPRESSED BACKUPSET DATABASE PLUS ARCHIVELOG;
  RELEASE CHANNEL c1;
  RELEASE CHANNEL c2;
}

Part 2: Restoring an RMAN Backup

1. Prepare the Environment

Add the Oracle SID to the oratab file. Ensure the DB home parameter is correct.
Edit oratab:

vi /etc/oratab

-- Add your entry:
<SID_of_DB>:/u01/app/oracle/product/19.0.0/dbhome_1:N

2. Restore the Database

Connect via SQL*Plus and start the instance in NOMOUNT mode using the pfile created during preparation.

sqlplus / as sysdba
STARTUP NOMOUNT pfile='/u01/RMAN_BACKUPS/init<db_name>.ora';
EXIT;

Restore Control File and Mount: Connect to RMAN to restore the control file and mount the database.

RMAN target /
RESTORE CONTROLFILE FROM '/u01/RMAN_BACKUPS/control_TESTDB.ctl';
ALTER DATABASE MOUNT;

Catalog Backups (If Moved): If your backup files were moved to a different location after creation catalog the new path.

CATALOG START WITH "path/to/new/location";

Restore and Recover:

RESTORE DATABASE;
RECOVER DATABASE;
EXIT;

Open Database: Finally, open the database with RESETLOGS.

sqlplus / as sysdba
ALTER DATABASE OPEN RESETLOGS;

Part 3: Advanced Restoration Scenarios (New Locations)

If you are restoring datafiles to a location different from the original (e.g., Filesystem to ASM or a new directory), follow these specific steps.

First, check the current schema to identify file IDs:

RMAN> REPORT SCHEMA;

Scenario A: Filesystem to ASM

Use SET NEWNAME to point files to the ASM disk group (+DATA).

RUN {
  SET NEWNAME FOR DATABASE TO '+DATA';
  SET NEWNAME FOR TEMPFILE 1 TO '+DATA/LIFEME/TEMPFILE/temp01.dbf';
  SET NEWNAME FOR TEMPFILE 2 TO '+DATA/LIFEME/TEMPFILE/temp02.dbf';
  SET NEWNAME FOR TEMPFILE 3 TO '+DATA/LIFEME/TEMPFILE/temp03.dbf';
  
  RESTORE DATABASE;
  SWITCH DATAFILE ALL;
  SWITCH TEMPFILE ALL;
  RECOVER DATABASE;
}

Scenario B: Filesystem to New Filesystem Path

Map each datafile ID to its new specific file path.

RUN {
  SET NEWNAME FOR DATAFILE 1 TO '/u01/app/oracle/oradata2/TESTDB/datafile/o1_mf_system_mrnbjpbm_.dbf';
  SET NEWNAME FOR DATAFILE 2 TO '/u01/app/oracle/oradata2/TESTDB/datafile/TESTUSER_TS.dbf';
  SET NEWNAME FOR DATAFILE 3 TO '/u01/app/oracle/oradata2/TESTDB/datafile/o1_mf_sysaux_mrnbjpbn_.dbf';
  SET NEWNAME FOR DATAFILE 4 TO '/u01/app/oracle/oradata2/TESTDB/datafile/o1_mf_undotbs1_mrnbjpc0_.dbf';
  SET NEWNAME FOR DATAFILE 5 TO '/u01/app/oracle/oradata2/TESTDB/datafile/HRUSER_TBS.dbf';
  SET NEWNAME FOR DATAFILE 7 TO '/u01/app/oracle/oradata2/TESTDB/datafile/o1_mf_users_mrnbjpc1_.dbf';
  SET NEWNAME FOR DATAFILE 8 TO '/u01/app/oracle/oradata2/TESTDB/datafile/NATIONALPVC01.dbf';
  SET NEWNAME FOR TEMPFILE 1 TO '/u01/app/oracle/oradata2/TESTDB/datafile/o1_mf_temp_mrnbo1y2_.tmp';
  RESTORE DATABASE;
  SWITCH DATAFILE ALL;
  SWITCH TEMPFILE ALL;
  RECOVER DATABASE;
}

Scenario C: ASM to ASM (Restoring to a Different Disk Group)

If you are restoring from one ASM disk group (e.g., +DATA) to a different ASM disk group (e.g., +DATA_NEW), use the following commands.

RUN {
  -- Set the new ASM disk group destination for all datafiles
  SET NEWNAME FOR DATABASE TO '+DATA_NEW';
  
  -- Explicitly set new locations for tempfiles if needed
  SET NEWNAME FOR TEMPFILE 1 TO '+DATA_NEW/LIFEME/TEMPFILE/temp01.dbf';

  RESTORE DATABASE;
  SWITCH DATAFILE ALL;
  SWITCH TEMPFILE ALL;
  RECOVER DATABASE;
}

Scenario D: ASM to Filesystem

If you are restoring a backup taken from an ASM environment onto a regular filesystem (OS directory), you must map the ASM files to specific filesystem paths.

RUN {
  -- Map ASM datafiles to the new filesystem paths
  SET NEWNAME FOR DATAFILE 1 TO '/u01/app/oracle/oradata2/TESTDB/system01.dbf';
  SET NEWNAME FOR DATAFILE 2 TO '/u01/app/oracle/oradata2/TESTDB/sysaux01.dbf';
  SET NEWNAME FOR DATAFILE 3 TO '/u01/app/oracle/oradata2/TESTDB/undotbs01.dbf';
  SET NEWNAME FOR DATAFILE 4 TO '/u01/app/oracle/oradata2/TESTDB/users01.dbf';
  
  -- Map ASM tempfiles to the filesystem
  SET NEWNAME FOR TEMPFILE 1 TO '/u01/app/oracle/oradata2/TESTDB/temp01.dbf';

  RESTORE DATABASE;
  SWITCH DATAFILE ALL;
  SWITCH TEMPFILE ALL;
  RECOVER DATABASE;
}

Comments

Popular posts from this blog

Installing Oracle Database 19c on Linux 8 (OL8) Server

Oracle GoldenGate Real-Time Replication (Unidirectional)

Repository Configuration Utility (RCU) for Oracle Forms & Reports