ITPub博客

首页 > 数据库 > Oracle > RMAN duplicate必须指定DBID的场景

RMAN duplicate必须指定DBID的场景

原创 Oracle 作者:oliseh 时间:2015-07-07 20:32:31 0 删除 编辑
RMAN duplicate 在dbname相同但dbid不同的情况下需要指定dbid,下面来模拟一下这个场景:


###先记录当前数据库的信息并生成全库备份
SYS@tstdb1-SQL> select dbid,name from v$database;


      DBID NAME
---------- ---------
2030654775 TSTDB1


run
{
allocate channel d1 device type disk;
allocate channel d2 device type disk;
backup database include current controlfile format '/oradata06/dupuse/dbid/2030654775_%u';
}


alter system switch logfile;
alter system switch logfile;
alter system switch logfile;
alter system switch logfile;


SYS@tstdb1-SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     3
Next log sequence to archive   5
Current log sequence           5


backup archivelog sequence between 1 and 4 format '/oradata06/dupuse/dbid/2030654775_arch_%u';


backup spfile format '/oradata06/dupuse/dbid/2030654775_spfile_%u';


###修改dbid
shutdown immediate
startup mount;


tstdb1@jq570322b:/home/tstdb1>nid target=SYS


DBNEWID: Release 11.2.0.3.0 - Production on Tue Jul 7 15:37:57 2015


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


Password: 
Connected to database TSTDB1 (DBID=2030654775)


Connected to server version 11.2.0


Control Files in database:
    /oradata06/testaaaaa/control01.ctl
    /oradata06/testaaaaa/control02.ctl


Change database ID of database TSTDB1? (Y/[N]) => Y


Proceeding with operation
Changing database ID from 2030654775 to 2051793563
    Control File /oradata06/testaaaaa/control01.ctl - modified
    Control File /oradata06/testaaaaa/control02.ctl - modified
    Datafile /oradata06/testaaaaa/system01.db - dbid changed
    Datafile /oradata06/testaaaaa/sysaux01.db - dbid changed
    Datafile /oradata06/testaaaaa/undotbs01.db - dbid changed
    Datafile /oradata06/testaaaaa/users01.db - dbid changed
    Datafile /oradata06/testaaaaa/ts0422_1.db - dbid changed
    Datafile /oradata06/testaaaaa/xdbts1.db - dbid changed
    Datafile /oradata06/testaaaaa/ts0212.db - dbid changed
    Datafile /oradata06/testaaaaa/ts0212_1.db - dbid changed
    Datafile /oradata06/testaaaaa/undotbs3.db - dbid changed
    Datafile /oradata06/testaaaaa/temp01.db - dbid changed
    Control File /oradata06/testaaaaa/control01.ctl - dbid changed
    Control File /oradata06/testaaaaa/control02.ctl - dbid changed
    Instance shut down


Database ID for database TSTDB1 changed to 2051793563.
All previous backups and archived redo logs for this database are unusable.
Database is not aware of previous backups and archived logs in Recovery Area.
Database has been shutdown, open database with RESETLOGS option.
Succesfully changed database ID.
DBNEWID - Completed succesfully.


###修改dbid后重新启动数据库
sqlplus '/as sysdba'
startup;
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open


alter database open resetlogs;


SQL> select dbid,name from v$database;


      DBID NAME
---------- ---------
2051793563 TSTDB1


##重新注册到rman catalog
rman target / catalog rman/773946@tstdb2
register database;


##以TSTDB1为dbname的数据库有两个dbid=2030654775、dbid=2051793563
RMAN> list incarnation of database tstdb1;


List of Database Incarnations
DB Key  Inc Key DB Name  DB ID            STATUS  Reset SCN  Reset Time
------- ------- -------- ---------------- --- ---------- ----------
91139   91164   TSTDB1   2030654775       PARENT  12723361876275 20150501 22:23:18
91139   91165   TSTDB1   2030654775       PARENT  12723361982201 20150502 17:26:40
91139   91166   TSTDB1   2030654775       ORPHAN  12723361982602 20150502 16:51:47
91139   91167   TSTDB1   2030654775       PARENT  12723361984663 20150621 08:02:54
91139   91168   TSTDB1   2030654775       ORPHAN  12723362036923 20150621 13:35:30
91139   91169   TSTDB1   2030654775       PARENT  12723362039102 20150621 16:03:46
91139   91170   TSTDB1   2030654775       PARENT  12723362040689 20150621 16:08:49
91139   91171   TSTDB1   2030654775       PARENT  12723362054987 20150622 19:55:12
91139   91172   TSTDB1   2030654775       PARENT  12723362144134 20150623 10:23:34
91139   91173   TSTDB1   2030654775       PARENT  12723362147001 20150623 10:40:47
91139   91174   TSTDB1   2030654775       PARENT  12723362149501 20150623 10:57:09
91139   91175   TSTDB1   2030654775       PARENT  12723362559613 20150625 09:36:10
91139   91140   TSTDB1   2030654775       PARENT  12723362562754 20150625 10:44:56
91139   92114   TSTDB1   2030654775       ORPHAN  12723363819873 20150705 05:41:37
91139   92839   TSTDB1   2030654775       PARENT  12723363828514 20150705 20:47:27
91139   93574   TSTDB1   2030654775       PARENT  12723363925695 20150706 15:53:03
91139   94928   TSTDB1   2030654775       PARENT  12723363946794 20150706 16:52:31
91139   96192   TSTDB1   2030654775       ORPHAN  12723363961836 20150706 20:47:37
91139   96787   TSTDB1   2030654775       ORPHAN  12723363961836 20150707 06:07:12
91139   98834   TSTDB1   2030654775       PARENT  12723363961836 20150707 10:17:24
91139   97635   TSTDB1   2030654775       ORPHAN  12723363961836 20150707 08:47:25
91139   97143   TSTDB1   2030654775       ORPHAN  12723363961948 20150707 06:23:30
91139   99343   TSTDB1   2030654775       CURRENT 12723363962276 20150707 15:25:41
99781   99804   TSTDB1   2051793563       PARENT  12723363962276 20150707 15:25:41     
99781   99782   TSTDB1   2051793563       CURRENT 12723363963918 20150707 15:41:56   


###对于dbid=2051793563的tstdb1进行db backup
backup database include current controlfile format '/oradata06/dupuse/dbid/2051793563_%u' spfile format '/oradata06/dupuse/dbid/2051793563_spfile_%u';


alter system switch logfile;
alter system switch logfile;
alter system switch logfile;
alter system switch logfile;


SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     3
Next log sequence to archive   5
Current log sequence           5


backup archivelog sequence between 1 and 4 format '/oradata06/dupuse/dbid/2051793563_arch_%u';


###将/oradata06/dupuse/dbid目录下的内容复制到149.110(dup db) 同名目录下
。。。步骤略
附/oradata06/dupuse/dbid下的文件列表
total 12884144
-rw-r-----    1 oracle   oinstall 1353113600 Jul 07 15:29 2030654775_80qbf4tr
-rw-r-----    1 oracle   oinstall 1928019968 Jul 07 15:29 2030654775_7vqbf4tr
-rw-r-----    1 oracle   oinstall   14352384 Jul 07 15:29 2030654775_81qbf4uu
-rw-r-----    1 oracle   oinstall      98304 Jul 07 15:29 2030654775_82qbf4v3
-rw-r-----    1 oracle   oinstall     657408 Jul 07 15:32 2030654775_arch_83qbf53p
-rw-r-----    1 oracle   oinstall      98304 Jul 07 15:34 2030654775_spfile_85qbf57r
-rw-r-----    1 oracle   oinstall 3283673088 Jul 07 15:49 2051793563_86qbf61v
-rw-r-----    1 oracle   oinstall   14385152 Jul 07 15:49 2051793563_87qbf63d
-rw-r-----    1 oracle   oinstall      98304 Jul 07 15:49 2051793563_spfile_88qbf63f
-rw-r-----    1 oracle   oinstall    2155008 Jul 07 15:53 2051793563_arch_89qbf6b7


//////////////////////////
//场景1:不连接target & catalog,指定backup location duplicate到dup db
//////////////////////////
--149.110(dup db)操作
rm $ORACLE_HOME/dbs/spfiledupdb3.ora
rm $ORACLE_HOME/dbs/initdupdb3.ora
export ORACLE_SID=dupdb3
export ORA_RMAN_SGA_TARGET=500
sqlplus '/as sysdba'
shutdown abort


rman target /
startup nomount


--149.208(执行duplicate的RMAN client主机)操作
rman auxiliary sys/asdf3_14@dupdb3
duplicate database tstdb1 to dupdb3 until time '20150707 15:52:16' db_file_name_convert='/oradata06/testaaaaa/','/oradata06/testccccc/' backup location '/oradata06/dupuse/dbid/' spfile set control_files '/oradata06/testccccc/control01.ctl','/oradata06/testccccc/control02.ctl' set log_file_name_convert '/oradata06/testaaaaa/','/oradata06/testccccc/';
。。。。
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 /oradata06/testccccc/system01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00002 to /oradata06/testccccc/sysaux01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /oradata06/testccccc/undotbs01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /oradata06/testccccc/users01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00005 to /oradata06/testccccc/ts0422_1.dbf
channel ORA_AUX_DISK_1: restoring datafile 00006 to /oradata06/testccccc/xdbts1.dbf
channel ORA_AUX_DISK_1: restoring datafile 00007 to /oradata06/testccccc/ts0212.dbf
channel ORA_AUX_DISK_1: restoring datafile 00008 to /oradata06/testccccc/ts0212_1.dbf
channel ORA_AUX_DISK_1: restoring datafile 00010 to /oradata06/testccccc/undotbs3.dbf
channel ORA_AUX_DISK_1: reading from backup piece /oradata06/dupuse/dbid/2051793563_86qbf61v
channel ORA_AUX_DISK_1: piece handle=/oradata06/dupuse/dbid/2051793563_86qbf61v tag=TAG20150707T154814   <---来自于新的dbid:2051793563
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:45
Finished restore at 20150707 16:28:47
。。。


duplicate database tstdb1 to dupdb3 until time '20150707 15:35:50' db_file_name_convert='/oradata06/testaaaaa/','/oradata06/testccccc/' backup location '/oradata06/dupuse/dbid/' spfile set control_files '/oradata06/testccccc/control01.ctl','/oradata06/testccccc/control02.ctl' set log_file_name_convert '/oradata06/testaaaaa/','/oradata06/testccccc/';
。。。。
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 /oradata06/testccccc/system01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00002 to /oradata06/testccccc/sysaux01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /oradata06/testccccc/undotbs01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /oradata06/testccccc/users01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00005 to /oradata06/testccccc/ts0422_1.dbf
channel ORA_AUX_DISK_1: restoring datafile 00006 to /oradata06/testccccc/xdbts1.dbf
channel ORA_AUX_DISK_1: restoring datafile 00007 to /oradata06/testccccc/ts0212.dbf
channel ORA_AUX_DISK_1: restoring datafile 00008 to /oradata06/testccccc/ts0212_1.dbf
channel ORA_AUX_DISK_1: restoring datafile 00010 to /oradata06/testccccc/undotbs3.dbf
channel ORA_AUX_DISK_1: reading from backup piece /oradata06/dupuse/dbid/2030654775_7vqbf4tr
channel ORA_AUX_DISK_1: piece handle=/oradata06/dupuse/dbid/2030654775_7vqbf4tr tag=TAG20150707T152857   <---来自于老的dbid:2030654775
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:55
Finished restore at 20150707 16:32:42
。。。


可以看出以backup location指定的备份文件作为duplicate源头的情况下,通过until time指定不同的时间能够不用dbid也能筛选出target db,经过测试即使两个db的备份时间有重叠RMAN会自动选择其中一个,不会报错


//////////////////////////
//场景2:仅连接catalog,执行duplicate
//////////////////////////
--149.110(dup db)操作
rm $ORACLE_HOME/dbs/spfiledupdb3.ora
rm $ORACLE_HOME/dbs/initdupdb3.ora
export ORACLE_SID=dupdb3
export ORA_RMAN_SGA_TARGET=500
sqlplus '/as sysdba'
shutdown abort


rman target /
startup nomount


--149.208(执行duplicate的RMAN client主机)操作
rman catalog rman/773946@tstdb2 auxiliary sys/asdf3_14@dupdb3
duplicate database tstdb1 to dupdb3 until sequence 3 db_file_name_convert='/oradata06/testaaaaa/','/oradata06/testccccc/' backup location '/oradata06/dupuse/dbid/' spfile set control_files '/oradata06/testccccc/control01.ctl','/oradata06/testccccc/control02.ctl' set log_file_name_convert '/oradata06/testaaaaa/','/oradata06/testccccc/';


Starting Duplicate Db at 20150707 16:39:08
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of Duplicate Db command at 07/07/2015 16:39:08
RMAN-05501: aborting duplication of target database
RMAN-12010: automatic channel allocation initialization failed
RMAN-06004: ORACLE error from recovery catalog database: RMAN-20005: target database name is ambiguous


***指定dbid
duplicate database tstdb1 dbid 2051793563 to dupdb3 until sequence 3 db_file_name_convert='/oradata06/testaaaaa/','/oradata06/testccccc/' backup location '/oradata06/dupuse/dbid/' spfile set control_files '/oradata06/testccccc/control01.ctl','/oradata06/testccccc/control02.ctl' set log_file_name_convert '/oradata06/testaaaaa/','/oradata06/testccccc/';
。。。
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 /oradata06/testccccc/system01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00002 to /oradata06/testccccc/sysaux01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /oradata06/testccccc/undotbs01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /oradata06/testccccc/users01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00005 to /oradata06/testccccc/ts0422_1.dbf
channel ORA_AUX_DISK_1: restoring datafile 00006 to /oradata06/testccccc/xdbts1.dbf
channel ORA_AUX_DISK_1: restoring datafile 00007 to /oradata06/testccccc/ts0212.dbf
channel ORA_AUX_DISK_1: restoring datafile 00008 to /oradata06/testccccc/ts0212_1.dbf
channel ORA_AUX_DISK_1: restoring datafile 00010 to /oradata06/testccccc/undotbs3.dbf
channel ORA_AUX_DISK_1: reading from backup piece /oradata06/dupuse/dbid/2051793563_86qbf61v
channel ORA_AUX_DISK_1: piece handle=/oradata06/dupuse/dbid/2051793563_86qbf61v tag=TAG20150707T154814
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:45
Finished restore at 20150707 16:41:14
。。。


***不指定dbid,使用看似能区分出db的until time,依然报错
duplicate database tstdb1 to dupdb3 until time '20150707 15:31:00' db_file_name_convert='/oradata06/testaaaaa/','/oradata06/testccccc/' backup location '/oradata06/dupuse/dbid/' spfile set control_files '/oradata06/testccccc/control01.ctl','/oradata06/testccccc/control02.ctl' set log_file_name_convert '/oradata06/testaaaaa/','/oradata06/testccccc/';
RMAN> duplicate database tstdb1 to dupdb3 until time '20150707 15:31:00' db_file_name_convert='/oradata06/testaaaaa/','/oradata06/testccccc/' backup location '/oradata06/dupuse/dbid/' spfile set control_files '/oradata06/testccccc/control01.ctl','/oradata06/testccccc/control02.ctl' set log_file_name_convert '/oradata06/testaaaaa/','/oradata06/testccccc/';


Starting Duplicate Db at 20150707 16:43:20
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of Duplicate Db command at 07/07/2015 16:43:20
RMAN-05501: aborting duplication of target database
RMAN-12010: automatic channel allocation initialization failed
RMAN-06004: ORACLE error from recovery catalog database: RMAN-20005: target database name is ambiguous


在connect catalog only的情况下如遇两个dbname相同,必须使用dbid加以区别

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/53956/viewspace-1725981/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
不仅仅专注Oracle database技术, member of SHOUG

注册时间:2014-04-06

  • 博文量
    128
  • 访问量
    1616689