Duplicate a database using Rman backups in oracle 11gR2.
Duplicating a database or database cloning creates a seperate database that contains all or subset of the source database. Here we don't have to establish the network connection between the source and target host servers, we just need to copy all the rman backups to the target server.
The source database name is "testdb" and I am duplicating with the same name as the source database in the target server. The source hostname is test and the that of target is test1.
SOURCE SERVER
Copy the rman backups to the target server
Copy the spfile and control file auto backup
[oracle@test ~]$ cd /u01/app/oracle/flash_recovery_area/TESTDB/autobackup/2013_05_06
[oracle@test 2013_05_06]$ ls -lrt
total 28848
-rw-r----- 1 oracle oinstall 9830400 May 6 08:44 o1_mf_s_814697065_8rg80p21_.bkp
-rw-r----- 1 oracle oinstall 9830400 May 6 08:57 o1_mf_s_814697863_8rg8sk2o_.bkp
-rw-r----- 1 oracle oinstall 9830400 May 6 21:22 o1_mf_s_814742526_8rhnfbd2_.bkp
[oracle@test 2013_05_06]$ scp o1_mf_s_814742526_8rhnfbd2_.bkp oracle@192.168.1.193:/u01/app/oradata/backup/
oracle@192.168.1.193's password:
o1_mf_s_814742526_8rhnfbd2_.bkp 100% 9600KB 9.4MB/s 00:01
Copy the backup sets of all the datafiles and archive logs
[oracle@test 2013_05_06]$ cd /u01/app/oradata/backup/
[oracle@test backup]$ ls -lrt
total 1089744
-rw-r----- 1 oracle oinstall 36849152 May 6 21:15 df_0do8vuj3_1_1.dbf
-rw-r----- 1 oracle oinstall 1077731328 May 6 21:21 df_0eo8vujn_1_1.dbf
-rw-r----- 1 oracle oinstall 212992 May 6 21:22 df_0fo8vuvs_1_1.dbf
[oracle@test backup]$ scp * oracle@192.168.1.193:/u01/app/oradata/backup/
oracle@192.168.1.193's password:
df_0do8vuj3_1_1.dbf 100% 35MB 3.9MB/s 00:09
df_0eo8vujn_1_1.dbf 100% 1028MB 2.6MB/s 06:37
df_0fo8vuvs_1_1.dbf 100% 208KB 208.0KB/s 00:00
[oracle@test backup]$
TARGET SERVER
Check to see all the backups are copied to the target server location
[oracle@test1 ~]$ cd /u01/app/oradata/backup/
[oracle@test1 backup]$ ls -lrt
total 1099360
-rw-r----- 1 oracle oinstall 9830400 May 6 21:28 o1_mf_s_814742526_8rhnfbd2_.bkp
-rw-r----- 1 oracle oinstall 36849152 May 6 21:28 df_0do8vuj3_1_1.dbf
-rw-r----- 1 oracle oinstall 212992 May 6 21:35 df_0fo8vuvs_1_1.dbf
-rw-r----- 1 oracle oinstall 1077731328 May 6 21:35 df_0eo8vujn_1_1.dbf
[oracle@test1 backup]$ pwd
/u01/app/oradata/backup
[oracle@test1 backup]$
Create the necessary directories
Here I have created all the directories same as that of source server.
[oracle@test1 ~]$ mkdir -p /u01/app/oracle/oradata/testdb
[oracle@test1 ~]$ mkdir -p /u01/app/oracle/fast_recovery_area/testdb
[oracle@test1 ~]$ mkdir -p /u01/app/oracle/admin/testdb/adump
Create a pfile with the name inittestdb.ora
Create a pfile with only one parameter DB_NAME, rest of the parameters will be available from the spfile backup during duplication.
[oracle@test1 ~]$ cd $ORACLE_HOME/dbs
[oracle@test1 ~]$ cat inittestdb.ora
DB_NAME=testdb
[oracle@test1 ~]$
Start the duplicate database in nomount
[oracle@test1 ~]$ export ORACLE_SID=testdb
[oracle@test1 ~]$ sqlplus
SQL*Plus: Release 11.2.0.1.0 Production on Tue May 7 22:15:20 2013
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Enter user-name: /as sysdba
Connected to an idle instance.
SQL> startup nomount
ORACLE instance started.
Total System Global Area 1000189952 bytes
Fixed Size 1340832 bytes
Variable Size 570428000 bytes
Database Buffers 423624704 bytes
Redo Buffers 4796416 bytes
SQL>
Connect to duplicate database using rman
Open another terminal and connect to the duplicate database using rman.
[oracle@test1 ~]$ export ORACLE_SID=testdb
[oracle@test1 adump]$ rman auxiliary /
Recovery Manager: Release 11.2.0.1.0 - Production on Mon May 6 09:09:03 2013
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to auxiliary database: TESTDB (not mounted)
RMAN>
Duplicate the target database using spfile and the backups
RMAN> duplicate target database to testdb spfile backup location '/u01/app/oradata/backup/' nofilenamecheck;
Starting Duplicate Db at 06-MAY-13
contents of Memory Script:
{
restore clone spfile to '/u01/app/oracle/product/11.2.0/db_1/dbs/spfiletestdb.ora' from
'/u01/app/oradata/backup/sp_08o8uij7_1_1';
sql clone "alter system set spfile= ''/u01/app/oracle/product/11.2.0/db_1/dbs/spfiletestdb.ora''";
}
executing Memory Script
Starting restore at 06-MAY-13
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=20 device type=DISK
channel ORA_AUX_DISK_1: restoring spfile from AUTOBACKUP /u01/app/oradata/backup/sp_08o8uij7_1_1
channel ORA_AUX_DISK_1: SPFILE restore from AUTOBACKUP complete
Finished restore at 06-MAY-13
sql statement: alter system set spfile= ''/u01/app/oracle/product/11.2.0/db_1/dbs/spfiletestdb.ora''
contents of Memory Script:
{
sql clone "alter system set db_name =
''TESTDB'' comment=
''duplicate'' scope=spfile";
shutdown clone immediate;
startup clone nomount;
}
executing Memory Script
sql statement: alter system set db_name = ''TESTDB'' comment= ''duplicate'' scope=spfile
Oracle instance shut down
connected to auxiliary database (not started)
Oracle instance started
Total System Global Area 1000189952 bytes
Fixed Size 1340832 bytes
Variable Size 570428000 bytes
Database Buffers 423624704 bytes
Redo Buffers 4796416 bytes
contents of Memory Script:
{
sql clone "alter system set db_name =
''TESTDB'' comment=
''Modified by RMAN duplicate'' scope=spfile";
sql clone "alter system set db_unique_name =
''TESTDB'' comment=
''Modified by RMAN duplicate'' scope=spfile";
shutdown clone immediate;
startup clone force nomount
restore clone primary controlfile from '/u01/app/oradata/backup/ctl_0bo8ujc1_1_1.ctl';
alter clone database mount;
}
executing Memory Script
sql statement: alter system set db_name = ''TESTDB'' comment= ''Modified by RMAN duplicate'' scope=spfile
sql statement: alter system set db_unique_name = ''TESTDB'' comment= ''Modified by RMAN duplicate'' scope=spfile
Oracle instance shut down
Oracle instance started
Total System Global Area 1000189952 bytes
Fixed Size 1340832 bytes
Variable Size 570428000 bytes
Database Buffers 423624704 bytes
Redo Buffers 4796416 bytes
Starting restore at 06-MAY-13
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=1 device type=DISK
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:18
output file name=/u01/app/oracle/oradata/testdb/control01.ctl
output file name=/u01/app/oracle/flash_recovery_area/testdb/control02.ctl
Finished restore at 06-MAY-13
database mounted
released channel: ORA_AUX_DISK_1
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=1 device type=DISK
RMAN-05538: WARNING: implicitly using DB_FILE_NAME_CONVERT
contents of Memory Script:
{
set until scn 872040;
set newname for datafile 1 to
"/u01/app/oracle/oradata/testdb/system01.dbf";
set newname for datafile 2 to
"/u01/app/oracle/oradata/testdb/sysaux01.dbf";
set newname for datafile 3 to
"/u01/app/oracle/oradata/testdb/undotbs01.dbf";
set newname for datafile 4 to
"/u01/app/oracle/oradata/testdb/users01.dbf";
set newname for datafile 5 to
"/u01/app/oracle/oradata/testdb/example01.dbf";
restore
clone database
;
}
executing Memory Script
executing command: SET until clause
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting restore at 06-MAY-13
using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/testdb/system01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/testdb/sysaux01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/testdb/undotbs01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/testdb/users01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/testdb/example01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oradata/backup/df_03o8t92i_1_1.dbf
channel ORA_AUX_DISK_1: piece handle=/u01/app/oradata/backup/df_03o8t92i_1_1.dbf tag=TAG20130505T205546
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:10:23
Finished restore at 06-MAY-13
contents of Memory Script:
{
switch clone datafile all;
}
executing Memory Script
datafile 1 switched to datafile copy
input datafile copy RECID=1 STAMP=814699313 file name=/u01/app/oracle/oradata/testdb/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=2 STAMP=814699314 file name=/u01/app/oracle/oradata/testdb/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=3 STAMP=814699314 file name=/u01/app/oracle/oradata/testdb/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=4 STAMP=814699314 file name=/u01/app/oracle/oradata/testdb/users01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=5 STAMP=814699314 file name=/u01/app/oracle/oradata/testdb/example01.dbf
contents of Memory Script:
{
set until scn 872040;
recover
clone database
delete archivelog
;
}
executing Memory Script
executing command: SET until clause
Starting recover at 06-MAY-13
using channel ORA_AUX_DISK_1
starting media recovery
channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=1 sequence=8
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oradata/backup/df_04o8t99r_1_1.dbf
channel ORA_AUX_DISK_1: piece handle=/u01/app/oradata/backup/df_04o8t99r_1_1.dbf tag=TAG20130505T205938
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/u01/app/oracle/flash_recovery_area/TESTDB/archivelog/2013_05_06/o1_mf_1_8_8rgb6zvd_.arc thread=1 sequence=8
channel clone_default: deleting archived log(s)
archived log file name=/u01/app/oracle/flash_recovery_area/TESTDB/archivelog/2013_05_06/o1_mf_1_8_8rgb6zvd_.arc RECID=1 STAMP=814699319
media recovery complete, elapsed time: 00:00:09
Finished recover at 06-MAY-13
contents of Memory Script:
{
shutdown clone immediate;
startup clone nomount;
sql clone "alter system set db_name =
''TESTDB'' comment=
''Reset to original value by RMAN'' scope=spfile";
sql clone "alter system reset db_unique_name scope=spfile";
shutdown clone immediate;
startup clone nomount;
}
executing Memory Script
database dismounted
Oracle instance shut down
connected to auxiliary database (not started)
Oracle instance started
Total System Global Area 1000189952 bytes
Fixed Size 1340832 bytes
Variable Size 570428000 bytes
Database Buffers 423624704 bytes
Redo Buffers 4796416 bytes
sql statement: alter system set db_name = ''TESTDB'' comment= ''Reset to original value by RMAN'' scope=spfile
sql statement: alter system reset db_unique_name scope=spfile
Oracle instance shut down
connected to auxiliary database (not started)
Oracle instance started
Total System Global Area 1000189952 bytes
Fixed Size 1340832 bytes
Variable Size 570428000 bytes
Database Buffers 423624704 bytes
Redo Buffers 4796416 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "TESTDB" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 SIZE 50 M ,
GROUP 2 SIZE 50 M ,
GROUP 3 SIZE 50 M
DATAFILE
'/u01/app/oracle/oradata/testdb/system01.dbf'
CHARACTER SET AL32UTF8
contents of Memory Script:
{
set newname for tempfile 1 to
"/u01/app/oracle/oradata/testdb/temp01.dbf";
switch clone tempfile all;
catalog clone datafilecopy "/u01/app/oracle/oradata/testdb/sysaux01.dbf",
"/u01/app/oracle/oradata/testdb/undotbs01.dbf",
"/u01/app/oracle/oradata/testdb/users01.dbf",
"/u01/app/oracle/oradata/testdb/example01.dbf";
switch clone datafile all;
}
executing Memory Script
executing command: SET NEWNAME
renamed tempfile 1 to /u01/app/oracle/oradata/testdb/temp01.dbf in control file
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/testdb/sysaux01.dbf RECID=1 STAMP=814699360
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/testdb/undotbs01.dbf RECID=2 STAMP=814699360
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/testdb/users01.dbf RECID=3 STAMP=814699360
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/testdb/example01.dbf RECID=4 STAMP=814699360
datafile 2 switched to datafile copy
input datafile copy RECID=1 STAMP=814699360 file name=/u01/app/oracle/oradata/testdb/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=2 STAMP=814699360 file name=/u01/app/oracle/oradata/testdb/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=3 STAMP=814699360 file name=/u01/app/oracle/oradata/testdb/users01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=4 STAMP=814699360 file name=/u01/app/oracle/oradata/testdb/example01.dbf
contents of Memory Script:
{
Alter clone database open resetlogs;
}
executing Memory Script
database opened
Finished Duplicate Db at 06-MAY-13
RMAN>
The duplicate database is ready in the new server and we can use it for our testing purpose.
22:28:07 SQL> select instance_name,status from v$instance;
INSTANCE_NAME STATUS
---------------- ------------
testdb OPEN
Elapsed: 00:00:00.01
22:28:34 SQL>
kindly check no need of spfile
ReplyDelete