2014/01/15

Published 1月 15, 2014 by

Duplicate database

流程:
一、Backup Source DB and Copy file to Duplicate DB
二、Source DB備份spfilepfile
三、設定Duplicate DB password
四、設定Duplicate DB TNS
五、修改pfile檔案內容及路徑,並建立路徑
六、Duplicate DB(From Disk & Tape+RC)




DB:Oracle 10.2.0.4
Source DB:testdb(來源端,要被Duplicate DB)
Target DB:orcl2(Duplicate 出來的DB)
OS:Redhat 5.4

*****************(同台電腦使用RMAN,不同SID)
Source DB:
一、備份資料(因此測試是在同一台,所以資料兩台都可以看得到)
#export ORACLE_SID=testdb
# rman target /
rman>
run {
backup database;
sql 'alter system  archive log current';
backup archivelog all;
}
二、備份spfilepfile
SQL> create pfile='/home/oracle/initorcl2.ora' from spfile;  --使用source databaseparameter file產生基本的auxiliary parameter file
把產生的pfile放到target db,當然備份檔案也要copy過去給Duplicate Server(若是同一台就沒有差異)

三、設定Duplicate DB Password
Target DB:
建立duplicate database(orcl2)password file,假設orcl2instance name(同一台機器上不能有相同名字的instance出現,dbname也是如此)
[oracle@oracleDB ~]$ orapwd file=$ORACLE_HOME/dbs/orapw$ORACLE_SID password=oracle entries=10 ignorecase=y
Ps:ignorecase=y是在11g才有的參數,忽略大小寫

四、設定Duplicate DB TNS
建立net service name(testdb2),可以連到auxiliary instance
  --如果要使用@orcl2連到auxiliary instance,則記得必須對listener進行static registration
TESTDB2 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.55.79.26)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl2)
    )
  )
[oracle@oracleDB ~]$ tnsping testdb2

五、修改pfile檔案內容及路徑,並確認所有的路徑都存在
**修改initorcl2.ora將其變成正確的auxiliary instanceparameter file
#vi /home/oracle/initorcl2.ora
orcl2.__db_cache_size=415236096
orcl2.__java_pool_size=4194304
orcl2.__large_pool_size=4194304
orcl2.__shared_pool_size=150994944
orcl2.__streams_pool_size=0
*.audit_file_dest='/u1/oracle/admin/orcl2/adump'
*.background_dump_dest='/u1/oracle/admin/orcl2/bdump'
*.compatible='10.2.0.3.0'
*.control_files='/u2/oradata/orcl2/control01.ctl','/u2/oradata/orcl2/control02.ctl','/u2/oradata/orcl2/control03.ctl'#Restore Controlfile
*.core_dump_dest='/u1/oracle/admin/orcl2/cdump'
*.db_block_size=8192
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_name='orcl2' <--duplicated database位在同一台機器上,則必須與target database不同名字
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orcl2XDB)'
*.job_queue_processes=10
*.log_archive_dest_1='LOCATION=/archive/orcl2'
#*.log_archive_start=TRUE <-這一行需註解掉,否則會出現ORA-32006: LOG_ARCHIVE_START initialization parameter has been deprecated
*.open_cursors=300
*.pga_aggregate_target=418381824
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=581959680
*.undo_management='AUTO'
*.undo_tablespace='UNDOTBS1'
*.user_dump_dest='/u1/oracle/admin/orcl2/udump'
*.db_file_name_convert='/u2/oradata/testdb','/u2/oradata/orcl2'    <----重要
*.log_file_name_convert='/u2/oradata/testdb','/u2/oradata/orcl2'   <----重要


--duplicated database所在機器上進行
--建立相關的目錄(根據pfile來建立File)
[oracle@C5TDB2 ~]$ mkdir -p /u1/oracle/admin/orcl2/adump
[oracle@C5TDB2 ~]$ mkdir -p /u1/oracle/admin/orcl2/bdump
[oracle@C5TDB2 ~]$ mkdir -p /u1/oracle/admin/orcl2/cdump
[oracle@C5TDB2 ~]$ mkdir -p /u1/oracle/admin/orcl2/udump
[oracle@C5TDB2 ~]$ mkdir -p /u2/oracle/orcl2
[oracle@C5TDB2 ~]$ mkdir -p /archive/orcl2
[oracle@C5TDB2 ~]$ mkdir /u2/oradata/orcl2

六、Duplicate DB (From Disk & Tape)
1.startup aux instance nomount
[oracle@oracleDB ~]$ export ORACLE_SID=orcl2
[oracle@oracleDB ~]$ sqlplus / as sysdba
Connected to an idle instance.

SQL> startup nomount pfile=/home/oracle/initorcl2.ora    --必須事先將修改完成的initorcl2.ora傳遞到duplicated database所在的主機上

2.auxilary instance進行duplicate database
[oracle@oracleDB ~]$ export ORACLE_SID=orcl2
[oracle@oracleDB ~]$ rman target sys/oracle@testdb2 auxiliary /  --@orcl連線到target database
connected to target database: ORCL (DBID=1257464825)
connected to auxiliary database: ORCL2 (not mounted)
RMAN> run {
allocate auxiliary channel aux1 device type disk;
duplicate target database to orcl2;}  --orcl2必須與parameter filedb_name相同
**其餘工作將由RMAN自動產生的memory script完成所有操作

*******************補充資料,透過Tape還原+Catalog****************
Source db:c5pepm
Source Server:c5subdb1

若資料是放在Tape,有catalog DB,還原方式如下:
PS.若需要NBU Agent,當然需要先設定好及安裝好設定
#export ORACLE_SID=c5pepm
設定要從catalog server還原的server(主機名稱)(NBU指定的電腦名稱)
#export NB_ORA_CLIENT=c5subdb1

sqlplus / as sysdba
SQL>startup nomount pfile=/home/oracle/c5pepm.ora

$rman target sys/oracle@c5pepm catalog rman/rman@c5rman auxiliary /
Recovery Manager: Release 10.2.0.4.0 - Production on Tue Jan 14 10:52:05 2014
Copyright (c) 1982, 2007, Oracle.  All rights reserved.
connected to target database: C5PEPM (DBID=223792576)
connected to recovery catalog database
connected to auxiliary database: C5PEPM (not mounted)

run {
allocate auxiliary channel aux1 device type 'sbt_tape';
allocate auxiliary channel aux2 device type 'sbt_tape';
duplicate target database to c5pepm;}

**也可以使用active target database當作資料來源-> RMAN> duplicate target database to orcl2 from active database;

常見問題
Q1:
released channel: aux1
RMAN-00571: ==================================================
RMAN-00569: ==== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ==================================================
RMAN-03002: failure of Duplicate Db command at 01/13/2014 11:40:44
RMAN-03015: error occurred in stored script Memory Script
RMAN-06026: some targets not found - aborting restore
RMAN-06100: no channel to restore a backup or copy of datafile 5
RMAN-06100: no channel to restore a backup or copy of datafile 4
RMAN-06100: no channel to restore a backup or copy of datafile 3
RMAN-06100: no channel to restore a backup or copy of datafile 2
RMAN-06100: no channel to restore a backup or copy of datafile 1

A:target端未做archive log backup

run {
sql 'alter system  archive log current';
backup archivelog all;
}

Q: ORA-32006: LOG_ARCHIVE_START initialization parameter has been deprecated
A:
Control file需把”*.log_archive_start=TRUE”註解掉或刪除掉,在google找到的原因是說10g之後已把這個參數拿掉了。

Q:
RMAN-03002: failure of Duplicate Db command at 01/13/2014 13:51:05
RMAN-06136: ORACLE error from auxiliary database: ORA-01503: CREATE CONTROLFILE failed
ORA-01504: database name 'ORCL2' does not match parameter db_name 'TESTDB'

A:
duplicate端啟動db,可以看到說未找到參數檔,copy啟動參數到這個目錄底下:
SQL> startup
ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/u1/oracle/10gr2/dbs/initorcl2.ora'

# cp /home/oracle/initorcl2.ora /u1/oracle/10gr2/dbs/initorcl2.ora

Q: ORA-01589: must use RESETLOGS or NORESETLOGS option for database open
A:啟動DB時,需要Resetlog
SQL>startup mount;
SQL> alter database open resetlogs;

Q: RMAN-05001: auxiliary filename /oradata/c5pepm/data/c5pepm/sysaux01.dbf conflicts with a file used by the target database
RMAN-05001: auxiliary filename /oradata/c5pepm/data/c5pepm/undotbs01.dbf conflicts with a file used by the target database
RMAN-05001: auxiliary filename /oradata/c5pepm/data/c5pepm/system01.dbf conflicts with a file used by the target database

A:未設定此兩個參數,一定要全部都設定完成
*.db_file_name_convert='source1',’dest1’, 'source2',’dest2’ , 'source3',’dest3’
*.log_file_name_convert='source1',’dest1’, 'source2',’dest2’ , 'source3',’dest3’

參考資料:
Rman Duplicate database&常見問題
http://shortterm.blog.163.com/blog/static/588188242009635282339/
異機使用rman備份檔(11g)

http://ladfi.blogspot.tw/2013/07/oracle-11g-duplicate-database-rman.html