【转】RMAN创建duplicate数据库

http://www.cnblogs.com/dba001/archive/2012/03/25/2416398.html 
通过rman duplicate创建一个文件目录结构与源库不同的数据库
 
rman duplicate与standby数据库的不同之处在于,后者是主库的一个备用库,也会被实施的更新,当主库发生故障以后,后者可以切换为主库并承担必要的工作;而前者的主要目的是创建出一个数据库用于做软件更新,维护测试等工作,不能够承担备用库的工作。两者的使用场景不同
使用rman duplicate创建数据库时,能够生成一个独特的DBID,该ID与源库不同。
创建duplicate数据库的主要步骤:
  1. 准备并创建辅助数据库(auxiliary)实例 本实验中,主库实例为source;备库实例为dp
  2. 配置两个服务器的口令文件和oracle net,测试能否互访
  3. 主库备份,并将备份文件拷贝到备库相同目录下
  4. 通过rman duplicate创建duplicate数据库
 
创建auxiliary数据库实例
登录到auxiliary数据库服务器,配置环境变量,创建pfile和passwordfile
 
[oracle@tam admin]$  /sbin /ifconfig eth1 
eth1 Link encap :Ethernet HWaddr  5C :F3 :FC : 49 : 6F :AE  
          inet addr : 172. 26. 29. 4 Bcast : 172. 26. 29. 255 Mask : 255. 255. 255. 0
          inet6 addr : fe80 : : 5ef3 :fcff :fe49 : 6fae / 64 Scope :Link
          UP BROADCAST RUNNING MULTICAST MTU : 1500 Metric : 1
          RX packets : 9681799 errors : 0 dropped : 0 overruns : 0 frame : 0
          TX packets : 4081907 errors : 0 dropped : 0 overruns : 0 carrier : 0
          collisions : 0 txqueuelen : 1000 
          RX bytes : 8935435736 ( 8. 3 GiB) TX bytes : 1880436288 ( 1. 7 GiB)
          Interrupt : 178 Memory : 94000000 - 94012800 
[oracle@tam admin]$ env |grep ORA 
ORACLE_SID =DP
ORACLE_BASE = /u01 /app
ORACLE_HOME = /u01 /app /oracle /product / 11. 2. 0 /db_1
[oracle@tam admin]$ cd $ORACLE_HOME /dbs 
[oracle@tam dbs]$ orapwd file =orapwDP password =sys entries = 5 ignorecase =
[oracle@tam dbs]$  ls
hc_DP.dat initDP.ora init.ora lkTDB1 orapwtdb1
hc_tdb1.dat initDP.ora.bak lkDP orapwDP spfiletdb1.ora
配置Oracle net,保证两台服务器能够相互访问
[oracle@tam dbs]$ cd  /u01 /app /oracle /product / 11. 2. 0 /db_1 /network /admin /
[oracle@tam admin]$  cat listener.ora  
# listener.ora Network Configuration File: /u01/app/oracle/product/10.2.0.5/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.

SID_LIST_LISTENER  =
  (SID_LIST  =
    (SID_DESC  =
      (SID_NAME  = PLSExtProc)
      (ORACLE_HOME  =  /u01 /app /oracle /product / 11. 2. 0 /db_1)
      (PROGRAM  = extproc)
    )

    (SID_DESC  =
      (SID_NAME  = DP)
      (ORACLE_HOME  =  /u01 /app /oracle /product / 11. 2. 0 /db_1)
      (GLOBAL_DBNAME  = dp)
    )
  )

LISTENER  =
  (DESCRIPTION_LIST  =
    (DESCRIPTION  =
      (ADDRESS  = (PROTOCOL  = TCP)(HOST  =  172. 26. 29. 4)(PORT  =  1521))
      (ADDRESS  = (PROTOCOL  = IPC)(KEY  = EXTPROC0))
    )
  )
[oracle@tam admin]$  cat tnsnames.ora
DP  = 
  (DESCRIPTION  =
    (ADDRESS  = (PROTOCOL  = TCP)(HOST  =  172. 26. 29. 4)(PORT  =  1521))
    (CONNECT_DATA  =
      (SERVER  = DEDICATED)
      (SERVICE_NAME  = DP)
    )
  )
SOURCE  =
  (DESCRIPTION  =
    (ADDRESS  = (PROTOCOL  = TCP)(HOST  =  172. 26. 29. 2)(PORT  =  1521))
    (CONNECT_DATA  =
      (SERVER  = DEDICATED)
      (SERVICE_NAME  = SOURCE)
    )
  )
常见备库的初始化参数文件pfile,根据参数文件创建必要的目录
[oracle@tam dbs]$  cat initDP.ora 
*.compatible = '11.2.0'
*.control_files = '/u01/data/dp/dp/control01.ctl', '/u01/data/dp/dp/control02.ctl'
*.core_dump_dest = '/u01/app/oracle/admin/dp/cdump'
*.db_block_size = 8192
*.db_name = 'DP'
*.db_recovery_file_dest = '/u01/app/oracle/flash_recovery_area'
*.db_recovery_file_dest_size = 53687091200
*.log_archive_format = '%t_%s_%r.arc'
*.log_archive_max_processes = 10
*.nls_date_format = 'YYYY-MM-DD hh24:mi:ss'
*.nls_language = 'SIMPLIFIED CHINESE'
*.nls_territory = 'CHINA'
*.open_cursors = 300
*.pga_aggregate_target = 1669332992
*.processes = 1000
*.remote_login_passwordfile = 'exclusive'
*.sessions = 1105
*.sga_target = 1610612736
*.standby_file_management = 'auto'
*.undo_management = 'AUTO'
*.undo_tablespace = 'UNDOTBS01'
启动备库监听和实例
[oracle@tam  ~]$ sqlplus  / as sysdba 

SQL *Plus : Release  11. 2. 0. 1. 0 Production on Sun Mar  25  10 : 15 : 35  2012

Copyright (c)  19822009, Oracle. All rights reserved.

Connected to an idle instance.

SYS@DP >startup nomount
ORACLE instance started.

Total System Global Area  1603411968 bytes
Fixed Size  2213776 bytes
Variable Size  402655344 bytes
Database Buffers  1191182336 bytes
Redo Buffers  7360512 bytes
SYS@DP > !lsnrctl status 

LSNRCTL  for Linux : Version  11. 2. 0. 1. 0  - Production on  25 -MAR - 2012  10 : 16 : 08

Copyright (c)  19912009, Oracle. All rights reserved.

Connecting to (DESCRIPTION =(ADDRESS =(PROTOCOL =TCP)(HOST = 172. 26. 29. 4)(PORT = 1521)))
STATUS of the LISTENER
-- -- -- -- -- -- -- -- -- -- -- --
Alias LISTENER
Version TNSLSNR  for Linux : Version  11. 2. 0. 1. 0  - Production
Start Date  15 -MAR - 2012  21 : 54 : 43
Uptime  9 days  12 hr.  21 min.  24 sec
Trace Level off
Security ON : Local OS Authentication
SNMP OFF
Listener Parameter File  /u01 /app /oracle /product / 11. 2. 0 /db_1 /network /admin /listener.ora
Listener Log File  /u01 /app /diag /tnslsnr /tam /listener /alert /log.xml
Listening Endpoints Summary...
  (DESCRIPTION =(ADDRESS =(PROTOCOL =tcp)(HOST = 172. 26. 29. 4)(PORT = 1521)))
  (DESCRIPTION =(ADDRESS =(PROTOCOL =ipc)(KEY =EXTPROC0)))
Services Summary...
Service  "PLSExtProc" has  1 instance(s).
  Instance  "PLSExtProc", status UNKNOWN, has  1 handler(s)  for this service...
Service  "dp" has  2 instance(s).
  Instance  "DP", status UNKNOWN, has  1 handler(s)  for this service...
  Instance  "DP", status BLOCKED, has  1 handler(s)  for this service...
The command completed successfully
 
主库完全备份
登录到主库服务器,完全备份数据库
[oracle@localhost  ~]$ rman target  / 
RMAN > run { 
2 > allocate channel c1 type disk;
3 > allocate channel c2 type disk;
4 > backup database format  '/u01/data/bak/DB-bak-20120325-%U';
5 > backup archivelog all delete all input format  '/u01/data/bak/ARC_%U';
6 > }

using target database control file instead of recovery catalog
allocated channel : c1
channel c1 : SID = 580 device type =DISK

allocated channel : c2
channel c2 : SID = 961 device type =DISK

Starting backup at  25 -MAR - 12
channel c1 : starting full datafile backup set
channel c1 : specifying datafile(s)  in backup set
input datafile file number = 00001 name = /u01 /data /source /system01.dbf
input datafile file number = 00003 name = /u01 /data /source /undotbs01.dbf
channel c1 : starting piece  1 at  25 -MAR - 12
channel c2 : starting full datafile backup set
channel c2 : specifying datafile(s)  in backup set
input datafile file number = 00002 name = /u01 /data /source /sysaux01.dbf
channel c2 : starting piece  1 at  25 -MAR - 12
channel c1 : finished piece  1 at  25 -MAR - 12
piece handle = /u01 /data /bak /DB -bak - 20120325 - 07n6og8u_1_1 tag =TAG20120325T101454 comment =NONE
channel c1 : backup set complete, elapsed time : 00 :00 : 16
channel c2 : finished piece  1 at  25 -MAR - 12
piece handle = /u01 /data /bak /DB -bak - 20120325 - 08n6og8u_1_1 tag =TAG20120325T101454 comment =NONE
channel c2 : backup set complete, elapsed time : 00 :00 : 15
Finished backup at  25 -MAR - 12

Starting backup at  25 -MAR - 12
current log archived
channel c1 : starting archived log backup set
channel c1 : specifying archived log(s)  in backup set
input archived log thread = 1 sequence = 16 RECID = 16 STAMP = 778846511
channel c1 : starting piece  1 at  25 -MAR - 12
channel c1 : finished piece  1 at  25 -MAR - 12
piece handle = /u01 /data /bak /ARC_09n6og9g_1_1 tag =TAG20120325T101511 comment =NONE
channel c1 : backup set complete, elapsed time : 00 :00 : 01
channel c1 : deleting archived log(s)
archived log file name = /u01 /app /oracle /flash_recovery_area /SOURCE /archivelog / 2012_03_25 /o1_mf_1_16_7pwzxhds_.arc RECID = 16STAMP = 778846511
Finished backup at  25 -MAR - 12

Starting Control File Autobackup at  25 -MAR - 12
piece handle = /u01 /data /bak /ctl_c - 2896366647 - 20120325 -00 comment =NONE
Finished Control File Autobackup at  25 -MAR - 12
released channel : c1
released channel : c2
主库创建口令文件,配置Oracle Net并测试与备库的互通性
[oracle@localhost  ~]$ cd  /u01 /app /oracle /product / 11. 2. 0 /db_1 /network /admin /
[oracle@localhost admin]$  cat listener.ora  
# listener.ora Network Configuration File: /u01/app/oracle/product/10.2.0.5/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.

SID_LIST_LISTENER  =
  (SID_LIST  =
    (SID_DESC  =
      (SID_NAME  = PLSExtProc)
      (ORACLE_HOME  =  /u01 /app /oracle /product / 11. 2. 0 /db_1)
      (PROGRAM  = extproc)
    )

    (SID_DESC  =
      (SID_NAME  = SOURCE)
      (ORACLE_HOME  =  /u01 /app /oracle /product / 11. 2. 0 /db_1)
      (GLOBAL_DBNAME  = source)
    )
  )

LISTENER  =
  (DESCRIPTION_LIST  =
    (DESCRIPTION  =
      (ADDRESS  = (PROTOCOL  = TCP)(HOST  =  172. 26. 29. 2)(PORT  =  1521))
      (ADDRESS  = (PROTOCOL  = IPC)(KEY  = EXTPROC0))
    )
  )

[oracle@localhost admin]$  cat tnsnames.ora  
names.ora Network Configuration File :  /u01 /app /oracle /product / 11. 2. 0 /db_1 /network /admin /tnsnames.ora
# Generated by Oracle configuration tools.
DP  = 
  (DESCRIPTION  =
    (ADDRESS  = (PROTOCOL  = TCP)(HOST  =  172. 26. 29. 4)(PORT  =  1521))
    (CONNECT_DATA  =
      (SERVER  = DEDICATED)
      (SERVICE_NAME  = DP)
    ) 
SOURCE  =
  (DESCRIPTION  =
    (ADDRESS  = (PROTOCOL  = TCP)(HOST  =  172. 26. 29. 2)(PORT  =  1521))
    (CONNECT_DATA  =
      (SERVER  = DEDICATED)
      (SERVICE_NAME  = SOURCE)
    ) 
EXTPROC_CONNECTION_DATA  = 
  (DESCRIPTION  =
    (ADDRESS_LIST  =
      (ADDRESS  = (PROTOCOL  = IPC)(KEY  = EXTPROC0))
    )
    (CONNECT_DATA  =
      (SID  = PLSExtProc)
      (PRESENTATION  = RO)
    )
  )
[oracle@localhost admin]$ lsnrctl status 

LSNRCTL  for Linux : Version  11. 2. 0. 1. 0  - Production on  25 -MAR - 2012  10 : 21 : 55

Copyright (c)  19912009, Oracle. All rights reserved.

Connecting to (DESCRIPTION =(ADDRESS =(PROTOCOL =TCP)(HOST = 172. 26. 29. 2)(PORT = 1521)))
STATUS of the LISTENER
-- -- -- -- -- -- -- -- -- -- -- --
Alias LISTENER
Version TNSLSNR  for Linux : Version  11. 2. 0. 1. 0  - Production
Start Date  15 -MAR - 2012  21 : 47 : 05
Uptime  9 days  12 hr.  34 min.  49 sec
Trace Level off
Security ON : Local OS Authentication
SNMP OFF
Listener Parameter File  /u01 /app /oracle /product / 11. 2. 0 /db_1 /network /admin /listener.ora
Listener Log File  /u01 /app /diag /tnslsnr /localhost /listener /alert /log.xml
Listening Endpoints Summary...
  (DESCRIPTION =(ADDRESS =(PROTOCOL =tcp)(HOST = 172. 26. 29. 2)(PORT = 1521)))
  (DESCRIPTION =(ADDRESS =(PROTOCOL =ipc)(KEY =EXTPROC0)))
Services Summary...
Service  "PLSExtProc" has  1 instance(s).
  Instance  "PLSExtProc", status UNKNOWN, has  1 handler(s)  for this service...
Service  "source" has  1 instance(s).
  Instance  "SOURCE", status UNKNOWN, has  1 handler(s)  for this service...
The command completed successfully
创建口令文件
[oracle@localhost admin]$ cd  /u01 /app /oracle /product / 11. 2. 0 /db_1 /dbs /
[oracle@localhost dbs]$ orapwd file =orapwSOURCE password =sys entries = 5 ignorecase =y      
[oracle@localhost dbs]$  ls
hc_PRIMARY.dat hc_tdb1.dat initSOURCE.ora lkPRIMARY lkTDB1 orapwSOURCE snapcf_SOURCE.f
hc_SOURCE.dat init.ora lkPRAMARY lkSOURCE lkTEST orapwtdb1 spfiletdb1.ora
两台服务器互相测试Oracle Net的互通性
主库
[oracle@localhost admin]$ sqlplus sys /sys@dp as sysdba 

SQL *Plus : Release  11. 2. 0. 1. 0 Production on Sun Mar  25  10 : 30 : 38  2012

Copyright (c)  19822009, Oracle. All rights reserved.


Connected to :
Oracle Database  11g Enterprise Edition Release  11. 2. 0. 1. 0  -  64bit Production
With the Partitioning, OLAP, Data Mining  and Real Application Testing options

SYS@dp >
备库
[oracle@tam  ~]$ sqlplus sys /sys@source as sysdba 

SQL *Plus : Release  11. 2. 0. 1. 0 Production on Sun Mar  25  10 : 22 : 50  2012

Copyright (c)  19822009, Oracle. All rights reserved.


Connected to :
Oracle Database  11g Enterprise Edition Release  11. 2. 0. 1. 0  -  64bit Production
With the Partitioning, OLAP, Data Mining  and Real Application Testing options

SYS@source >
在远程备库创建duplicate数据库
将主库的备份文件拷贝到备库
[oracle@localhost admin]$ cd  /u01 /data /bak / 
[oracle@localhost bak]$  ls
ARC_09n6og9g_1_1 DB -bak - 20120325 - 07n6og8u_1_1
ctl_c - 2896366647 - 20120325 -00 DB -bak - 20120325 - 08n6og8u_1_1
[oracle@localhost bak]$ scp  *  172. 26. 29. 4 : /u01 /data /bak
oracle@ 172. 26. 29. 4 's password: 
ARC_09n6og9g_1_1 100% 10MB 10.2MB/s 00:00    
ctl_c-2896366647-20120325-00 100% 8192KB 8.0MB/s 00:00    
DB-bak-20120325-07n6og8u_1_1 100% 177MB 44.1MB/s 00:04    
DB-bak-20120325-08n6og8u_1_1 100% 181MB 36.2MB/s 00:05  
 
duplicate数据库
[oracle@localhost bak]$ rman target sys /sys@source auxiliary sys /sys@dp
RMAN > run { 
2 > set newname  for datafile  1 to  '/u01/data/dp/system01.dbf';
3 > set newname  for datafile  2 to  '/u01/data/dp/sysaux01.dbf';
4 > set newname  for datafile  3 to  '/u01/data/dp/undotbs01.dbf';
5 > set newname  for tempfile  3 to  '/u01/data/dp/temp.dbf';
6 > duplicate target database to dp nofilenamecheck;
7 > }

....................

database opened 
Finished Duplicate Db at  25 -MAR - 12

RMAN >
至此 完成duplicate数据库操作
可以在备库中试验一下
[oracle@tam bak]$ sqlplus  / as sysdba 

SQL *Plus : Release  11. 2. 0. 1. 0 Production on Sun Mar  25  10 : 42 : 33  2012

Copyright (c)  19822009, Oracle. All rights reserved.


Connected to :
Oracle Database  11g Enterprise Edition Release  11. 2. 0. 1. 0  -  64bit Production
With the Partitioning, OLAP, Data Mining  and Real Application Testing options

SYS@DP >select instance_name from v$instance;

INSTANCE_NAME
-- -- -- -- -- -- -- --
DP

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

转载于:http://blog.itpub.net/21861353/viewspace-754743/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值