Wednesday 27 August 2014

Duplicate Database Using RMAN Backup Without Connecting To Target Database

Take full backup on Source:
RUN
{
  ALLOCATE CHANNEL ch11 TYPE DISK MAXPIECESIZE 10G;
  BACKUP
  FORMAT '/u01/app/oracle/backup/%d_D_%T_%u_s%s_p%p'
  DATABASE
  PLUS ARCHIVELOG
  FORMAT '/u01/app/oracle/backup/%d_A_%T_%u_s%s_p%p';
  RELEASE CHANNEL ch11;
}
using target database control file instead of recovery catalog
allocated channel: ch11
channel ch11: SID=1 device type=DISK

Starting backup at 15-JUL-14
current log archived
channel ch11: starting archived log backup set
channel ch11: specifying archived log(s) in backup set
input archived log thread=1 sequence=17 RECID=1 STAMP=981547239
channel ch11: starting piece 1 at 15-JUL-14
channel ch11: finished piece 1 at 15-JUL-14
piece handle=/u01/app/oracle/backup/PRODDB_A_20180715_1ht82e78_s49_p1 tag=TAG20180715T120040 comment=NONE
channel ch11: backup set complete, elapsed time: 00:00:01
Finished backup at 15-JUL-14

Starting backup at 15-JUL-14
channel ch11: starting full datafile backup set
channel ch11: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/app/oracle/proddb/system01.dbf
input datafile file number=00002 name=/u01/app/oracle/proddb/sysaux01.dbf
input datafile file number=00003 name=/u01/app/oracle/proddb/undotbs01.dbf
channel ch11: starting piece 1 at 15-JUL-14
channel ch11: finished piece 1 at 15-JUL-14
piece handle=/u01/app/oracle/backup/PRODDB_D_20180715_1it82e79_s50_p1 tag=TAG20180715T120041 comment=NONE
channel ch11: backup set complete, elapsed time: 00:00:07
Finished backup at 15-JUL-14

Starting backup at 15-JUL-14
current log archived
channel ch11: starting archived log backup set
channel ch11: specifying archived log(s) in backup set
input archived log thread=1 sequence=18 RECID=2 STAMP=981547248
channel ch11: starting piece 1 at 15-JUL-14
channel ch11: finished piece 1 at 15-JUL-14
piece handle=/u01/app/oracle/backup/PRODDB_A_20180715_1jt82e7h_s51_p1 tag=TAG20180715T120048 comment=NONE
channel ch11: backup set complete, elapsed time: 00:00:01
Finished backup at 15-JUL-14

Starting Control File Autobackup at 15-JUL-14
piece handle=/u01/app/oracle/flash_recovery_area/PRODDB/autobackup/2018_07_15/o1_mf_n_981547250_fnotjtfy_.bkp comment=NONE
Finished Control File Autobackup at 15-JUL-14

released channel: ch11


Take controlfile backup if it's not auto backedup:
SQL> alter database backup controlfile to '/u01/app/oracle/backup/ctl.bkp';

Database altered.

Copy backups to target side:

Target side create parameter file and start db in nomount:
[oracle@jcraju dbs]$ cat inittestdb.ora
db_name='testdb'
memory_target=300M
audit_file_dest='/u01/app/oracle/adump'
audit_trail='db'
db_block_size=8192
db_recovery_file_dest='/u01/app/oracle/flash_recovery_area'
db_recovery_file_dest_size=2G
diagnostic_dest='/u01/app/oracle'
dispatchers='(PROTOCOL=TCP) (SERVICE=ORCLXDB)'
open_cursors=300
undo_tablespace='UNDOTBS1'
db_file_name_convert=/u01/app/oracle/proddb,/u01/app/oracle/testdb
log_file_name_convert=/u01/app/oracle/proddb,/u01/app/oracle/testdb
control_files=/u01/app/oracle/testdb/control1.ctl, /u01/app/oracle/testdb/control2.ctl


SQL> startup nomount;
ORACLE instance started.

Total System Global Area  314572800 bytes
Fixed Size            8620224 bytes
Variable Size             234882880 bytes
Database Buffers     67108864 bytes
Redo Buffers                3960832 bytes


Duplicate database using auxiliary:
[oracle@jcraju dbs]$ rman auxiliary /

Recovery Manager: Release 12.2.0.1.0 - Production on Sun Jul 15 03:06:30 2014

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

connected to auxiliary database: TESTDB (not mounted)

RMAN> duplicate database to testdb backup location '/u01/app/oracle/backup';

Starting Duplicate Db at 15-JUL-14

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     314572800 bytes

Fixed Size                     8620224 bytes
Variable Size                234882880 bytes
Database Buffers              67108864 bytes
Redo Buffers                   3960832 bytes

contents of Memory Script:
{
   sql clone "alter system set  db_name =
 ''PRODDB'' 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/oracle/backup/ctl.bkp';
   alter clone database mount;
}
executing Memory Script

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

Fixed Size                     8620224 bytes
Variable Size                234882880 bytes
Database Buffers              67108864 bytes
Redo Buffers                   3960832 bytes

Starting restore at 15-JUL-14
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=35 device type=DISK

channel ORA_AUX_DISK_1: copied control file copy
output file name=/u01/app/oracle/testdb/control1.ctl
output file name=/u01/app/oracle/testdb/control2.ctl
Finished restore at 15-JUL-14

database mounted
released channel: ORA_AUX_DISK_1
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=35 device type=DISK

contents of Memory Script:
{
   set until scn  751063;
   set newname for datafile  1 to
 "/u01/app/oracle/testdb/system01.dbf";
   set newname for datafile  2 to
 "/u01/app/oracle/testdb/sysaux01.dbf";
   set newname for datafile  3 to
 "/u01/app/oracle/testdb/undotbs01.dbf";
   restore
   clone database
   ;
}
executing Memory Script

executing command: SET until clause

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at 15-JUL-14
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/testdb/system01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00002 to /u01/app/oracle/testdb/sysaux01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /u01/app/oracle/testdb/undotbs01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/backup/PRODDB_D_20180715_1it82e79_s50_p1
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/backup/PRODDB_D_20180715_1it82e79_s50_p1 tag=TAG20180715T120041
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:15
Finished restore at 15-JUL-14

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

datafile 1 switched to datafile copy
input datafile copy RECID=5 STAMP=981515423 file name=/u01/app/oracle/testdb/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=6 STAMP=981515423 file name=/u01/app/oracle/testdb/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=7 STAMP=981515423 file name=/u01/app/oracle/testdb/undotbs01.dbf

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

executing command: SET until clause

Starting recover at 15-JUL-14
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=18
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/backup/PRODDB_A_20180715_1jt82e7h_s51_p1
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/backup/PRODDB_A_20180715_1jt82e7h_s51_p1 tag=TAG20180715T120048
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/2018_07_15/o1_mf_1_18_fnowv0jq_.arc thread=1 sequence=18
channel clone_default: deleting archived log(s)
archived log file name=/u01/app/oracle/flash_recovery_area/TESTDB/archivelog/2018_07_15/o1_mf_1_18_fnowv0jq_.arc RECID=1 STAMP=981515424
media recovery complete, elapsed time: 00:00:00
Finished recover at 15-JUL-14
Oracle instance started

Total System Global Area     314572800 bytes

Fixed Size                     8620224 bytes
Variable Size                234882880 bytes
Database Buffers              67108864 bytes
Redo Buffers                   3960832 bytes

contents of Memory Script:
{
   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";
}
executing Memory Script

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 started

Total System Global Area     314572800 bytes

Fixed Size                     8620224 bytes
Variable Size                234882880 bytes
Database Buffers              67108864 bytes
Redo Buffers                   3960832 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "TESTDB" RESETLOGS ARCHIVELOG
  MAXLOGFILES     16
  MAXLOGMEMBERS      2
  MAXDATAFILES       30
  MAXINSTANCES     1
  MAXLOGHISTORY      292
 LOGFILE
  GROUP   1 ( '/u01/app/oracle/testdb/redo01.log' ) SIZE 100 M  REUSE,
  GROUP   2 ( '/u01/app/oracle/testdb/redo02.log' ) SIZE 100 M  REUSE,
  GROUP   3 ( '/u01/app/oracle/testdb/redo03.log' ) SIZE 100 M  REUSE
 DATAFILE
  '/u01/app/oracle/testdb/system01.dbf'
 CHARACTER SET US7ASCII


contents of Memory Script:
{
   set newname for tempfile  1 to
 "/u01/app/oracle/testdb/temp01.dbf";
   switch clone tempfile all;
   catalog clone datafilecopy  "/u01/app/oracle/testdb/sysaux01.dbf",
 "/u01/app/oracle/testdb/undotbs01.dbf";
   switch clone datafile all;
}
executing Memory Script

executing command: SET NEWNAME

renamed tempfile 1 to /u01/app/oracle/testdb/temp01.dbf in control file

cataloged datafile copy
datafile copy file name=/u01/app/oracle/testdb/sysaux01.dbf RECID=1 STAMP=981515444
cataloged datafile copy
datafile copy file name=/u01/app/oracle/testdb/undotbs01.dbf RECID=2 STAMP=981515444

datafile 2 switched to datafile copy
input datafile copy RECID=1 STAMP=981515444 file name=/u01/app/oracle/testdb/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=2 STAMP=981515444 file name=/u01/app/oracle/testdb/undotbs01.dbf

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

database opened
Cannot remove created server parameter file
Finished Duplicate Db at 15-JUL-14

RMAN> exit


Duplicate database command will open db with resetlogs,
check db status:
Sql>select database_role,open_mode,name from gv$database;
DATABASE_ROLE     OPEN_MODE        NAME
---------------- ----------------  ---------
PRIMARY           READ WRITE        TESTDB

No comments:

Post a Comment