duplicate database

 工作很久了,也一直都没有操作过duplicate database,因为平常的备份恢复,用rman普通方式就可以搞定了,但这个duplicate database是必须了解的,所以现在实验一下,以免以后用到。
带着疑问:duplicate database有什么过人之处,导致我们非要使用它,到底和普通的备份恢复有啥区别?
       据说是用catalog的话,必须使用duplicate,如果用ctl的话,那基本和普通的备份恢复没啥区别,所以这应该也是我这么多年都没有太了解duplicate的原因吧,因为我一直都使用ctl,没有使用catalog,虽然说备份软件里的内置数据库就类似于我们的catalog,但操作上还是有一定区别的。他最大的特点可能就是可以生产新的dbid吧。

定义和原理:
 我理解所谓duplicate database这个命令,其实就是一堆命令的封装,当我们执行这个命令时,可以自动的完成很多工作。对于原理,还不是很清楚,所以还是需要通过实验来了解原理。过了1h,实验完毕。现在来简单记录一下原理:duplicate database可以修改dbid,所以我们要是异机恢复的话,不需要记录dbid,在原数据库mount状态下就可以执行duplicate database,之所以必须要求原数据库在mount下是因为duplicate database要使用原数据库的控制文件里的备份信息。所以我们使用duplicate database,更严格的说是可以复制数据库。

 实验:
 原库:192.168.160.2 hostname:dongdong.com,已有数据库和实例,状态为open。
 duplicate database:192.168.160.128 hostname:maomao.com,已安装数据库软件,没有实例。
 备注:原库和目标库的所有路径都一样。
1. 原库备份
RMAN> backup database plus archivelog;-----需要将归档也备份。
[oracle@baobao ~]$ scp -r 2013_12_01/ 192.168.160.128:/u01/app/oracle/flash_recovery_area/DONG/backupset/
[oracle@maomao 2013_12_01]$ pwd
/u01/app/oracle/flash_recovery_area/DONG/backupset/2013_12_01
[oracle@maomao 2013_12_01]$ ll
总用量 1281504
-rw-r-----. 1 oracle oinstall   12736512 12月  1 13:19 o1_mf_annnn_TAG20131201T131320_99okcjxn_.bkp
-rw-r-----. 1 oracle oinstall       3584 12月  1 13:16 o1_mf_annnn_TAG20131201T131450_99okgc5k_.bkp
-rw-r-----. 1 oracle oinstall   10158080 12月  1 13:16 o1_mf_ncsnf_TAG20131201T131322_99okg99z_.bkp
-rw-r-----. 1 oracle oinstall 1289355264 12月  1 13:18 o1_mf_nnndf_TAG20131201T131322_99okclrp_.bkp
2 duplicate数据库创建pfile,并启动实例
[oracle@maomao dbs]$ export ORACLE_SID=mm
[oracle@maomao dbs]$ cat initmm.ora
*.control_files='/u01/app/oracle/oradata/dong/control01.ctl'#Restore Controlfile
*.db_name='mm'
[oracle@maomao dbs]$ sqlplus / as sysdba
SQL> startup nomount
ORACLE instance started.
Total System Global Area  150667264 bytes
Fixed Size                  1335080 bytes
Variable Size              92274904 bytes
Database Buffers           50331648 bytes
Redo Buffers                6725632 bytes
3 配置tns监听,让两边都可以互相连接
4 配置duplicate database的口令文件
5 连接,执行duplicate database命令
[oracle@baobao backupset]$ rman target / auxiliary sys/oracle@mm

Recovery Manager: Release 11.2.0.1.0 - Production on Sun Dec 1 13:24:47 2013

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

connected to target database: DONG (DBID=2075447482)
connected to auxiliary database: MM (not mounted)

RMAN> duplicate target database to mm nofilenamecheck;(备注:这里使用nofilenamecheck是因为oracle以为你要将恢复到当前机器,会覆盖dbf。其实我们是恢复到auxiliary库上,但oracle目前还没有这么聪明,所以我们就需要写啦)

Starting Duplicate Db at 01-DEC-13
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=10 device type=DISK

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

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

Oracle instance shut down

Oracle instance started

Total System Global Area     150667264 bytes

Fixed Size                     1335080 bytes
Variable Size                 92274904 bytes
Database Buffers              50331648 bytes
Redo Buffers                   6725632 bytes

Starting restore at 01-DEC-13
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=95 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/flash_recovery_area/DONG/backupset/2013_12_01/o1_mf_ncsnf_TAG20131201T131322_99okg99z_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/flash_recovery_area/DONG/backupset/2013_12_01/o1_mf_ncsnf_TAG20131201T131322_99okg99z_.bkp tag=TAG20131201T131322
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/dong/control01.ctl
Finished restore at 01-DEC-13

database mounted
Using previous duplicated file /u01/app/oracle/oradata/dong/system01.dbf for datafile 1 with checkpoint SCN of 1411720
Using previous duplicated file /u01/app/oracle/oradata/dong/sysaux01.dbf for datafile 2 with checkpoint SCN of 1411720
Using previous duplicated file /u01/app/oracle/oradata/dong/undotbs01.dbf for datafile 3 with checkpoint SCN of 1411720
Using previous duplicated file /u01/app/oracle/oradata/dong/users01.dbf for datafile 4 with checkpoint SCN of 1411720

contents of Memory Script:
{
   catalog clone datafilecopy  "/u01/app/oracle/oradata/dong/system01.dbf",
 "/u01/app/oracle/oradata/dong/sysaux01.dbf",
 "/u01/app/oracle/oradata/dong/undotbs01.dbf",
 "/u01/app/oracle/oradata/dong/users01.dbf";
   switch clone datafile  1 to datafilecopy
 "/u01/app/oracle/oradata/dong/system01.dbf";
   switch clone datafile  2 to datafilecopy
 "/u01/app/oracle/oradata/dong/sysaux01.dbf";
   switch clone datafile  3 to datafilecopy
 "/u01/app/oracle/oradata/dong/undotbs01.dbf";
   switch clone datafile  4 to datafilecopy
 "/u01/app/oracle/oradata/dong/users01.dbf";
}
executing Memory Script

cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/dong/system01.dbf RECID=1 STAMP=833030747
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/dong/sysaux01.dbf RECID=2 STAMP=833030747
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/dong/undotbs01.dbf RECID=3 STAMP=833030747
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/dong/users01.dbf RECID=4 STAMP=833030747

datafile 1 switched to datafile copy
input datafile copy RECID=1 STAMP=833030747 file name=/u01/app/oracle/oradata/dong/system01.dbf

datafile 2 switched to datafile copy
input datafile copy RECID=2 STAMP=833030747 file name=/u01/app/oracle/oradata/dong/sysaux01.dbf

datafile 3 switched to datafile copy
input datafile copy RECID=3 STAMP=833030747 file name=/u01/app/oracle/oradata/dong/undotbs01.dbf

datafile 4 switched to datafile copy
input datafile copy RECID=4 STAMP=833030747 file name=/u01/app/oracle/oradata/dong/users01.dbf

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

executing command: SET until clause

Starting recover at 01-DEC-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=3
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/DONG/backupset/2013_12_01/o1_mf_annnn_TAG20131201T131320_99okcjxn_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/flash_recovery_area/DONG/backupset/2013_12_01/o1_mf_annnn_TAG20131201T131320_99okcjxn_.bkp tag=TAG20131201T131320
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/product/11.2.0/dbhome_1/dbs/arch1_3_832784280.dbf thread=1 sequence=3
channel clone_default: deleting archived log(s)
archived log file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_3_832784280.dbf RECID=4 STAMP=833030748
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=4
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/DONG/backupset/2013_12_01/o1_mf_annnn_TAG20131201T131450_99okgc5k_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/flash_recovery_area/DONG/backupset/2013_12_01/o1_mf_annnn_TAG20131201T131450_99okgc5k_.bkp tag=TAG20131201T131450
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/product/11.2.0/dbhome_1/dbs/arch1_4_832784280.dbf thread=1 sequence=4
channel clone_default: deleting archived log(s)
archived log file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_4_832784280.dbf RECID=5 STAMP=833030751
media recovery complete, elapsed time: 00:00:01
Finished recover at 01-DEC-13

contents of Memory Script:
{
   shutdown clone immediate;
   startup clone nomount;
   sql clone "alter system set  db_name =
 ''MM'' 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     150667264 bytes

Fixed Size                     1335080 bytes
Variable Size                 92274904 bytes
Database Buffers              50331648 bytes
Redo Buffers                   6725632 bytes

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

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


contents of Memory Script:
{
   catalog clone datafilecopy  "/u01/app/oracle/oradata/dong/sysaux01.dbf",
 "/u01/app/oracle/oradata/dong/undotbs01.dbf",
 "/u01/app/oracle/oradata/dong/users01.dbf";
   switch clone datafile all;
   switch clone datafile  2 to datafilecopy
 "/u01/app/oracle/oradata/dong/sysaux01.dbf";
   switch clone datafile  3 to datafilecopy
 "/u01/app/oracle/oradata/dong/undotbs01.dbf";
   switch clone datafile  4 to datafilecopy
 "/u01/app/oracle/oradata/dong/users01.dbf";
}
executing Memory Script

cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/dong/sysaux01.dbf RECID=1 STAMP=833030769
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/dong/undotbs01.dbf RECID=2 STAMP=833030769
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/dong/users01.dbf RECID=3 STAMP=833030769


datafile 2 switched to datafile copy
input datafile copy RECID=1 STAMP=833030769 file name=/u01/app/oracle/oradata/dong/sysaux01.dbf

datafile 3 switched to datafile copy
input datafile copy RECID=2 STAMP=833030769 file name=/u01/app/oracle/oradata/dong/undotbs01.dbf

datafile 4 switched to datafile copy
input datafile copy RECID=3 STAMP=833030769 file name=/u01/app/oracle/oradata/dong/users01.dbf

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

database opened
Finished Duplicate Db at 01-DEC-13
[oracle@maomao ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Sun Dec 1 13:34:03 2013

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


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> select status from v$instance;

STATUS
------------
OPEN

SQL> show parameter name

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_file_name_convert                 string
db_name                              string      MM
db_unique_name                       string      MM
global_names                         boolean     FALSE
instance_name                        string      mm
lock_name_space                      string
log_file_name_convert                string
service_names                        string      MM

如果dbf和control的路径和原库不一样的话,那就set newname设置一下即可。


 

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

转载于:http://blog.itpub.net/24500180/viewspace-1061781/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Table: PE_Address Schema dbo Descriptions 地址表 Fields PK Name Data type Not null Unique Row GUID Collation Default Description AddressID int 地址ID UserName nvarchar(20) Chinese_PRC_CI_AS 用户名 ConsigneeName nvarchar(255) Chinese_PRC_CI_AS 收货人姓名 HomePhone nvarchar(50) Chinese_PRC_CI_AS 固定电话 Mobile nvarchar(30) Chinese_PRC_CI_AS 移动电话 Country nvarchar(50) Chinese_PRC_CI_AS 国家 Province nvarchar(30) Chinese_PRC_CI_AS 省份 City nvarchar(30) Chinese_PRC_CI_AS 城市 Area nvarchar(30) Chinese_PRC_CI_AS 地区 Address nvarchar(255) Chinese_PRC_CI_AS 详细地址 ZipCode nvarchar(50) Chinese_PRC_CI_AS 邮政编码 IsDefault bit 0 是否默认 Foreign Keys There are no foreign keys for table PE_Address Checks There are no check constraints for table PE_Address Indices Name Type Fields File Group Fill Factor Clustered Don't Recompute Statistics Ignore Duplicate Keys Pad Index Allow Row Locks Allow Page Locks Description IX_PE_Address_UserName Index UserName PRIMARY 0 PK_PE_Address_AddressID Primary Key AddressID PRIMARY 0 Triggers There are no triggers for table PE_Address Definition CREATE TABLE [dbo].[PE_Address] ( [AddressID] int NOT NULL, [UserName] nvarchar(20) COLLATE Chinese_PRC_CI_AS NULL, [ConsigneeName] nvarchar(255) COLLATE Chinese_PRC_CI_AS NULL, [HomePhone] nvarchar(50) COLLATE Chinese_PRC_CI_AS NULL, [Mobile] nvarchar(30) COLLATE Chinese_PRC_CI_AS NULL, [Country] nvarchar(50) COLLATE Chinese_PRC_CI_AS NULL, [Province] nvarchar(30) COLLATE Chinese_PRC_CI_AS NULL, [City] nvarchar(30) COLLATE Chinese_PRC_CI_AS NULL, [Area] nvarchar(30) COLLATE Chinese_PRC_CI_AS NULL, [Address] nvarchar(255) COLLATE Chinese_PRC_CI_AS NULL, [ZipCode] nvarchar(50) COLLATE Chinese_PRC_CI_AS NULL, [IsDefault] bit CONSTRAINT [DF_PE_Address_IsDefalult] DEFAULT 0 NULL, CONSTRAINT [PK_PE_Address_AddressID] PRIMARY KEY NONCLUSTERED ([AddressID]) ) ON [PRIMARY] GO EXEC sp_addextendedproperty 'MS_Description', N'地址表', 'schema', 'dbo', 'table', 'PE_Address' GO EXEC sp_addextendedproperty 'MS_Description', N'地址ID', 'schema', 'dbo', 'table', 'PE_Address', 'column', 'AddressID' GO EXEC sp_addextendedproperty 'MS_Description', N'用户名', 'schema', 'dbo', 'table', 'PE_Address', 'column', 'UserName' GO EXEC sp_addextendedproperty 'MS_Description', N'收货人姓名', 'schema', 'dbo', 'table', 'PE_Address', 'column', 'ConsigneeName' GO EXEC sp_addextendedproperty 'MS_Description', N'固定电话', 'schema', 'dbo', 'table', 'PE_Address', 'column', 'HomePhone' GO EXEC sp_addextendedproperty 'MS_Description', N'移动电话', 'schema', 'dbo', 'table', 'PE_Address', 'column', 'Mobile' GO EXEC sp_addextendedproperty 'MS_Description', N'国家', 'schema', 'dbo', 'table', 'PE_Address', 'column', 'Country' GO EXEC sp_addextendedproperty 'MS_Description', N'省份', 'schema', 'dbo', 'table', 'PE_Address', 'column', 'Province' GO EXEC sp_addextendedproperty 'MS_Description', N'城市', 'schema', 'dbo', 'table', 'PE_Address', 'column', 'City' GO EXEC sp_addextendedproperty 'MS_Description', N'地区', 'schema', 'dbo', 'table', 'PE_Address', 'column', 'Area' GO EXEC sp_addextendedproperty 'MS_Description', N'详细地址', 'schema', 'dbo', 'table', 'PE_Address', 'column', 'Address' GO EXEC sp_addextendedproperty 'MS_Description', N'邮政编码', 'schema', 'dbo', 'table', 'PE_Address', 'column', 'ZipCode' GO EXEC sp_addextendedproperty 'MS_Description', N'是否默认', 'schema', 'dbo', 'table', 'PE_Address', 'column', 'IsDefault' GO CREATE CLUSTERED INDEX [IX_PE_Address_UserName] ON [dbo].[PE_Address] ([UserName]) WITH ( PAD_INDEX = OFF, DROP_EXISTING = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] GO

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值