Friday, November 20, 2009

Cloning Oracle database/Hotbackup Restoration/Synchronize Production database with Test database

Description:
We can use the below methods to synchronize/clone Production database to Test database. Before discussing about clone the database. I would like recall Hotbackup process.

Hotbackup Process:
Step 1: Login as “SYSDBA” using the below
$sqlplus “/as sysdba”
Step 2: Change the database to Begin backup mode using the below command.
SQL>alter database begin backup;
Note: “alter database begin backup” command will change all tablespaces to begin backup mode (starting from Oracle10g).
Step 3: Copy all the datafiles to Hotbackup location using “cp” (unix) / “ocopy” (windows)
Step 4: Change the database to End Backup mode using the below command
SQL>alter database end backup;
Step 5: Take the control file backup using the below command
SQL> alter database backup controlfile to '/Hotbackuplocation/control.sql';
Sample Control File:
CREATE CONTROLFILE REUSE DATABASE "TESTDB" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 454
LOGFILE
GROUP 1 'ORACLE_HOME/TESTDB/REDO01.LOG' SIZE 40M,
GROUP 2 'ORACLE_HOME/TESTDB/REDO02.LOG' SIZE 40M,
GROUP 3 'ORACLE_HOME/TESTDB/REDO03.LOG' SIZE 40M
-- STANDBY LOGFILE
DATAFILE
'ORACLE_HOME/TESTDB/SYSTEM01.DBF',
'ORACLE_HOME/TESTDB/UNDOTBS01.DBF',
'ORACLE_HOME/TESTDB/SYSAUX01.DBF',
'ORACLE_HOME/TESTDB/USERS01.DBF',
'ORACLE_HOME/TESTDB/TESTDB_BIG_TAB01.DBF',
'ORACLE_HOME/TESTDB/TESTDB_SMALL_TAB01.DBF',
'ORACLE_HOME/TESTDB/TESTDB_BIG_IDX01.DBF ',
'ORACLE_HOME/TESTDB/TESTDB_SMALL_IDX01.DBF'
CHARACTER SET WE8MSWIN1252
;
Cloning Databases/Hotbackup Restoration/Synchronize Production database with Test database

Step 1: Shutdown the test database if it is already running
SQL>shutdown immediate or SQL>shutdown abort
Step 2: Copy all the Hotbackup datafiles and control file backup from Production/Source database to test database.
Note: Initially, you can copy all the Hotbackup datafiles to one directory and then you can spread all the datafiles to the destination directory. If have space constraint, you can keep all the files in one directory, but you should change the path of the datafiles in control file. You check the control file’s datafile location and OS datafiles location, it should match or you may get the error.
Step 3: Start the database in NO MOUNT stage
SQL>startup nomount
Step 4: Create control file using the control file backup.
Step 5: Mount the database using below command
SQL> alter database mount;
Step 6: Recover the database using backup controlfile
SQL>recover database until cancel using backup controlfile;
Step 7: Database prompts for archivelog file and/ or redolog file names. It keeps failing until the redo log file with matching SCN is provided.
Please check the below link to do recovery with redolog file.
http://ragudba.blogspot.com/2009/11/ora-01113-media-recovery.html
Step 8: Open the database using the below command
SQL> alter database open resetlogs;
Database opened.
Step 9: After recovery you check the Temp tablespace exists or not. If did not exists, Create the Temporary tablespace using the below
ALTER TABLESPACE TEMP ADD TEMPFILE 'ORACLE_HOME/TESTDB/TEMP01.DBF'
SIZE 28311552 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M;

No comments: