【轉】RMAN建立duplicate資料庫

chaobaojun發表於2013-02-26
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/,如需轉載,請註明出處,否則將追究法律責任。

相關文章