Tuesday, October 6, 2009

Step-by-step instructions on how to using RMAN DUPLICATE to restore/duplicate a database

To test my backup and recovery procedures, I restore the Production database backup into the testing database once a year, and conduct tests against the new database through the testing application. Since the DBID is different, I can’t use RESTORE and RECOVER commands. RMAN DUPLICATE is used for restore/recovery instead.

Here I list steps instructions on how to using RMAN DUPLICATE to restore/duplicate a database on Windows and UNIX servers, either on a new machine or local machine.

My settings in this case are:

- The Database version is 10.2.0.3;
- The production database (the target database) is called TARG and the testing database (the duplicate database) is called DUPL;
- Archive log mode is enabled on TARG. Weekly hot whole database backup of TARG is taken to disk by RMAN and then copied to tape. The archive log files are also backed up and deleted with the weekly backup.
- The Tape backup and archived log files on disk are used for restore/recovery in this example;
- I use Flash Recovery Area to store backup related files;
- The directory structure of two systems are identical;
- No recovery catalog is used.

1 Before you get started:

1) Make sure the operating system on the target and duplicate systems are the same.
2) Make sure the same Oracle software release is used on the target and duplicate databases.
3) Make sure you have the necessary backups of the target database. Ensure sure the backups, and the archived redo logs if needed, are accessible from the duplicate site.
4) Exam your RMAN configuration. Login to target database as a user with sysdba privileges.
$rman target /@TARG
RMAN> show all;

RMAN configuration parameters are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 2;
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default
CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO BACKUPSET PARALLELISM 1;
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO 'E:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\SNCFTARG.ORA'; # default

2 Delete the testing database using Oracle DBCA.
Retain a backup of the testing database in case the duplicate fails and you need to restore the original testing database.

If you want to restore/duplicate the database to a new server, install Oracle Database software without the starter database, and then patch it if needed.

3 Copy the appropriate tape backup files to Target database backup location using your tape management tool.
I renamed the original disk backup of TARG instead of overwriting it.

4 Create a password file for the testing database DUPL. The password for SYS must be identical on both databases.

- On Windows:
$cd %ORACLE_HOME%\database
$orapwd file=pwdDUPL.ora password=xxxxxxxx force=y
(Note: Replace xxxxxxxxx with your actual password for the SYS user.)

- On UNIX:
$cd $ORACLE_HOME/dbs
$Orapwd file=pwdDUPL.ora password=xxxxxxxx force=y
(Note: Replace xxxxxxxxx with your actual password for the SYS user.)

5 Update tnsnames.ora and listener.ora of the Target database to add the duplicate database entries.

6 Create an Initialization parameter for the duplicate database.
On Target database TARG, issue the following command:

- On Windows:
SQL>create pfile=’\database\pfileDUPL.ora’ from spfile;
(Note- specify your Oracle home path to replace ‘’).

- On UNIX:
SQL>create pfile=’/dbs/pfileDUPL.ora’ from spfile;
(Note- specify your Oracle home path to replace ‘’).

7 Copy pfileDUPL.ora to duplicate database site and edit it.

1) Copy it to \database directory on Windows or /dbs directory on UNIX.
2) Modify this pfile to include parameters DB_NAME, CONTROL_FILES, DB_FILE_NAME_CONVERT and LOG_FILE_NAME_CONVERT. For example (here the file paths are from a windows system. For UNIX system, specify the path accordingly):

db_name='DUPL'
control_files='E:\ORACLE\PRODUCT\10.2.0\ORADATA\DUPL\CONTROLFILE\CONTROL01.CTL', 'F:\ORACLE\FLASH_RECOVERY_AREA\DEVL\CONTROLFILE\CONTROL02.CTL'
# Specify the location of the target DB datafiles followed by the duplicate location
db_file_name_convert='E:\oracle\product\10.2.0\oradata\TARG\DATAFILE', 'E:\oracle\Product\10.2.0\oradata\DUPL\DATAFILE'
# Specify the location of the target DB online redo log files followed by the duplicate location
log_file_name_convert='E:\oracle\product\10.2.0\oradata\TARG\ONLINELOG', 'E:\oracle\product\10.2.0\oradata\DUPL\ONLINELOG', 'F:\oracle\flash_recovery_area\TARG\ONLINELOG','F:\oracle\flash_recovery_area\DUPL\ONLINELOG'

Modify some other parameters for DUPL such as adump, bdump, cdump, udump, and dpdump.

8 Create following dump directories for the duplicate database.
Create adump, bdump, cdump, udump, dpdump directories.

9 Create data directories where you want to store new data files.
Create directories for controlfile, datafile and onlinelog.

10 On Windows start the Oracle Services.

$oradim –new –sid DUPL –startmode auto

Now go to control panel>administrative tools, open services and see whether oracle services for DUPL is running.

Change the Oracle DB Server account from local system to a user with administrative account. After the change, stop and start Oracle DB Services.

11 Startup nomount the Duplicate instance and generate a spfile.

- On Windows:
SQL>shutdown immediate
SQL>startup nomount pfile=’\database\initDUPL.ora’;
SQL> create spfile from pfile=’\database\initDUPL.ora';
-- Restart the duplicate instance using the newly created SPFILE.
SQL>shutdown immediate;
SQL>startup mount;

- On UNIX:
SQL>shutdown immediate
SQL>startup nomount pfile=’/dbs/initDUPL.ora’;
SQL> create spfile from pfile=’/dbs/initDUPL.ora';
-- Restart the duplicate instance using the newly created SPFILE.
SQL>shutdown immediate;
SQL>startup mount;

12 Mount or open the target database TARG if it is not already mount or open.

13 Ensure you have the necessary backups and archived redo logs.
$rman target /@TARG
Rman>list backup summary
Rman>exit

14 Resote/Duplicate the database using RMAN DUPLICATE command.

1) Login to the target and duplicate database
$rman target /@TARG auxiliary /@DUPL

2) Run the RMAN duplicate command:

RMAN>run {
allocate auxiliary channel ch1 type disk;
duplicate target database to DUPL;
}

15 Create DB console for the duplicate database.
- On Windows
$cd %ORACLE_HOME%\bin
$emca –config dbcontrol db

- On UNIX
$cd $ORACLE_HOME/bin
$emca –config dbcontrol db

Enter SID, password for users sys, sysman, dbsnmp when prompted.

16 Modify settings in Application and the DUPL database to reflect the changes if necessary.

17 Test the duplicate database through Oracle tools and through the front-end application.

No comments:

Post a Comment