码迷,mamicode.com
首页 > 数据库 > 详细

在相同的主机上创建一个duplicate数据库

时间:2015-06-25 17:06:14      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:

在相同的主机上创建一个duplicate数据库

source db:dbtest

auxiliary db:dupdb

 

duplicate database会自动分配一个新的DBID
要确保auxiliary channel能访问到所需的备份以及归档日志

 

1.备份source db

$ rman target /
RMAN> backup database format =/home/oracle/arch/dbbak_%U plus archivelog;

2.修改监听文件,静态注册监听

SID_LIST_LISTENER =
    (SID_LIST =
        (SID_DESC =
            (GLOBAL_DBNAME = testdb)
            (ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1/)
        (SID_NAME =testdb)
        )
        (SID_DESC =
            (GLOBAL_DBNAME = dupdb)
            (ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1/)
            (SID_NAME =dupdb)
        )
    )

3.修改tnsnames.ora文件

DBTEST =
    (DESCRIPTION =
        (ADDRESS_LIST =
            (ADDRESS = (PROTOCOL = TCP)(HOST = testdb)(PORT = 1521))
        )
            (CONNECT_DATA =
                (SERVER = DEDICATED)
                (SERVICE_NAME = dbtest)
            )
        )
        
DUPDB =
    (DESCRIPTION =
        (ADDRESS_LIST =
            (ADDRESS = (PROTOCOL = TCP)(HOST = testdb)(PORT = 1521))
        )
        (CONNECT_DATA =
            (SERVER = DEDICATED)
            (SERVICE_NAME = dupdb)
        )
    )

4.为duplicate 数据库创建参数文件initdupdb.ora

db_name=dupdb
db_block_size=8192
compatible=11.2.0.4.0
remote_login_passwordfile=exclusive
control_files=(/u01/app/oracle/oradata/dupdb/control01.ctl,/u01/app/oracle/oradata/dupdb/control02.ctl)
db_file_name_convert=(/u01/app/oracle/oradata/dbtest,/u01/app/oracle/oradata/dupdb)
log_file_name_covert=(/u01/app/oracle/oradata/dbtest,/u01/app/oracle/oradata/dupdb)

#其他参数是可选的

5.启动auxiliary database(duplicate database)

$ export ORACLE_SID=dupdb
$ sqlplus /nolog
SQL> connect /as sysdba
SQL> startup nomount pfile=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/initdupdb.ora
ORACLE instance started.

Total System Global Area  317370368 bytes
Fixed Size                  2252784 bytes
Variable Size             260046864 bytes
Database Buffers           50331648 bytes
Redo Buffers                4739072 bytes
SQL> 

6.启动rman

$ export ORACLE_SID=dupdb
$ rman 

Recovery Manager: Release 11.2.0.4.0 - Production on Thu Jun 25 07:52:09 2015

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

RMAN> connect target sys/system1@dbtest

connected to target database: DBTEST (DBID=1275290034)

RMAN> connect auxiliary /

connected to auxiliary database: DUPDB (not mounted)

RMAN> 

7.启动duplicate database操作

RMAN> duplicate target database to dupdb;

以下为duplicate命令的执行结果:

RMAN> duplicate target database to dupdb;

Starting Duplicate Db at 25-JUN-2015 08:18:24
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=396 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     321548288 bytes

Fixed Size                     2252824 bytes
Variable Size                264245224 bytes
Database Buffers              50331648 bytes
Redo Buffers                   4718592 bytes

contents of Memory Script:
{
   sql clone "alter system set  db_name = 
 ‘‘DBTEST‘‘ comment=
 ‘‘Modified by RMAN duplicate‘‘ scope=spfile";
   sql clone "alter system set  db_unique_name = 
 ‘‘DUPDB‘‘ 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 =  ‘‘DBTEST‘‘ comment= ‘‘Modified by RMAN duplicate‘‘ scope=spfile

sql statement: alter system set  db_unique_name =  ‘‘DUPDB‘‘ comment= ‘‘Modified by RMAN duplicate‘‘ scope=spfile

Oracle instance shut down

Oracle instance started

Total System Global Area     321548288 bytes

Fixed Size                     2252824 bytes
Variable Size                264245224 bytes
Database Buffers              50331648 bytes
Redo Buffers                   4718592 bytes

Starting restore at 25-JUN-2015 08:18:40
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=396 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 /u01/app/oracle/fast_recovery_area/DBTEST/autobackup/2015_06_25/o1_mf_s_883287663_brp8zhvt_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/DBTEST/autobackup/2015_06_25/o1_mf_s_883287663_brp8zhvt_.bkp tag=TAG20150625T054103
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/u01/app/oracle/oradata/dupdb/control01.ctl
output file name=/u01/app/oracle/oradata/dupdb/control02.ctl
Finished restore at 25-JUN-2015 08:18:41

database mounted

contents of Memory Script:
{
   set until scn  1553917;
   sql clone alter database flashback off;
   set newname for datafile  1 to 
 "/u01/app/oracle/oradata/dupdb/system01.dbf";
   set newname for datafile  2 to 
 "/u01/app/oracle/oradata/dupdb/sysaux01.dbf";
   set newname for datafile  3 to 
 "/u01/app/oracle/oradata/dupdb/undotbs01.dbf";
   set newname for datafile  4 to 
 "/u01/app/oracle/oradata/dupdb/users01.dbf";
   set newname for datafile  5 to 
 "/u01/app/oracle/oradata/dupdb/example01.dbf";
   set newname for datafile  6 to 
 "/u01/app/oracle/oradata/dupdb/nnc_data01.dbf";
   set newname for datafile  7 to 
 "/u01/app/oracle/oradata/dupdb/nnc_data02.dbf";
   set newname for datafile  8 to 
 "/u01/app/oracle/oradata/dupdb/nnc_data03.dbf";
   set newname for datafile  9 to 
 "/u01/app/oracle/oradata/dupdb/nnc_index01.dbf";
   set newname for datafile  10 to 
 "/u01/app/oracle/oradata/dupdb/nnc_index02.dbf";
   set newname for datafile  11 to 
 "/u01/app/oracle/oradata/dupdb/nnc_index03.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

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at 25-JUN-2015 08:18:46
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/dupdb/system01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/dupdb/sysaux01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/dupdb/undotbs01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/dupdb/users01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/dupdb/example01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/dupdb/nnc_data01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00007 to /u01/app/oracle/oradata/dupdb/nnc_data02.dbf
channel ORA_AUX_DISK_1: restoring datafile 00008 to /u01/app/oracle/oradata/dupdb/nnc_data03.dbf
channel ORA_AUX_DISK_1: restoring datafile 00009 to /u01/app/oracle/oradata/dupdb/nnc_index01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00010 to /u01/app/oracle/oradata/dupdb/nnc_index02.dbf
channel ORA_AUX_DISK_1: restoring datafile 00011 to /u01/app/oracle/oradata/dupdb/nnc_index03.dbf
channel ORA_AUX_DISK_1: reading from backup piece /home/oracle/arch/dbbak_0tqabpiv_1_1
channel ORA_AUX_DISK_1: piece handle=/home/oracle/arch/dbbak_0tqabpiv_1_1 tag=TAG20150625T054047
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:25
Finished restore at 25-JUN-2015 08:19:11

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

datafile 1 switched to datafile copy
input datafile copy RECID=13 STAMP=883297151 file name=/u01/app/oracle/oradata/dupdb/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=14 STAMP=883297151 file name=/u01/app/oracle/oradata/dupdb/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=15 STAMP=883297151 file name=/u01/app/oracle/oradata/dupdb/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=16 STAMP=883297151 file name=/u01/app/oracle/oradata/dupdb/users01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=17 STAMP=883297151 file name=/u01/app/oracle/oradata/dupdb/example01.dbf
datafile 6 switched to datafile copy
input datafile copy RECID=18 STAMP=883297151 file name=/u01/app/oracle/oradata/dupdb/nnc_data01.dbf
datafile 7 switched to datafile copy
input datafile copy RECID=19 STAMP=883297151 file name=/u01/app/oracle/oradata/dupdb/nnc_data02.dbf
datafile 8 switched to datafile copy
input datafile copy RECID=20 STAMP=883297151 file name=/u01/app/oracle/oradata/dupdb/nnc_data03.dbf
datafile 9 switched to datafile copy
input datafile copy RECID=21 STAMP=883297151 file name=/u01/app/oracle/oradata/dupdb/nnc_index01.dbf
datafile 10 switched to datafile copy
input datafile copy RECID=22 STAMP=883297151 file name=/u01/app/oracle/oradata/dupdb/nnc_index02.dbf
datafile 11 switched to datafile copy
input datafile copy RECID=23 STAMP=883297151 file name=/u01/app/oracle/oradata/dupdb/nnc_index03.dbf

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

executing command: SET until clause

Starting recover at 25-JUN-2015 08:19:11
using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 10 is already on disk as file /home/oracle/arch/1_10_883118265.dbf
archived log for thread 1 with sequence 11 is already on disk as file /home/oracle/arch/1_11_883118265.dbf
archived log file name=/home/oracle/arch/1_10_883118265.dbf thread=1 sequence=10
archived log file name=/home/oracle/arch/1_11_883118265.dbf thread=1 sequence=11
media recovery complete, elapsed time: 00:00:01
Finished recover at 25-JUN-2015 08:19:13
Oracle instance started

Total System Global Area     321548288 bytes

Fixed Size                     2252824 bytes
Variable Size                264245224 bytes
Database Buffers              50331648 bytes
Redo Buffers                   4718592 bytes

contents of Memory Script:
{
   sql clone "alter system set  db_name = 
 ‘‘DUPDB‘‘ 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 =  ‘‘DUPDB‘‘ 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     321548288 bytes

Fixed Size                     2252824 bytes
Variable Size                264245224 bytes
Database Buffers              50331648 bytes
Redo Buffers                   4718592 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "DUPDB" RESETLOGS ARCHIVELOG 
  MAXLOGFILES     16
  MAXLOGMEMBERS      3
  MAXDATAFILES      100
  MAXINSTANCES     8
  MAXLOGHISTORY      292
 LOGFILE
  GROUP   1 ( /u01/app/oracle/oradata/dupdb/redo01.log ) SIZE 50 M  REUSE,
  GROUP   2 ( /u01/app/oracle/oradata/dupdb/redo02.log ) SIZE 50 M  REUSE,
  GROUP   3 ( /u01/app/oracle/oradata/dupdb/redo03.log ) SIZE 50 M  REUSE
 DATAFILE
  /u01/app/oracle/oradata/dupdb/system01.dbf
 CHARACTER SET ZHS16GBK


contents of Memory Script:
{
   set newname for tempfile  1 to 
 "/u01/app/oracle/oradata/dupdb/temp01.dbf";
   switch clone tempfile all;
   catalog clone datafilecopy  "/u01/app/oracle/oradata/dupdb/sysaux01.dbf", 
 "/u01/app/oracle/oradata/dupdb/undotbs01.dbf", 
 "/u01/app/oracle/oradata/dupdb/users01.dbf", 
 "/u01/app/oracle/oradata/dupdb/example01.dbf", 
 "/u01/app/oracle/oradata/dupdb/nnc_data01.dbf", 
 "/u01/app/oracle/oradata/dupdb/nnc_data02.dbf", 
 "/u01/app/oracle/oradata/dupdb/nnc_data03.dbf", 
 "/u01/app/oracle/oradata/dupdb/nnc_index01.dbf", 
 "/u01/app/oracle/oradata/dupdb/nnc_index02.dbf", 
 "/u01/app/oracle/oradata/dupdb/nnc_index03.dbf";
   switch clone datafile all;
}
executing Memory Script

executing command: SET NEWNAME

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

cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/dupdb/sysaux01.dbf RECID=1 STAMP=883297164
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/dupdb/undotbs01.dbf RECID=2 STAMP=883297164
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/dupdb/users01.dbf RECID=3 STAMP=883297164
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/dupdb/example01.dbf RECID=4 STAMP=883297164
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/dupdb/nnc_data01.dbf RECID=5 STAMP=883297164
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/dupdb/nnc_data02.dbf RECID=6 STAMP=883297164
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/dupdb/nnc_data03.dbf RECID=7 STAMP=883297164
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/dupdb/nnc_index01.dbf RECID=8 STAMP=883297164
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/dupdb/nnc_index02.dbf RECID=9 STAMP=883297164
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/dupdb/nnc_index03.dbf RECID=10 STAMP=883297164

datafile 2 switched to datafile copy
input datafile copy RECID=1 STAMP=883297164 file name=/u01/app/oracle/oradata/dupdb/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=2 STAMP=883297164 file name=/u01/app/oracle/oradata/dupdb/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=3 STAMP=883297164 file name=/u01/app/oracle/oradata/dupdb/users01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=4 STAMP=883297164 file name=/u01/app/oracle/oradata/dupdb/example01.dbf
datafile 6 switched to datafile copy
input datafile copy RECID=5 STAMP=883297164 file name=/u01/app/oracle/oradata/dupdb/nnc_data01.dbf
datafile 7 switched to datafile copy
input datafile copy RECID=6 STAMP=883297164 file name=/u01/app/oracle/oradata/dupdb/nnc_data02.dbf
datafile 8 switched to datafile copy
input datafile copy RECID=7 STAMP=883297164 file name=/u01/app/oracle/oradata/dupdb/nnc_data03.dbf
datafile 9 switched to datafile copy
input datafile copy RECID=8 STAMP=883297164 file name=/u01/app/oracle/oradata/dupdb/nnc_index01.dbf
datafile 10 switched to datafile copy
input datafile copy RECID=9 STAMP=883297164 file name=/u01/app/oracle/oradata/dupdb/nnc_index02.dbf
datafile 11 switched to datafile copy
input datafile copy RECID=10 STAMP=883297164 file name=/u01/app/oracle/oradata/dupdb/nnc_index03.dbf

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

database opened
Finished Duplicate Db at 25-JUN-2015 08:19:28

RMAN> 

 

在相同的主机上创建一个duplicate数据库

标签:

原文地址:http://www.cnblogs.com/abclife/p/4600299.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!