RMAN複製資料庫(一)

eric0435發表於2015-03-26

使用RMAN的duplicate命令使用目標資料庫(主庫)的備份來建立一個副本資料庫同時保留原目標資料庫副本資料庫可以和目標資料庫完全相同或者只包含目標資料庫中一部分表空間。目標資料庫和副本資料庫可以是在單獨的機器上,也可以是在相同的機器上。

副本資料庫是目標資料庫的副本可以用於各種目的。例如,可以用來:
.測試備份和恢復過程
.匯出那些無意中從生產資料庫中刪除的表資料並重新匯入到生產資料庫中

例如,可以將主機host1上的生產資料庫複製到主機host2上,並使用主機host2上的副本資料庫來練習還原和恢復的同時主機host1上的生產資料庫處於執行狀態。

複製的副本資料庫與備庫是有差別的,雖然兩種型別的資料庫都是使用duplicate命令建立。備庫是主庫的一個副本可以使用主庫的歸檔重做日誌連續或定期地更新。如果主庫被損壞或破壞,那麼可以對備庫執行故障轉移將它轉換為主庫。複製的副本資料庫是不能這樣使用的,它不能執和故障轉移並且不支援各種備庫恢復和故障轉移選項。

為了進行資料庫複製,首先得建立一個輔助例項。為了執行復制,必須使用RMAN連線到目標資料庫(主庫)和一個啟動到nomount狀態的輔助例項。

在輔助例項上至少分配一個輔助通道。執行復制的主要工作就是透過輔助通道來完成的,在複製的副本主機上啟動一個服務會話。這個輔助通道然後會還原所需要的主庫備份,使用它們來建立一個副本資料庫,並執行恢復。

只要RMAN可以連線到主資料庫和輔助例項,RMAN客戶端可以在任何主機上執行。所有用來建立和恢復複製的副本資料庫的備份和歸檔重做日誌都必須能被副本主機上的服務會話所訪問。如果副本主機與目標主機相同,那麼對一目標主機上的備份必須使用主資料庫的完整路徑名來讓副本主機能使用。

當使用磁碟備份時,可以使用以下任意方式來完成這個任務:
.從主資料庫主機上將備份手動傳輸到副本資料庫主機上的相同目錄下。例如,如果在主資料庫主機上備份儲存在/dsk1/bkp,那麼將它們傳輸到副本資料庫主機上的/dsk1/bkp中。

.從主資料庫主機上將備份手動傳輸到副本資料庫主機上的新目錄下。例如,如果在主資料庫主機上備份儲存在/dsk1/bkp,然後將備份傳輸到副本資料庫主機上的/dsk2/dup中。在這裡新路徑 /dsk2/dup必須在目標主機和副本主機上都能訪問。執行catalog命令將這些備份副本登記在副本資料庫主機上的RMAN檔案庫中。

.使用NFS或共享磁碟並確保在副本資料庫主機上有相同的路徑。例如,NFS的掛載點在所有主機上都是/home/file_server

當使用磁帶備份時,必須讓儲存備份的磁帶能讓副本資料庫主機所訪問。透過物理移動磁帶上的備份到副本資料庫主機所附加的裝置上或者透過網路訪問磁帶服務

作為複製操作的一部分,RMAN自動執行以下步驟:
.為複製的副本資料庫建立控制檔案
.透過使用所有可用的增量備份和歸檔重做日誌來對副本資料庫還原目標資料檔案並執行不完全恢復
.重啟輔助例項.
.在不完全恢復後使用resetlogs選項來開啟資料庫並建立聯機重做日誌(當執行在duplicate ... for standby之下時RMAN不會開啟資料庫)

在執行復制時,RMAN必須執行不完全恢復因為目標資料庫的聯機重做日誌沒有被備份並且不能應用到複製的副本資料庫。RMAN可以將副本資料庫恢復到目標資料庫最後歸檔重做日誌所對應的時間點。

當複製資料庫時可以執行以下選項:
.可以使用也可以不使用恢復目錄來執行duplicate命令
.使用skip readonly子句跳過只讀表空間,預設情況下包含只讀表空間。
.使用skip tablespace子句來排除表空間。可以排除system表空間或包含回滾或undo段的表空間之外的任何表空間。
.可以在新主機上建立副本資料庫。如果新主機的目錄結構與目標主機相同,那麼指定nofilenamecheck選項並對複製的資料檔案使用目標資料庫資料檔名。
.可以將儲存在傳統檔案系統上的目標資料庫複製到ASM或OMF中
.預設情況下,duplicate命令將使用目標資料庫的最近備份來建立副本資料庫並恢復到歸檔日誌檔案所對應的一致性時間點。透過使用set until命令的RUN塊或透過有until子句的duplicate命令來讓RMAN將複製的副本資料庫恢復到當前資料庫化身的過去某個時間點。(然而不能使用duplicate命令將複製的副本資料庫恢復到目標資料庫之前化身的過去某個時間點)
.在相同恢復目錄中可以像目標資料庫一樣來注意複製的副本資料庫。因為RMAN給複製的副本資料庫生成了新的DBID。注意:如果使用作業系統工具複製目標資料庫,那麼複製生成的副本資料庫的DBID與目標資料庫一樣。為了在相同的恢復目錄中註冊副本資料庫必須使用DBNEWID工具來改變副本資料庫的DBID。
.在有些情況下,可以設定複製的副本資料庫的DB_NAME不同於目標資料庫的DB_NAME。具體來說,如果在目標資料庫相同的Oracle Home目錄中複製一個資料庫時,那麼DB_NAME引數必須不同。如果在與目標資料庫不同的Oracle Home目錄中複製一個資料庫,那麼DB_NAME引數在它的Oracle Home中必須是唯一的。

重新命名RMAN複製資料庫的資料庫檔案
在複製一個資料庫時,RMAN會對資料庫檔案生成檔名,其中包括控制檔案,聯機重做日誌檔案,資料檔案和臨時檔案。

重新命名複製資料庫的控制檔案
確定複製資料庫控制檔名稱的優先順序規則與create controlfile語句使用的一樣。當給複製資料庫的控制檔案選擇名稱時,確保對輔助資料庫設定了正確的引數,否則,可能會覆蓋目標資料庫的控制檔案。

重新命名複製資料庫的聯機重做日誌檔案
RMAN需要為複製生成的資料庫使用新的聯機重做日誌檔名。可以在duplicate命令中顯式指定,也可以讓RMAN根據下面的規則來生成。

表1-1 生成聯機重做日誌檔名的優先順序規則

-------------------------------------------------------------------------------------------
優先順序       方法                                   結果
-------------------------------------------------------------------------------------------
1        在duplicate命令中指定logfile子句         根據指定條件生成聯機重做日誌檔案

2        設定log_file_name_convert引數            轉換目標檔名,例如從log_*轉換為duplog_*
                                                  注意可以指定多個轉換對

3        設定一個OMF引數db_create_file_dest,      基於設定的引數來轉換目標檔名。這些引數
         db_create_online_dest_n或者              的優先順序與alter database add logfile語句
         db_recovery_file_dest                    一樣

4        沒有執行前面的設定                       複製資料庫的檔名與目標資料庫的檔名相
                                                  同。當使用這種方法時必須指定
                                                  nofilenamecheck選項,並且要將資料庫複製到
                                                  不同的主機上這樣聯機重做日誌檔案才不會與
                                                  目標資料庫的聯機重做日誌檔案衝突
-------------------------------------------------------------------------------------------

優先順序規則中優先順序高的會覆蓋優先順序低的。例如,如果指定了logfile子句和log_file_name_convert引數,那麼RMAN將會使用logfile子句。如果目標資料庫和複製的資料庫在相同主機上,那麼不要對複製的資料庫使用與目標資料庫相同名稱的聯機重做日誌。如果複製的資料庫與目標資料庫在不同主機上,但沒有使用nofilenamecheck選項,那麼不要對複製的資料庫使用與目標資料庫相同名稱的聯機重做日誌

重新命名RMAN複製資料庫的資料檔名
有幾種方法用來指定複製資料庫的資料檔名。按優先順序依次為:
1.在RUN塊中使用set newname for datafile命令,包含set newname與duplicate命令。
2.對已經存在的資料檔案使用configure auxname來指定新名稱。在duplicate命令之前執行configure auxname命令。
3.在duplicate命令中指定db_file_name_convert引數來為沒有使用set newname或configure auxname進行重新命名的任何資料檔案指定檔名轉換的規則。在目標例項使用OMF時有db_file_name_convert子句的duplicate命令不能對複製的副本例項生成新的檔名。
4.設定db_file_name_convert引數。在目標例項使用OMF時db_file_name_convert引數不能對複製的副本例項生成新的檔名。它的語法與duplicate命令中的db_file_name_convert引數一樣。
5.設定db_create_file_dest引數在指定目錄中生成OMF的資料檔案

如果沒有使用上面的任何規則選項,那麼複製的資料庫將重用目標資料庫的資料檔案目錄。

阻止對複製資料庫的檔名檢查
如果可能使用configure auxname,set newname或db_file_name_convert來生成複製的副本資料庫檔名在這種情況下,在duplicate命令中指定nofilenamecheck選項可以避免出錯。

例如,假設主機A上資料庫有兩個檔案:資料檔案1被命名為/oracle/data/file1.f,資料檔案2被命名為/oracle/data/file2.f。當將資料庫複製到主機B上時,使用配置的通道進行復制:

RUN
{
SET NEWNAME FOR DATAFILE 1 TO /oracle/data/file2.f; # rename df 1 as file2.f
SET NEWNAME FOR DATAFILE 2 TO /oracle/data/file1.f; # rename df 2 as file1.f
DUPLICATE TARGET DATABASE TO newdb;
}

即使你對所有資料檔案執行set newname命令,因為複製的檔名仍然會使用目標資料庫的資料檔名所以duplicate命令會失敗。雖然資料檔案1在目標資料庫中沒有使用/oracle/data/file2.f並且資料檔案2在目標資料庫中沒有使用/oracle/data/file1.f,目標資料庫名被另一個複製的資料檔案所使用。因此必須指定duplicate ... nofilenamecheck來避免錯誤。

重新命名RMAN複製資料庫的臨時檔案
作為複製一個資料庫的一部分RMAN會重新建立臨時表空間。有幾種方法來為複製資料庫的臨時檔案指定目錄。按優先順序別依次為:
1.在RUN塊中使用set newname for tempfile命令這樣同時使用set newname和duplicate命令。
2.在duplicate命令中使用db_file_name_convert子句來為沒有使用set newname或configure auxname進行重新命名的臨時檔案指定轉換規則。當目標例項使用了OMF,db_file_name_convert子句不能用來生成複製資料庫的檔名。
3.設定db_file_name_convert引數。db_file_name_convert引數與duplicate命令中的
db_file_name_convert引數有相同的語法和限制
4.設定db_create_file_dest引數來建立OMF的臨時檔案

RMAN複製資料庫時跳過指定表空間
不總是需要複製資料庫中的所有表空間。例如,可能只需要從目標資料庫中複製一組表空間來生成報告。RMAN的duplicate database可以跳過只讀表空間或者當前offline normal的表空間。

複製資料庫時跳過只讀取表空間
當指定skip readonly時,RMAN不會複製只讀表空間的資料檔案。在複製完成後,可以查詢複製的副本資料庫中的檢視來判斷那些資料檔案被跳過。status和enabled列描述了複製資料檔案的當前狀態。

使用相同目錄結構在遠端主機上建立複製資料庫
在不同主機上覆制資料庫的最簡單情況就是使用相同目錄結構。在這種情況下不需要改變初始化引數檔案或者不需要為複製的資料檔案設定新的檔名。

1.建立輔助例項的密碼檔案(這裡輔助例項名為dup)

[oracle@jingyong1 dbs]$ orapwd file=/u01/app/oracle/product/10.2.0/db/dbs/orapwdup password=oracle entries=10;
[oracle@jingyong1 dbs]$ ls -lrt
-rw-r----- 1 oracle oinstall    2560 Mar 24 14:47 orapwdup

2.建立輔助例項網路連線
修改監聽檔案,使用靜態監聽來監聽輔助例項

[oracle@jingyong1 admin]$ vi listener.ora

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
     (SID_NAME = dup)
      (ORACLE_HOME =/u01/app/oracle/product/10.2.0/db)
    )
  )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.11)(PORT = 1521))
    )
  )

給輔助例項增加網路服務名

[oracle@jingyong1 admin]$ vi tnsnames.ora
dup =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST =192.168.56.11)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME =dup)
      (UR=A)
    )
  )

測試網路連線

[oracle@jingyong1 admin]$ export ORACLE_SID=dup
[oracle@jingyong1 admin]$ sqlplus /nolog

SQL*Plus: Release 10.2.0.5.0 - Production on Tue Mar 24 14:57:08 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

SQL> conn sys/oracle@dup as sysdba
Connected to an idle instance.

3.建立輔助例項的引數檔案

[oracle@jingyong1 dbs]$ vi initdup.ora

db_name=dup
db_unique_name=dup
control_files= /u01/app/oracle/oradata/test/control01.ctl
remote_login_passwordfile=exclusive
compatible = 10.2.0.5.0
db_block_size=8192
sga_target=160M
sga_max_size=160M
pga_aggregate_target=16M



[oracle@jingyong1 dbs]$ export ORACLE_SID=dup
[oracle@jingyong1 dbs]$ sqlplus /nolog

SQL*Plus: Release 10.2.0.5.0 - Production on Tue Mar 24 15:05:51 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

SQL> conn sys/oracle@dup as sysdba

SQL> create spfile from pfile='/u01/app/oracle/product/10.2.0/db/dbs/initdup.ora';

File created.

4.啟動輔助例項

[oracle@jingyong1 dbs]$ export ORACLE_SID=dup
[oracle@jingyong1 dbs]$ sqlplus /nolog

SQL*Plus: Release 10.2.0.5.0 - Production on Tue Mar 24 15:05:51 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

SQL> conn sys/oracle@dup as sysdba
Connected to an idle instance.

SQL> startup nomount
ORACLE instance started.

Total System Global Area  167772160 bytes
Fixed Size                  1272624 bytes
Variable Size              58721488 bytes
Database Buffers          104857600 bytes
Redo Buffers                2920448 bytes

SQL> show parameter spfile

NAME                                 TYPE                   VALUE
------------------------------------ ---------------------- ------------------------------
spfile                               string                 /u01/app/oracle/product/10.2.0
                                                            /db/dbs/spfiledup.ora

斷開連線

SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

這裡一定要斷開啟動輔助例項的會話否則在執行復制操作時會出現如下錯誤 :

executing Memory Script

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of Duplicate Db command at 03/24/2015 18:28:32
RMAN-03015: error occurred in stored script Memory Script
RMAN-06136: ORACLE error from auxiliary database: ORA-01013: user requested cancel of current operation

在目標主機(執行被複制資料庫的主機)配置輔助例項的網路服務名

[oracle@oracle11g admin]$ vi tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/oracle/10.2.0/db/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.

JY =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.11)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = jy)
    )
  )

TEST =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.2)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = test)
    )
  )




dup =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST =192.168.56.11)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME =dup)
      (UR=A)
    )
  )

[oracle@oracle11g admin]$ sqlplus /nolog

SQL*Plus: Release 10.2.0.5.0 - Production on Tue Mar 24 15:49:11 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

SQL> conn sys/oracle@dup as sysdba
Connected.

5.載入或開啟目標資料庫

[oracle@oracle11g ~]$ sqlplus /nolog

SQL*Plus: Release 10.2.0.5.0 - Production on Tue Mar 24 08:48:03 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

SQL> conn / as sysdba
Connected to an idle instance.
SQL> startup
ORACLE instance started.

Total System Global Area  167772160 bytes
Fixed Size                  1272600 bytes
Variable Size              92275944 bytes
Database Buffers           71303168 bytes
Redo Buffers                2920448 bytes
Database mounted.
Database opened.

6.確保有需要的備份和歸檔重做日誌
對目標資料庫(被複制的資料庫)進行備份(包含資料檔案和歸檔重做日誌)

[oracle@oracle11g admin]$ export NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss'
[oracle@oracle11g admin]$ rman target sys/zzh_2046@test catalog rman/rman@jy

Recovery Manager: Release 10.2.0.5.0 - Production on Tue Mar 24 15:15:52 2015

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

connected to target database: TEST (DBID=2168949517)
connected to recovery catalog database

RMAN> backup as backupset database plus archivelog delete all input;


Starting backup at 2015-03-24 15:18:57
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=49 recid=56 stamp=874583978
input archive log thread=1 sequence=50 recid=57 stamp=874583996
input archive log thread=1 sequence=51 recid=58 stamp=874585387
input archive log thread=1 sequence=52 recid=59 stamp=874587721
input archive log thread=1 sequence=53 recid=60 stamp=874588386
input archive log thread=1 sequence=54 recid=61 stamp=874657003
input archive log thread=1 sequence=55 recid=62 stamp=874667860
input archive log thread=1 sequence=56 recid=63 stamp=874667943
input archive log thread=1 sequence=57 recid=64 stamp=874668125
input archive log thread=1 sequence=58 recid=65 stamp=874668205
input archive log thread=1 sequence=59 recid=66 stamp=874841642
input archive log thread=1 sequence=60 recid=67 stamp=874842111
input archive log thread=1 sequence=61 recid=68 stamp=875091192
input archive log thread=1 sequence=62 recid=69 stamp=875177310
input archive log thread=1 sequence=63 recid=70 stamp=875200740
channel ORA_DISK_1: starting piece 1 at 2015-03-24 15:19:03
channel ORA_DISK_1: finished piece 1 at 2015-03-24 15:19:19
piece handle=/u02/ora_test875200742_711 tag=TAG20150324T151901 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:17
channel ORA_DISK_1: deleting archive log(s)
archive log filename=/u02/1_49_870806981.dbf recid=56 stamp=874583978
archive log filename=/u02/1_50_870806981.dbf recid=57 stamp=874583996
archive log filename=/u02/1_51_870806981.dbf recid=58 stamp=874585387
archive log filename=/u02/1_52_870806981.dbf recid=59 stamp=874587721
archive log filename=/u02/1_53_870806981.dbf recid=60 stamp=874588386
archive log filename=/u02/1_54_870806981.dbf recid=61 stamp=874657003
archive log filename=/u02/1_55_870806981.dbf recid=62 stamp=874667860
archive log filename=/u02/1_56_870806981.dbf recid=63 stamp=874667943
archive log filename=/u02/1_57_870806981.dbf recid=64 stamp=874668125
archive log filename=/u02/1_58_870806981.dbf recid=65 stamp=874668205
archive log filename=/u02/1_59_870806981.dbf recid=66 stamp=874841642
archive log filename=/u02/1_60_870806981.dbf recid=67 stamp=874842111
archive log filename=/u02/1_61_870806981.dbf recid=68 stamp=875091192
archive log filename=/u02/1_62_870806981.dbf recid=69 stamp=875177310
archive log filename=/u02/1_63_870806981.dbf recid=70 stamp=875200740
Finished backup at 2015-03-24 15:19:20

Starting backup at 2015-03-24 15:19:20
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=/u01/app/oracle/oradata/test/system01.dbf
input datafile fno=00003 name=/u01/app/oracle/oradata/test/sysaux01.dbf
input datafile fno=00005 name=/u01/app/oracle/oradata/test/example01.dbf
input datafile fno=00006 name=/u01/app/oracle/oradata/test/tspitr01.dbf
input datafile fno=00002 name=/u01/app/oracle/oradata/test/undotbs01.dbf
input datafile fno=00004 name=/u01/app/oracle/oradata/test/users01.dbf
channel ORA_DISK_1: starting piece 1 at 2015-03-24 15:19:21
channel ORA_DISK_1: finished piece 1 at 2015-03-24 15:20:46
piece handle=/u02/ora_test875200761_721 tag=TAG20150324T151920 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:25
Finished backup at 2015-03-24 15:20:46

Starting backup at 2015-03-24 15:20:47
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=64 recid=71 stamp=875200847
channel ORA_DISK_1: starting piece 1 at 2015-03-24 15:20:49
channel ORA_DISK_1: finished piece 1 at 2015-03-24 15:20:50
piece handle=/u02/ora_test875200848_731 tag=TAG20150324T152048 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
channel ORA_DISK_1: deleting archive log(s)
archive log filename=/u02/1_64_870806981.dbf recid=71 stamp=875200847
Finished backup at 2015-03-24 15:20:50

Starting Control File and SPFILE Autobackup at 2015-03-24 15:20:50
piece handle=/u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_03_24/o1_mf_s_875200851_bk242now_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 2015-03-24 15:20:55

RMAN> list backup;


List of Backup Sets
===================

BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ -------------------
4452    61.69M     DISK        00:00:15     2015-03-24 15:19:17
        BP Key: 4453   Status: AVAILABLE  Compressed: NO  Tag: TAG20150324T151901
        Piece Name: /u02/ora_test875200742_711

  List of Archived Logs in backup set 4452
  Thrd Seq     Low SCN    Low Time            Next SCN   Next Time
  ---- ------- ---------- ------------------- ---------- ---------
  1    49      833130     2015-03-17 11:59:13 833176     2015-03-17 11:59:38
  1    50      833176     2015-03-17 11:59:38 833183     2015-03-17 11:59:56
  1    51      833183     2015-03-17 11:59:56 834037     2015-03-17 12:23:07
  1    52      834037     2015-03-17 12:23:07 835281     2015-03-17 13:02:01
  1    53      835281     2015-03-17 13:02:01 835767     2015-03-17 13:13:06
  1    54      835767     2015-03-17 13:13:06 867877     2015-03-18 08:16:39
  1    55      867877     2015-03-18 08:16:39 873825     2015-03-18 11:17:38
  1    56      873825     2015-03-18 11:17:38 873875     2015-03-18 11:19:03
  1    57      873875     2015-03-18 11:19:03 873988     2015-03-18 11:22:05
  1    58      873988     2015-03-18 11:22:05 874075     2015-03-18 11:23:25
  1    59      874075     2015-03-18 11:23:25 907518     2015-03-20 11:33:59
  1    60      907518     2015-03-20 11:33:59 928331     2015-03-20 11:41:50
  1    61      928331     2015-03-20 11:41:50 960300     2015-03-23 08:53:08
  1    62      960300     2015-03-23 08:53:08 998814     2015-03-24 08:48:24
  1    63      998814     2015-03-24 08:48:24 1009277    2015-03-24 15:18:57

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
4479    Full    624.66M    DISK        00:01:24     2015-03-24 15:20:45
        BP Key: 4495   Status: AVAILABLE  Compressed: NO  Tag: TAG20150324T151920
        Piece Name: /u02/ora_test875200761_721
  List of Datafiles in backup set 4479
  File LV Type Ckp SCN    Ckp Time            Name
  ---- -- ---- ---------- ------------------- ----
  1       Full 1009303    2015-03-24 15:19:21 /u01/app/oracle/oradata/test/system01.dbf
  2       Full 1009303    2015-03-24 15:19:21 /u01/app/oracle/oradata/test/undotbs01.dbf
  3       Full 1009303    2015-03-24 15:19:21 /u01/app/oracle/oradata/test/sysaux01.dbf
  4       Full 1009303    2015-03-24 15:19:21 /u01/app/oracle/oradata/test/users01.dbf
  5       Full 1009303    2015-03-24 15:19:21 /u01/app/oracle/oradata/test/example01.dbf
  6       Full 1009303    2015-03-24 15:19:21 /u01/app/oracle/oradata/test/tspitr01.dbf

BS Key  Size       Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ -------------------
4511    3.00K      DISK        00:00:01     2015-03-24 15:20:49
        BP Key: 4518   Status: AVAILABLE  Compressed: NO  Tag: TAG20150324T152048
        Piece Name: /u02/ora_test875200848_731

  List of Archived Logs in backup set 4511
  Thrd Seq     Low SCN    Low Time            Next SCN   Next Time
  ---- ------- ---------- ------------------- ---------- ---------
  1    64      1009277    2015-03-24 15:18:57 1009334    2015-03-24 15:20:47

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
4529    Full    6.89M      DISK        00:00:02     2015-03-24 15:20:53
        BP Key: 4531   Status: AVAILABLE  Compressed: NO  Tag: TAG20150324T152051
        Piece Name: /u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_03_24/o1_mf_s_875200851_bk242now_.bkp
  Control File Included: Ckp SCN: 1009356      Ckp time: 2015-03-24 15:20:51
  SPFILE Included: Modification time: 2015-03-24 08:48:23

將上面的備份傳輸到遠端主機的相同目錄中:

[oracle@jingyong1 u02]$ scp -r oracle@192.168.56.2:/u02/ora_test875200742_711 /u02
The authenticity of host '192.168.56.2 (192.168.56.2)' can't be established.
RSA key fingerprint is fb:1d:33:a6:9e:25:86:6a:a0:44:76:d4:cf:eb:c9:c4.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.56.2' (RSA) to the list of known hosts.
oracle@192.168.56.2's password:
ora_test875200742_711                                                                                                                100%   62MB  10.3MB/s   00:06
[oracle@jingyong1 u02]$ scp -r oracle@192.168.56.2:/u02/ora_test875200761_721 /u02
oracle@192.168.56.2's password:
ora_test875200761_721                                                                                                                100%  625MB   7.7MB/s   01:21
[oracle@jingyong1 u02]$ scp -r oracle@192.168.56.2:/u02/ora_test875200848_731 /u02
oracle@192.168.56.2's password:
ora_test875200848_731                                                                                                                100% 3584     3.5KB/s   00:00
[oracle@jingyong1 u02]$ scp -r oracle@192.168.56.2:/u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_03_24/o1_mf_s_875200851_bk242now_.bkp /u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_03_24/
oracle@192.168.56.2's password:
o1_mf_s_875200851_bk242now_.bkp

7.執行duplicate命令,如果沒有配置自動通道,那麼至少手動分配一個輔助例項。給duplicate命令指定nofilenamecheck引數。如果是使用PFILE引數檔案啟動輔助例項需要指定pfile引數檔案,且pfile引數檔案必須儲存在執行RMAN執行復制的主機上。這裡輔助例項使用SPFILE引數檔案來啟動,並使用自動通道和指定nofilenamecheck選項:

[oracle@oracle11g admin]$ rman target sys/zzh_2046@test auxiliary sys/oracle@dup catalog rman/rman@jy

Recovery Manager: Release 10.2.0.5.0 - Production on Tue Mar 24 19:19:31 2015

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

connected to target database: TEST (DBID=2168949517)
connected to recovery catalog database
connected to auxiliary database: DUP (not mounted)

RMAN> duplicate target database to dup nofilenamecheck;

Starting Duplicate Db at 2015-03-24 19:19:46
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=35 devtype=DISK

contents of Memory Script:
{
   set until scn  1009334;
   set newname for datafile  1 to
 "/u01/app/oracle/oradata/test/system01.dbf";
   set newname for datafile  2 to
 "/u01/app/oracle/oradata/test/undotbs01.dbf";
   set newname for datafile  3 to
 "/u01/app/oracle/oradata/test/sysaux01.dbf";
   set newname for datafile  4 to
 "/u01/app/oracle/oradata/test/users01.dbf";
   set newname for datafile  5 to
 "/u01/app/oracle/oradata/test/example01.dbf";
   set newname for datafile  6 to
 "/u01/app/oracle/oradata/test/tspitr01.dbf";
   restore
   check readonly
   clone database
   ;
}
executing Memory Script

executing command: SET until clause

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at 2015-03-24 19:19:46
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u01/app/oracle/oradata/test/system01.dbf
restoring datafile 00002 to /u01/app/oracle/oradata/test/undotbs01.dbf
restoring datafile 00003 to /u01/app/oracle/oradata/test/sysaux01.dbf
restoring datafile 00004 to /u01/app/oracle/oradata/test/users01.dbf
restoring datafile 00005 to /u01/app/oracle/oradata/test/example01.dbf
restoring datafile 00006 to /u01/app/oracle/oradata/test/tspitr01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test875200761_721
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test875200761_721 tag=TAG20150324T151920
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:05
Finished restore at 2015-03-24 19:20:52
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "DUP" RESETLOGS ARCHIVELOG
  MAXLOGFILES     16
  MAXLOGMEMBERS      3
  MAXDATAFILES      100
  MAXINSTANCES     8
  MAXLOGHISTORY      292
 LOGFILE
  GROUP  1 ( '/u01/app/oracle/oradata/test/redo01.log' ) SIZE 50 M  REUSE,
  GROUP  2 ( '/u01/app/oracle/oradata/test/redo02.log' ) SIZE 50 M  REUSE,
  GROUP  3 ( '/u01/app/oracle/oradata/test/redo03.log' ) SIZE 50 M  REUSE
 DATAFILE
  '/u01/app/oracle/oradata/test/system01.dbf'
 CHARACTER SET ZHS16GBK


contents of Memory Script:
{
   switch clone datafile all;
}
executing Memory Script

datafile 2 switched to datafile copy
input datafile copy recid=1 stamp=875215264 filename=/u01/app/oracle/oradata/test/undotbs01.dbf
datafile 3 switched to datafile copy
input datafile copy recid=2 stamp=875215264 filename=/u01/app/oracle/oradata/test/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy recid=3 stamp=875215264 filename=/u01/app/oracle/oradata/test/users01.dbf
datafile 5 switched to datafile copy
input datafile copy recid=4 stamp=875215264 filename=/u01/app/oracle/oradata/test/example01.dbf
datafile 6 switched to datafile copy
input datafile copy recid=5 stamp=875215264 filename=/u01/app/oracle/oradata/test/tspitr01.dbf

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

executing command: SET until clause

Starting recover at 2015-03-24 19:20:53
using channel ORA_AUX_DISK_1

starting media recovery

channel ORA_AUX_DISK_1: starting archive log restore to default destination
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=64
channel ORA_AUX_DISK_1: reading from backup piece /u02/ora_test875200848_731
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/ora_test875200848_731 tag=TAG20150324T152048
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_64_870806981.dbf thread=1 sequence=64
channel clone_default: deleting archive log(s)
archive log filename=/u01/app/oracle/product/10.2.0/db/dbs/arch1_64_870806981.dbf recid=1 stamp=875215263
media recovery complete, elapsed time: 00:00:01
Finished recover at 2015-03-24 19:20:57

contents of Memory Script:
{
   shutdown clone;
   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     167772160 bytes

Fixed Size                     1272624 bytes
Variable Size                 58721488 bytes
Database Buffers             104857600 bytes
Redo Buffers                   2920448 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "DUP" RESETLOGS ARCHIVELOG
  MAXLOGFILES     16
  MAXLOGMEMBERS      3
  MAXDATAFILES      100
  MAXINSTANCES     8
  MAXLOGHISTORY      292
 LOGFILE
  GROUP  1 ( '/u01/app/oracle/oradata/test/redo01.log' ) SIZE 50 M  REUSE,
  GROUP  2 ( '/u01/app/oracle/oradata/test/redo02.log' ) SIZE 50 M  REUSE,
  GROUP  3 ( '/u01/app/oracle/oradata/test/redo03.log' ) SIZE 50 M  REUSE
 DATAFILE
  '/u01/app/oracle/oradata/test/system01.dbf'
 CHARACTER SET ZHS16GBK


contents of Memory Script:
{
   set newname for tempfile  1 to
 "/u01/app/oracle/oradata/test/temp01.dbf";
   switch clone tempfile all;
   catalog clone datafilecopy  "/u01/app/oracle/oradata/test/undotbs01.dbf";
   catalog clone datafilecopy  "/u01/app/oracle/oradata/test/sysaux01.dbf";
   catalog clone datafilecopy  "/u01/app/oracle/oradata/test/users01.dbf";
   catalog clone datafilecopy  "/u01/app/oracle/oradata/test/example01.dbf";
   catalog clone datafilecopy  "/u01/app/oracle/oradata/test/tspitr01.dbf";
   switch clone datafile all;
}
executing Memory Script

executing command: SET NEWNAME

renamed temporary file 1 to /u01/app/oracle/oradata/test/temp01.dbf in control file

cataloged datafile copy
datafile copy filename=/u01/app/oracle/oradata/test/undotbs01.dbf recid=1 stamp=875215374

cataloged datafile copy
datafile copy filename=/u01/app/oracle/oradata/test/sysaux01.dbf recid=2 stamp=875215374

cataloged datafile copy
datafile copy filename=/u01/app/oracle/oradata/test/users01.dbf recid=3 stamp=875215374

cataloged datafile copy
datafile copy filename=/u01/app/oracle/oradata/test/example01.dbf recid=4 stamp=875215374

cataloged datafile copy
datafile copy filename=/u01/app/oracle/oradata/test/tspitr01.dbf recid=5 stamp=875215374

datafile 2 switched to datafile copy
input datafile copy recid=1 stamp=875215374 filename=/u01/app/oracle/oradata/test/undotbs01.dbf
datafile 3 switched to datafile copy
input datafile copy recid=2 stamp=875215374 filename=/u01/app/oracle/oradata/test/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy recid=3 stamp=875215374 filename=/u01/app/oracle/oradata/test/users01.dbf
datafile 5 switched to datafile copy
input datafile copy recid=4 stamp=875215374 filename=/u01/app/oracle/oradata/test/example01.dbf
datafile 6 switched to datafile copy
input datafile copy recid=5 stamp=875215374 filename=/u01/app/oracle/oradata/test/tspitr01.dbf

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

database opened
Finished Duplicate Db at 2015-03-24 19:23:05


[oracle@jingyong1 dbs]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.5.0 - Production on Tue Mar 24 19:26:06 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.


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

SQL> select instance_name from v$instance;

INSTANCE_NAME
----------------
dup

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26015009/viewspace-1475197/,如需轉載,請註明出處,否則將追究法律責任。

相關文章