Sunday, June 1, 2014

Duplicate database on the same host using rman backups

1.Backup the target database
backup database plus archivelog;
rman target ="/"

Recovery Manager: Release 11.2.0.4.0 - Production on Sun Jun 1 08:38:09 2014

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: CVRMAN (DBID=657566608)

RMAN> @ rman_backup.cmd

RMAN> backup database plus archivelog;

Starting backup at 01-JUN-14
current log archived
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=54 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=37 device type=DISK
skipping archived logs of thread 1 from sequence 3 to 8; already backed up
skipping archived logs of thread 1 from sequence 1 to 6; already backed up
skipping archived logs of thread 1 from sequence 1 to 7; already backed up
skipping archived logs of thread 1 from sequence 1 to 2; already backed up
skipping archived logs of thread 1 from sequence 1 to 2; already backed up
skipping archived logs of thread 1 from sequence 1 to 7; already backed up
skipping archived log of thread 1 with sequence 10; already backed up
skipping archived logs of thread 1 from sequence 13 to 18; already backed up
skipping archived logs of thread 1 from sequence 16 to 17; already backed up
skipping archived logs of thread 1 from sequence 1 to 8; already backed up
skipping archived log of thread 1 with sequence 1; already backed up
skipping archived logs of thread 1 from sequence 1 to 2; already backed up
skipping archived logs of thread 1 from sequence 1 to 2; already backed up
channel ORA_DISK_1: starting compressed archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=4 RECID=70 STAMP=847791844
input archived log thread=1 sequence=5 RECID=68 STAMP=847791844
input archived log thread=1 sequence=6 RECID=72 STAMP=847791844
input archived log thread=1 sequence=7 RECID=74 STAMP=847791845
input archived log thread=1 sequence=8 RECID=69 STAMP=847791844
input archived log thread=1 sequence=9 RECID=71 STAMP=847791844
input archived log thread=1 sequence=12 RECID=67 STAMP=847791844
input archived log thread=1 sequence=13 RECID=75 STAMP=847791848
channel ORA_DISK_1: starting piece 1 at 01-JUN-14
channel ORA_DISK_2: starting compressed archived log backup set
channel ORA_DISK_2: specifying archived log(s) in backup set
input archived log thread=1 sequence=1 RECID=84 STAMP=847844115
input archived log thread=1 sequence=5 RECID=82 STAMP=847802452
input archived log thread=1 sequence=6 RECID=83 STAMP=847836581
input archived log thread=1 sequence=7 RECID=85 STAMP=847857575
input archived log thread=1 sequence=10 RECID=94 STAMP=847862997
channel ORA_DISK_2: starting piece 1 at 01-JUN-14

2.Add static listener configuration for auxiliary database in the listener.ora file and start the listener named cv_duplicate
cv_duplicate =
(DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = ************)(PORT = 1580))
    )
  )
SID_LIST_cv_duplicate=
(SID_LIST =
 (SID_DESC =
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0.4/db1)
      (SID_NAME = cvdup)
    )
  )

3.Start the listener with static configuration of auxiliary database
lsnrctl start  cv_duplicate

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 01-JUN-2014 09:24:57

Copyright (c) 1991, 2013, Oracle.  All rights reserved.

Starting /u01/app/oracle/product/11.2.0.4/db1/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 11.2.0.4.0 - Production
System parameter file is /u01/app/oracle/product/11.2.0.4/db1/network/admin/listener.ora
Log messages written to /u01/app/oracle/diag/tnslsnr/cv_duplicate/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=**********)(PORT=1580)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=*********)(PORT=1580)))
STATUS of the LISTENER
------------------------
Alias                     cv_duplicate
Version                   TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date                01-JUN-2014 09:24:57
Uptime                    0 days 0 hr. 0 min. 0 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/11.2.0.4/db1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/cv_duplicate/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=***********)(PORT=1580)))
Services Summary...
Service "cvdup" has 1 instance(s).
  Instance "cvdup", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully


4.Add the entry in the $ORACLE_HOME/network/admin/tnsnames.ora
cvdup =
(DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = *********)(PORT = 1580))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = cvdup)
    )
  )


5.Tnsping the service name cvdup
tnsping cvdup
TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 01-JUN-2014 09:29:49

Copyright (c) 1997, 2013, Oracle.  All rights reserved.

Used parameter files:
/u01/app/oracle/product/11.2.0.4/db1/network/admin/sqlnet.ora
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = ********)(PORT = 1580)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = cvdup)))
OK (230 msec)

6.Create the password file for the auxiliary database cvdup
$ orapwd file=orapwcvdup entries=20 password=sys123
$ ls -ltr orapwcvdup
-rw-r----- 1 oracle oinstall 3584 Jun  1 09:42 orapwcvdup

7.Create the pfile for the auxiliary database cvdup
vi initcvdup.ora
db_name=cvdup
db_block_size=8192
compatible=11.2.0.4.0
remote_login_passwordfile=exclusive
control_files=('+DATA/cvdup/controlfile/control01.dbf','+DATA/cvdup/controlfile/control02.dbf')
db_file_name_convert=('+DATA/CVRMAN/','+DATA/cvdup/')
log_file_name_convert=('+DATA/CVRMAN/','+DATA/cvdup/')

8.Start the instance in nomount mode using the pfile created in the step 7.
$ export ORACLE_SID=cvdup
$ sqlplus '/as sysdba'
SQL*Plus: Release 11.2.0.4.0 Production on Sun Jun 1 09:56:14 2014

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

Connected to an idle instance.

SQL> startup nomount pfile=$ORACLE_HOME/dbs/initcvdup.ora
ORACLE instance started.

Total System Global Area  217157632 bytes
Fixed Size                  2251816 bytes
Variable Size             159384536 bytes
Database Buffers           50331648 bytes
Redo Buffers                5189632 bytes

SQL> select instance_name,status from v$instance;

INSTANCE_NAME    STATUS
---------------- ------------
cvdup            STARTED

9.Connect auxiliary and target database using rman
$ export ORACLE_SID=CVRMAN
$ rman
Recovery Manager: Release 11.2.0.4.0 - Production on Sun Jun 1 10:00:25 2014

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

RMAN> connect target /

connected to target database: CVRMAN (DBID=657566608)

RMAN> connect auxiliary sys/sys123@cvdup

connected to auxiliary database: CVDUP (not mounted)
 
RMAN>

10.Duplicate the target database in the same host using RMAN duplicate command
RMAN> spool log to duplicate_cvdup.log
RMAN> duplicate target database to cvdup;
RMAN> spool log off
Spooling for log turned off
Recovery Manager11.2.0.4.0
Spooling started in log file: duplicate_cvdup.log

Recovery Manager11.2.0.4.0

RMAN> 
Starting Duplicate Db at 01-JUN-14
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=21 device type=DISK
allocated channel: ORA_AUX_DISK_2
channel ORA_AUX_DISK_2: SID=24 device type=DISK

contents of Memory Script:
{
   sql clone "create spfile from memory";
}
executing Memory Script

sql statement: create spfile from memory

contents of Memory Script:
{
   shutdown clone immediate;
   startup clone nomount;
}
executing Memory Script

Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area     217157632 bytes

Fixed Size                     2251816 bytes
Variable Size                159384536 bytes
Database Buffers              50331648 bytes
Redo Buffers                   5189632 bytes

contents of Memory Script:
{
   sql clone "alter system set  db_name = 
 ''CVRMAN'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
   sql clone "alter system set  db_unique_name = 
 ''CVDUP'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
   shutdown clone immediate;
   startup clone force nomount
   restore clone primary controlfile;
   alter clone database mount;
}
executing Memory Script

sql statement: alter system set  db_name =  ''CVRMAN'' comment= ''Modified by RMAN duplicate'' scope=spfile

sql statement: alter system set  db_unique_name =  ''CVDUP'' comment= ''Modified by RMAN duplicate'' scope=spfile

Oracle instance shut down

Oracle instance started

Total System Global Area     217157632 bytes

Fixed Size                     2251816 bytes
Variable Size                159384536 bytes
Database Buffers              50331648 bytes
Redo Buffers                   5189632 bytes

Starting restore at 01-JUN-14
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=24 device type=DISK
allocated channel: ORA_AUX_DISK_2
channel ORA_AUX_DISK_2: SID=25 device type=DISK

channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece +DATA/cvrman/backupset/2014_06_01/ncnnf0_tag20140601t090105_0.420.849085635
channel ORA_AUX_DISK_1: piece handle=+DATA/cvrman/backupset/2014_06_01/ncnnf0_tag20140601t090105_0.420.849085635 tag=TAG20140601T090105
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:04
output file name=+DATA/cvdup/controlfile/control01.dbf
output file name=+DATA/cvdup/controlfile/control02.dbf
Finished restore at 01-JUN-14

database mounted
RMAN-05529: WARNING: DB_FILE_NAME_CONVERT resulted in invalid ASM names; names changed to disk group only.

contents of Memory Script:
{
   set until scn  1741111;
   sql clone 'alter database flashback off';
   set newname for datafile  1 to 
 "+data";
   set newname for datafile  2 to 
 "+data";
   set newname for datafile  3 to 
 "+data";
   set newname for datafile  4 to 
 "+data";
   set newname for datafile  5 to 
 "+DATA/cvdup/datafile/example_new.dbf";
   set newname for datafile  6 to 
 "+DATA/cvdup/datafile/tbs1_new.dbf";
   set newname for datafile  7 to 
 "+DATA/cvdup/datafile/tbs2_new.dbf";
   restore
   clone database
   ;
}
executing Memory Script

executing command: SET until clause

sql statement: alter database flashback off

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at 01-JUN-14
using channel ORA_AUX_DISK_1
using channel ORA_AUX_DISK_2

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 00002 to +data
channel ORA_AUX_DISK_1: restoring datafile 00003 to +data
channel ORA_AUX_DISK_1: restoring datafile 00007 to +DATA/cvdup/datafile/tbs2_new.dbf
channel ORA_AUX_DISK_1: reading from backup piece +DATA/cvrman/backupset/2014_06_01/nnndf0_tag20140601t090105_0.421.849085271
channel ORA_AUX_DISK_2: starting datafile backup set restore
channel ORA_AUX_DISK_2: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_2: restoring datafile 00001 to +data
channel ORA_AUX_DISK_2: restoring datafile 00004 to +data
channel ORA_AUX_DISK_2: restoring datafile 00005 to +DATA/cvdup/datafile/example_new.dbf
channel ORA_AUX_DISK_2: restoring datafile 00006 to +DATA/cvdup/datafile/tbs1_new.dbf
channel ORA_AUX_DISK_2: reading from backup piece +DATA/cvrman/backupset/2014_06_01/nnndf0_tag20140601t090105_0.415.849085271
channel ORA_AUX_DISK_1: piece handle=+DATA/cvrman/backupset/2014_06_01/nnndf0_tag20140601t090105_0.421.849085271 tag=TAG20140601T090105
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:04:37
channel ORA_AUX_DISK_2: piece handle=+DATA/cvrman/backupset/2014_06_01/nnndf0_tag20140601t090105_0.415.849085271 tag=TAG20140601T090105
channel ORA_AUX_DISK_2: restored backup piece 1
channel ORA_AUX_DISK_2: restore complete, elapsed time: 00:06:17
Finished restore at 01-JUN-14

contents of Memory Script:
{
   switch clone datafile all;
}
executing Memory Script

datafile 1 switched to datafile copy
input datafile copy RECID=110 STAMP=849089638 file name=+DATA/cvdup/datafile/system.490.849089261
datafile 2 switched to datafile copy
input datafile copy RECID=111 STAMP=849089638 file name=+DATA/cvdup/datafile/sysaux.489.849089261
datafile 3 switched to datafile copy
input datafile copy RECID=112 STAMP=849089638 file name=+DATA/cvdup/datafile/undotbs1.491.849089263
datafile 6 switched to datafile copy
input datafile copy RECID=113 STAMP=849089639 file name=+DATA/cvdup/datafile/tbs1_new.dbf
datafile 7 switched to datafile copy
input datafile copy RECID=114 STAMP=849089639 file name=+DATA/cvdup/datafile/tbs2_new.dbf

contents of Memory Script:
{
   set until scn  1741111;
   recover
   clone database
    delete archivelog
   ;
}
executing Memory Script

executing command: SET until clause

Starting recover at 01-JUN-14
using channel ORA_AUX_DISK_1
using channel ORA_AUX_DISK_2
datafile 4 not processed because file is read-only
datafile 5 not processed because file is read-only

starting media recovery

archived log for thread 1 with sequence 7 is already on disk as file +DATA/cvrman/archivelog/2014_06_01/thread_1_seq_7.485.849085687
archived log file name=+DATA/cvrman/archivelog/2014_06_01/thread_1_seq_7.485.849085687 thread=1 sequence=7
media recovery complete, elapsed time: 00:00:00
Finished recover at 01-JUN-14
Oracle instance started

Total System Global Area     217157632 bytes

Fixed Size                     2251816 bytes
Variable Size                159384536 bytes
Database Buffers              50331648 bytes
Redo Buffers                   5189632 bytes

contents of Memory Script:
{
   sql clone "alter system set  db_name = 
 ''CVDUP'' 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

sql statement: alter system set  db_name =  ''CVDUP'' 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     217157632 bytes

Fixed Size                     2251816 bytes
Variable Size                159384536 bytes
Database Buffers              50331648 bytes
Redo Buffers                   5189632 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "CVDUP" RESETLOGS ARCHIVELOG 
  MAXLOGFILES     16
  MAXLOGMEMBERS      3
  MAXDATAFILES      100
  MAXINSTANCES     8
  MAXLOGHISTORY      292
 LOGFILE
  GROUP   1 ( '+data', '+data' ) SIZE 50 M  REUSE,
  GROUP   2 ( '+data', '+data' ) SIZE 50 M  REUSE,
  GROUP   3 ( '+data', '+data' ) SIZE 50 M  REUSE
 DATAFILE
  '+DATA/cvdup/datafile/system.490.849089261'
 CHARACTER SET WE8MSWIN1252


contents of Memory Script:
{
   set newname for tempfile  1 to 
 "+data";
   switch clone tempfile all;
   catalog clone datafilecopy  "+DATA/cvdup/datafile/sysaux.489.849089261", 
 "+DATA/cvdup/datafile/undotbs1.491.849089263", 
 "+DATA/cvdup/datafile/tbs1_new.dbf", 
 "+DATA/cvdup/datafile/tbs2_new.dbf";
   switch clone datafile all;
}
executing Memory Script

executing command: SET NEWNAME

renamed tempfile 1 to +data in control file

cataloged datafile copy
datafile copy file name=+DATA/cvdup/datafile/sysaux.489.849089261 RECID=1 STAMP=849089692
cataloged datafile copy
datafile copy file name=+DATA/cvdup/datafile/undotbs1.491.849089263 RECID=2 STAMP=849089692
cataloged datafile copy
datafile copy file name=+DATA/cvdup/datafile/tbs1_new.dbf RECID=3 STAMP=849089692
cataloged datafile copy
datafile copy file name=+DATA/cvdup/datafile/tbs2_new.dbf RECID=4 STAMP=849089692

datafile 2 switched to datafile copy
input datafile copy RECID=1 STAMP=849089692 file name=+DATA/cvdup/datafile/sysaux.489.849089261
datafile 3 switched to datafile copy
input datafile copy RECID=2 STAMP=849089692 file name=+DATA/cvdup/datafile/undotbs1.491.849089263
datafile 6 switched to datafile copy
input datafile copy RECID=3 STAMP=849089692 file name=+DATA/cvdup/datafile/tbs1_new.dbf
datafile 7 switched to datafile copy
input datafile copy RECID=4 STAMP=849089692 file name=+DATA/cvdup/datafile/tbs2_new.dbf
Reenabling controlfile options for auxiliary database
Executing: alter database enable block change tracking using file '+DATA/cvdup/changetracking/ctf.279.847591985'
ORACLE error from auxiliary database: ORA-19751: could not create the change tracking file
ORA-19750: change tracking file: '+DATA/cvdup/changetracking/ctf.279.847591985'
ORA-17502: ksfdcre:4 Failed to create file +DATA/cvdup/changetracking/ctf.279.847591985
ORA-15046: ASM file name '+DATA/cvdup/changetracking/ctf.279.847591985' is not in single-file creation form

Ignoring error, reattempt command after duplicate finishes

contents of Memory Script:
{
   Alter clone database open resetlogs;
}
executing Memory Script

database opened

contents of Memory Script:
{
   catalog clone datafilecopy  "+DATA/cvdup/datafile/users.495.849089265", 
 "+DATA/cvdup/datafile/example_new.dbf";
   switch clone datafile  4 to datafilecopy 
 "+DATA/cvdup/datafile/users.495.849089265";
   switch clone datafile  5 to datafilecopy 
 "+DATA/cvdup/datafile/example_new.dbf";
   #online the readonly tablespace
   sql clone "alter tablespace  USERS online";
   #online the readonly tablespace
   sql clone "alter tablespace  EXAMPLE online";
}
executing Memory Script

cataloged datafile copy
datafile copy file name=+DATA/cvdup/datafile/users.495.849089265 RECID=5 STAMP=849089737
cataloged datafile copy
datafile copy file name=+DATA/cvdup/datafile/example_new.dbf RECID=6 STAMP=849089738

datafile 4 switched to datafile copy
input datafile copy RECID=5 STAMP=849089737 file name=+DATA/cvdup/datafile/users.495.849089265

datafile 5 switched to datafile copy
input datafile copy RECID=6 STAMP=849089738 file name=+DATA/cvdup/datafile/example_new.dbf

sql statement: alter tablespace  USERS online

sql statement: alter tablespace  EXAMPLE online
Finished Duplicate Db at 01-JUN-14

RMAN> 
RMAN> 


11.Check the status of auxiliary database
$ export ORACLE_SID=cvdup
$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Sun Jun 1 10:22:10 2014

Copyright (c) 1982, 2013, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options

SQL> select name,open_mode from v$database;

NAME      OPEN_MODE
--------- --------------------
CVDUP     READ WRITE

No comments: