天天看點

Oracle 11g RMAN 異機duplicate資料庫

Oracle 11g RMAN 異機duplicate資料庫

實驗平台: IBM AIX 5L + Oracle 11g 

目标庫資訊:

ORACLE_BASE: /u01/app/oracle

ORACLE_HOME: /u01/app/oracle/product/11.2.0/db_1

ORACLE_SID:orcl

IP: 172.30.2.40

輔助庫資訊:

ORACLE_BASE: /u01/app/oracle

ORACLE_HOME: /u01/app/oracle/product/11.2.0/db_1

ORACLE_SID:orcl

IP: 172.30.2.56

在這裡,我們以執行個體名相同的為例,執行個體名不同也一樣,在pfile裡修改對應參數就可以了。

步驟如下:

(1)建構輔助資料庫目錄結構

(2)建立pfile,并複制到輔助資料庫,修改相關内容

(3)建立輔助執行個體密碼檔案

(4)RMAN 備份源庫

(5)添加配置監聽

(6)将源庫備份檔案拷貝到輔助庫相同位置

(7)用pfile檔案,将輔助資料庫啟動到nomount 狀态

(8)執行RMAN duplicate指令複制資料庫

(9)建立spfile檔案

一.建構輔助資料庫目錄結構

1.1  Oracle data 目錄

$ mkdir -p /u01/app/oracle/oradata/orcl

1.2  其他目錄

$ mkdir -p /u01/app/oracle/admin/orcl/adump

$ mkdir -p /u01/app/oracle/admin/orcl/dpdump

$ mkdir -p /u01/app/oracle/admin/orcl/pfile

$ mkdir -p /u01/app/oracle/admin/orcl/scripts

$ mkdir -p /u01/app/oracle/diag

$ mkdir -p /u01/app/oracle/flash_recovery_area/orcl

二.建立pfile,複制到輔助資料庫,并修改相關參數

2.1 在源庫上建立pfile 檔案

$ sqlplus /nolog

SQL*Plus: Release 11.2.0.1.0 Production on Mon Apr 11 08:26:48 2011

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

idle> conn /as sysdba

Connected.

[email protected]> create pfile='/u01/initorcl.ora' from spfile;

File created.

2.2 用scp 指令将pfile 檔案傳到輔助庫,要放在$ORACLE_HOME/dbs目錄下,不然ORACLE 不識别。

$ scp initorcl.ora 172.30.2.56:/$ORACLE_HOME/dbs

Enter passphrase for key '/home/oracle/.ssh/id_rsa': 

initorcl.ora                                                         100%  921     0.9KB/s   00:00 

2.3 在輔助庫上确認檔案是否傳送過來

$ cd $ORACLE_HOME/dbs

$ ls

init.ora      initorcl.ora  orapworcl

2.4 在輔助庫上修改pfile參數

orcl.__db_cache_size=3288334336

orcl.__java_pool_size=16777216

orcl.__large_pool_size=16777216

orcl.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment

orcl.__pga_aggregate_target=2751463424

orcl.__sga_target=4127195136

orcl.__shared_io_pool_size=0

orcl.__shared_pool_size=754974720

orcl.__streams_pool_size=0

*.audit_file_dest='/u01/app/oracle/admin/orcl/adump'

*.audit_trail='db'

*.compatible='11.2.0.0.0'

*.control_files='/u01/app/oracle/oradata/orcl/control01.ctl','/u01/app/oracle/flash_recovery_area/orcl/

control02.ctl'

*.db_block_size=8192

*.db_domain='saci.com.cn'

*.db_name='orcl'

*.db_recovery_file_dest='/u01/app/oracle/flash_recovery_area'

*.db_recovery_file_dest_size=4039114752

*.diagnostic_dest='/u01/app/oracle'

*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'

*.memory_target=6867124224

*.open_cursors=300

*.processes=150

*.remote_login_passwordfile='EXCLUSIVE'

*.undo_tablespace='UNDOTBS1'

說明,在這裡我沒有做修改,因為我異機duplicate執行個體名相同,存儲位置也相同。如果說你複制的不同的話,就需要修改相關的執行個體名。如果存儲位置不同的話,還需要添加以下參數,對資料檔案位置進行轉換。

db_file_name_convert = ('/u01/app/oracle/oradata/orcl','/u01/app/oracle/oradata/mahee')

三.建立輔助執行個體ORCL的密碼檔案(需要和目标資料庫相同,最好從目标資料庫拷貝過來)

$ cd $ORACLE_HOME/bin

$ orapwd file=$ORACLE_HOME/dbs/orapworcl password=oracle entries=8

$ cd $ORACLE_HOME/dbs                                             

$ ls

init.ora      initorcl.ora  orapworcl

Windows下oracle預設的位置是$ORACLE_HOME/database目錄,檔案名格式是pwdSID.ora。 

Linux下oracle預設的位置是$ORACLE_HOME/dbs目錄,檔案名格式是orapwSID。建立完後,資料庫需要重新開機動,新的密碼檔案才能生效。

四.RMAN 備份源庫(目标資料庫orcl)

172.30.2.40(目标資料庫orcl)

$ rman target sys/[email protected]

Recovery Manager: Release 11.2.0.1.0 - Production on Mon Apr 11 08:40:43 2011

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

connected to target database: ORCL (DBID=1275959622)

RMAN> RUN {

2> allocate channel c1 type disk;

3> allocate channel c2 type disk;

4> BACKUP FORMAT '/u02/backup/orcl_%U_%T' skip inaccessible filesperset 5 DATABASE TAG orcl_hot_db_bk;

5> sql 'alter system archive log current';                                        

6> BACKUP FORMAT '/u02/backup/arch_%U_%T' skip inaccessible filesperset 5 ARCHIVELOG ALL DELETE INPUT;

7> backup current controlfile tag='bak_ctlfile' format='/u02/backup/ctl_file_%U_%T';

8> backup spfile tag='spfile' format='/u02/backup/ORCL_spfile_%U_%T';

9> release channel c2;

10> release channel c1;

11> }

using target database control file instead of recovery catalog

allocated channel: c1

channel c1: SID=195 device type=DISK

allocated channel: c2

channel c2: SID=10 device type=DISK

Starting backup at 11-APR-11

channel c1: starting full datafile backup set

channel c1: specifying datafile(s) in backup set

input datafile file number=00001 name=/u01/app/oracle/oradata/orcl/system01.dbf

input datafile file number=00004 name=/u01/app/oracle/oradata/orcl/users01.dbf

channel c1: starting piece 1 at 11-APR-11

channel c2: starting full datafile backup set

channel c2: specifying datafile(s) in backup set

input datafile file number=00002 name=/u01/app/oracle/oradata/orcl/sysaux01.dbf

input datafile file number=00005 name=/u01/app/oracle/oradata/orcl/example01.dbf

input datafile file number=00003 name=/u01/app/oracle/oradata/orcl/undotbs01.dbf

channel c2: starting piece 1 at 11-APR-11

channel c1: finished piece 1 at 11-APR-11

piece handle=/u02/backup/orcl_0cm9ga44_1_1_20110411 tag=ORCL_HOT_DB_BK comment=NONE

channel c1: backup set complete, elapsed time: 00:00:03

channel c2: finished piece 1 at 11-APR-11

piece handle=/u02/backup/orcl_0dm9ga44_1_1_20110411 tag=ORCL_HOT_DB_BK comment=NONE

channel c2: backup set complete, elapsed time: 00:00:03

Finished backup at 11-APR-11

Starting Control File and SPFILE Autobackup at 11-APR-11

piece handle=/u01/app/oracle/flash_recovery_area/ORCL/autobackup/2011_04_11/o1_mf_s_748169351_6t61pqbg_.bkp comment=NONE

Finished Control File and SPFILE Autobackup at 11-APR-11

sql statement: alter system archive log current

Starting backup at 11-APR-11

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=8 RECID=3 STAMP=748149036

input archived log thread=1 sequence=9 RECID=4 STAMP=748169352

channel c1: starting piece 1 at 11-APR-11

channel c2: starting archived log backup set

channel c2: specifying archived log(s) in backup set

input archived log thread=1 sequence=10 RECID=5 STAMP=748169352

channel c2: starting piece 1 at 11-APR-11

channel c1: finished piece 1 at 11-APR-11

piece handle=/u02/backup/arch_0fm9ga48_1_1_20110411 tag=TAG20110411T084912 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/ORCL/archivelog/2011_04_11/o1_mf_1_8_6t5fvwtm_.arc RECID=3 STAMP=748149036

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_04_11/o1_mf_1_9_6t61prft_.arc RECID=4 STAMP=748169352

channel c2: finished piece 1 at 11-APR-11

piece handle=/u02/backup/arch_0gm9ga48_1_1_20110411 tag=TAG20110411T084912 comment=NONE

channel c2: backup set complete, elapsed time: 00:00:01

channel c2: deleting archived log(s)

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_04_11/o1_mf_1_10_6t61prlf_.arc RECID=5 STAMP=748169352

Finished backup at 11-APR-11

Starting backup at 11-APR-11

channel c1: starting full datafile backup set

channel c1: specifying datafile(s) in backup set

including current control file in backup set

channel c1: starting piece 1 at 11-APR-11

channel c1: finished piece 1 at 11-APR-11

piece handle=/u02/backup/ctl_file_0hm9ga4a_1_1_20110411 tag=BAK_CTLFILE comment=NONE

channel c1: backup set complete, elapsed time: 00:00:01

Finished backup at 11-APR-11

Starting backup at 11-APR-11

channel c1: starting full datafile backup set

channel c1: specifying datafile(s) in backup set

including current SPFILE in backup set

channel c1: starting piece 1 at 11-APR-11

channel c1: finished piece 1 at 11-APR-11

piece handle=/u02/backup/ORCL_spfile_0im9ga4c_1_1_20110411 tag=SPFILE comment=NONE

channel c1: backup set complete, elapsed time: 00:00:01

Finished backup at 11-APR-11

Starting Control File and SPFILE Autobackup at 11-APR-11

piece handle=/u01/app/oracle/flash_recovery_area/ORCL/autobackup/2011_04_11/o1_mf_s_748169357_6t61px9v_.bkp comment=NONE

Finished Control File and SPFILE Autobackup at 11-APR-11

released channel: c2

released channel: c1

RMAN> list backup;

List of Backup Sets

===================

BS Key  Type LV Size       Device Type Elapsed Time Completion Time

------- ---- -- ---------- ----------- ------------ ---------------

5       Full    436.09M    DISK        00:00:02     11-APR-11      

        BP Key: 5   Status: AVAILABLE  Compressed: NO  Tag: ORCL_HOT_DB_BK

        Piece Name: /u02/backup/orcl_0dm9ga44_1_1_20110411

  List of Datafiles in backup set 5

  File LV Type Ckp SCN    Ckp Time  Name

  ---- -- ---- ---------- --------- ----

  2       Full 1081802    11-APR-11 /u01/app/oracle/oradata/orcl/sysaux01.dbf

  3       Full 1081802    11-APR-11 /u01/app/oracle/oradata/orcl/undotbs01.dbf

  5       Full 1081802    11-APR-11 /u01/app/oracle/oradata/orcl/example01.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time

------- ---- -- ---------- ----------- ------------ ---------------

6       Full    593.82M    DISK        00:00:02     11-APR-11      

        BP Key: 6   Status: AVAILABLE  Compressed: NO  Tag: ORCL_HOT_DB_BK

        Piece Name: /u02/backup/orcl_0cm9ga44_1_1_20110411

  List of Datafiles in backup set 6

  File LV Type Ckp SCN    Ckp Time  Name

  ---- -- ---- ---------- --------- ----

  1       Full 1081801    11-APR-11 /u01/app/oracle/oradata/orcl/system01.dbf

  4       Full 1081801    11-APR-11 /u01/app/oracle/oradata/orcl/users01.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time

------- ---- -- ---------- ----------- ------------ ---------------

7       Full    7.42M      DISK        00:00:00     11-APR-11      

        BP Key: 7   Status: AVAILABLE  Compressed: NO  Tag: TAG20110411T084911

        Piece Name: /u01/app/oracle/flash_recovery_area/ORCL/autobackup/2011_04_11/o1_mf_s_748169351_6t61pqbg_.bkp

  SPFILE Included: Modification time: 10-APR-11

  SPFILE db_unique_name: ORCL

  Control File Included: Ckp SCN: 1081809      Ckp time: 11-APR-11

BS Key  Size       Device Type Elapsed Time Completion Time

------- ---------- ----------- ------------ ---------------

8       2.00K      DISK        00:00:00     11-APR-11      

        BP Key: 8   Status: AVAILABLE  Compressed: NO  Tag: TAG20110411T084912

        Piece Name: /u02/backup/arch_0gm9ga48_1_1_20110411

  List of Archived Logs in backup set 8

  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time

  ---- ------- ---------- --------- ---------- ---------

  1    10      1081825    11-APR-11 1081833    11-APR-11

BS Key  Size       Device Type Elapsed Time Completion Time

------- ---------- ----------- ------------ ---------------

9       15.56M     DISK        00:00:00     11-APR-11      

        BP Key: 9   Status: AVAILABLE  Compressed: NO  Tag: TAG20110411T084912

        Piece Name: /u02/backup/arch_0fm9ga48_1_1_20110411

  List of Archived Logs in backup set 9

  Thrd Seq     Low SCN    Low Time  Next SCN   Next Time

  ---- ------- ---------- --------- ---------- ---------

  1    8       1066859    11-APR-11 1071335    11-APR-11

  1    9       1071335    11-APR-11 1081825    11-APR-11

BS Key  Type LV Size       Device Type Elapsed Time Completion Time

------- ---- -- ---------- ----------- ------------ ---------------

10      Full    7.39M      DISK        00:00:01     11-APR-11      

        BP Key: 10   Status: AVAILABLE  Compressed: NO  Tag: BAK_CTLFILE

        Piece Name: /u02/backup/ctl_file_0hm9ga4a_1_1_20110411

  Control File Included: Ckp SCN: 1081853      Ckp time: 11-APR-11

BS Key  Type LV Size       Device Type Elapsed Time Completion Time

------- ---- -- ---------- ----------- ------------ ---------------

11      Full    80.00K     DISK        00:00:00     11-APR-11      

        BP Key: 11   Status: AVAILABLE  Compressed: NO  Tag: SPFILE

        Piece Name: /u02/backup/ORCL_spfile_0im9ga4c_1_1_20110411

  SPFILE Included: Modification time: 10-APR-11

  SPFILE db_unique_name: ORCL

BS Key  Type LV Size       Device Type Elapsed Time Completion Time

------- ---- -- ---------- ----------- ------------ ---------------

12      Full    7.42M      DISK        00:00:00     11-APR-11      

        BP Key: 12   Status: AVAILABLE  Compressed: NO  Tag: TAG20110411T084917

        Piece Name: /u01/app/oracle/flash_recovery_area/ORCL/autobackup/2011_04_11/o1_mf_s_748169357_6t61px9v_.bkp

  SPFILE Included: Modification time: 10-APR-11

  SPFILE db_unique_name: ORCL

  Control File Included: Ckp SCN: 1081866      Ckp time: 11-APR-11

RMAN>  

五.添加,配置監聽

5.1 在輔助庫的listener.ora 檔案中,添加如下内容

$ cd $ORACLE_HOME/network/admin

LISTENER =

  (DESCRIPTION_LIST =

    (DESCRIPTION =

      (ADDRESS = (PROTOCOL = TCP)(HOST = 172.30.2.56)(PORT = 1521))

      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))

    )

  )

SID_LIST_LISTENER =

  (SID_LIST =

     (SID_DESC =

        (GLOBAL_DBNAME = orcl.saci.com.cn)

        (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)

        (SID_NAME = orcl)

      )

  )

ADR_BASE_LISTENER = /u01/app/oracle

5.2 修改輔助庫的tnsnames.ora 檔案,添加如下内容

TARGETORCL =

  (DESCRIPTION =

    (ADDRESS_LIST =

      (ADDRESS = (PROTOCOL = TCP)(HOST = 172.30.2.40)(PORT = 1521))

    )

    (CONNECT_DATA =

      (SERVICE_NAME = orcl.saci.com.cn)

    )

  )

ORCL =

  (DESCRIPTION =

    (ADDRESS_LIST =

      (ADDRESS = (PROTOCOL = TCP)(HOST = 172.30.2.56)(PORT = 1521))

    )

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = orcl.saci.com.cn)

    )

  )

AUXORCL =

  (DESCRIPTION =

    (ADDRESS_LIST =

      (ADDRESS = (PROTOCOL = TCP)(HOST = 172.30.2.56)(PORT = 1521))

    )

    (CONNECT_DATA =

      (SERVICE_NAME = orcl.saci.com.cn)

    )

  )

5.3 修改源庫的tnsnames.ora 檔案,添加如下内容:

TARGETORCL =

  (DESCRIPTION =

    (ADDRESS_LIST =

      (ADDRESS = (PROTOCOL = TCP)(HOST = 172.30.2.40)(PORT = 1521))

    )

    (CONNECT_DATA =

      (SERVICE_NAME = orcl.saci.com.cn)

    )

  )

ORCL =

  (DESCRIPTION =

    (ADDRESS_LIST =

      (ADDRESS = (PROTOCOL = TCP)(HOST = 172.30.2.40)(PORT = 1521))

    )

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = orcl.saci.com.cn)

    )

  )

AUXORCL =

  (DESCRIPTION =

    (ADDRESS_LIST =

      (ADDRESS = (PROTOCOL = TCP)(HOST = 172.30.2.56)(PORT = 1521))

    )

    (CONNECT_DATA =

      (SERVICE_NAME = orcl.saci.com.cn)

    )

  )

建議使用net manager 工具從界面來修改,這樣不容易出錯.

六. 将源庫的備份拷貝到輔助資料庫的相同位置

這裡有兩種方法,一種直接在輔助庫上建相同的目錄結構,在用SCP 指令把這些備份檔案copy過去,但是這樣會占用大量的網絡資源。還有一種就是建好目錄結構後用NFS直接mount上去,我這裡的實驗是在區域網路環境中,在這裡我采用前一種方法。

6.1 在輔助庫上建相同的備份目錄結構

因為我們在源庫上備份是備份到/u02/backup目錄中的,是以我們在輔助庫上也建這個目錄

# mkdir -p /u02/backup

# chown oracle:oinstall /u02/backup

# chmod 775 /u02/backup

6.2 利用scp拷貝目标資料庫備份集到輔助資料庫

$ cd /u02/backup

$ scp [email protected]:/u02/backup/* .

Enter passphrase for key '/home/oracle/.ssh/id_rsa': 

ORCL_spfile_0im9ga4c_1_1_20110411                                    100%   96KB  96.0KB/s   00:00    

arch_0fm9ga48_1_1_20110411                                           100%   16MB  15.6MB/s   00:00    

arch_0gm9ga48_1_1_20110411                                           100% 2560     2.5KB/s   00:00    

ctl_file_0hm9ga4a_1_1_20110411                                       100% 7584KB   7.4MB/s   00:00    

orcl_0cm9ga44_1_1_20110411                                           100%  594MB  59.4MB/s   00:10    

orcl_0dm9ga44_1_1_20110411                                           100%  436MB  62.3MB/s   00:07   

$ mkdir -p /u01/app/oracle/flash_recovery_area/ORCL/autobackup/2011_04_11

$ cd /u01/app/oracle/flash_recovery_area/ORCL/autobackup/2011_04_11                                  

$ scp [email protected]:/u01/app/oracle/flash_recovery_area/ORCL/autobackup/2011_04_11/o1_mf_s_748169351_6t61pqbg_.bkp .

Enter passphrase for key '/home/oracle/.ssh/id_rsa': 

o1_mf_s_748169351_6t61pqbg_.bkp                                                                                                      100% 7616KB   7.4MB/s   00:00    

$ scp [email protected]:/u01/app/oracle/flash_recovery_area/ORCL/autobackup/2011_04_11/o1_mf_s_748169357_6t61px9v_.bkp .

Enter passphrase for key '/home/oracle/.ssh/id_rsa': 

o1_mf_s_748169357_6t61px9v_.bkp                                                                                                      100% 7616KB   7.4MB/s   00:00    

$ ls

o1_mf_s_748169351_6t61pqbg_.bkp  o1_mf_s_748169357_6t61px9v_.bkp

七.啟動輔助庫至nomount 狀态,注意使用pfile參數啟動

$ sqlplus /nolog

SQL*Plus: Release 11.2.0.1.0 Production on Mon Apr 11 09:20:36 2011

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

SQL> conn /as sysdba

Connected to an idle instance.

SQL> startup nomount pfile=?/dbs/initorcl.ora

ORACLE instance started.

Total System Global Area 6847938560 bytes

Fixed Size                  2219808 bytes

Variable Size            3539992800 bytes

Database Buffers         3288334336 bytes

Redo Buffers               17391616 bytes

SQL> quit   -- 啟動後就退出session,因為在duplicata的時候不能有session連接配接

Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

八.RMAN 連接配接到目标執行個體和輔助執行個體,運作duplicate 指令複制資料庫

$ rman target sys/[email protected] auxiliary sys/[email protected];

Recovery Manager: Release 11.2.0.1.0 - Production on Mon Apr 11 09:23:14 2011

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

connected to target database: ORCL (DBID=1275959622)

connected to auxiliary database: ORCL (not mounted)

RMAN> duplicate target database to orcl nofilenamecheck

2> logfile

3> '/u01/app/oracle/oradata/orcl/redo01.dbf' size 50m,

4> '/u01/app/oracle/oradata/orcl/redo02.dbf' size 50m,

5> '/u01/app/oracle/oradata/orcl/redo03.dbf' size 50m;

Starting Duplicate Db at 11-APR-11

using target database control file instead of recovery catalog

allocated channel: ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: SID=63 device type=DISK

contents of Memory Script:

{

   sql clone "create spfile from memory";

}

executing Memory Script

sql statement: create spfile from memory

contents of Memory Script:

{

   shutdown clone immediate;

   startup clone nomount;

   -- 如果此時,輔助執行個體上有session連在上面,将一直等到session退出才能執行,如果等了很長時間還沒有執行,不妨檢查一下,有沒有session連在資料庫上。

}

executing Memory Script

Oracle instance shut down

connected to auxiliary database (not started)

Oracle instance started

Total System Global Area    6847938560 bytes

Fixed Size                     2219808 bytes

Variable Size               3556770016 bytes

Database Buffers            3271557120 bytes

Redo Buffers                  17391616 bytes

contents of Memory Script:

{

   sql clone "alter system set  db_name = 

 ''ORCL'' comment=

 ''Modified by RMAN duplicate'' scope=spfile";

   sql clone "alter system set  db_unique_name = 

 ''ORCL'' 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 =  ''ORCL'' comment= ''Modified by RMAN duplicate'' scope=spfile

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

Oracle instance shut down

Oracle instance started

Total System Global Area    6847938560 bytes

Fixed Size                     2219808 bytes

Variable Size               3556770016 bytes

Database Buffers            3271557120 bytes

Redo Buffers                  17391616 bytes

Starting restore at 11-APR-11

allocated channel: ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: SID=63 device type=DISK

channel ORA_AUX_DISK_1: starting datafile backup set restore  

-- 開始restore 資料檔案

channel ORA_AUX_DISK_1: restoring control file

channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/ORCL/autobackup/2011_04_11/o1_mf_s_748169357_6t61px9v_.bkp

channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/flash_recovery_area/ORCL/autobackup/2011_04_11/o1_mf_s_748169357_6t61px9v_.bkp tag=TAG20110411T084917

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/orcl/control01.ctl

output file name=/u01/app/oracle/flash_recovery_area/orcl/control02.ctl

Finished restore at 11-APR-11

database mounted

contents of Memory Script:

{

   set until scn  1081833;

   set newname for datafile  1 to 

 "/u01/app/oracle/oradata/orcl/system01.dbf";

   set newname for datafile  2 to 

 "/u01/app/oracle/oradata/orcl/sysaux01.dbf";

   set newname for datafile  3 to 

 "/u01/app/oracle/oradata/orcl/undotbs01.dbf";

   set newname for datafile  4 to 

 "/u01/app/oracle/oradata/orcl/users01.dbf";

   set newname for datafile  5 to 

 "/u01/app/oracle/oradata/orcl/example01.dbf";

   restore

   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

Starting restore at 11-APR-11

using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backup set restore

channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set

channel ORA_AUX_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/orcl/system01.dbf

channel ORA_AUX_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/orcl/users01.dbf

channel ORA_AUX_DISK_1: reading from backup piece /u02/backup/orcl_0cm9ga44_1_1_20110411

channel ORA_AUX_DISK_1: piece handle=/u02/backup/orcl_0cm9ga44_1_1_20110411 tag=ORCL_HOT_DB_BK

channel ORA_AUX_DISK_1: restored backup piece 1

channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03

channel ORA_AUX_DISK_1: starting datafile backup set restore

channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set

channel ORA_AUX_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/orcl/sysaux01.dbf

channel ORA_AUX_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/orcl/undotbs01.dbf

channel ORA_AUX_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/orcl/example01.dbf

channel ORA_AUX_DISK_1: reading from backup piece /u02/backup/orcl_0dm9ga44_1_1_20110411

channel ORA_AUX_DISK_1: piece handle=/u02/backup/orcl_0dm9ga44_1_1_20110411 tag=ORCL_HOT_DB_BK

channel ORA_AUX_DISK_1: restored backup piece 1

channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03

Finished restore at 11-APR-11

contents of Memory Script:

{

   switch clone datafile all;

}

executing Memory Script

datafile 1 switched to datafile copy

input datafile copy RECID=3 STAMP=748171541 file name=/u01/app/oracle/oradata/orcl/system01.dbf

datafile 2 switched to datafile copy

input datafile copy RECID=4 STAMP=748171541 file name=/u01/app/oracle/oradata/orcl/sysaux01.dbf

datafile 3 switched to datafile copy

input datafile copy RECID=5 STAMP=748171541 file name=/u01/app/oracle/oradata/orcl/undotbs01.dbf

datafile 4 switched to datafile copy

input datafile copy RECID=6 STAMP=748171541 file name=/u01/app/oracle/oradata/orcl/users01.dbf

datafile 5 switched to datafile copy

input datafile copy RECID=7 STAMP=748171541 file name=/u01/app/oracle/oradata/orcl/example01.dbf

contents of Memory Script:

{

   set until scn  1081833;

   recover

   clone database

    delete archivelog

   ;

}

executing Memory Script

executing command: SET until clause

Starting recover at 11-APR-11

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=9

channel ORA_AUX_DISK_1: reading from backup piece /u02/backup/arch_0fm9ga48_1_1_20110411

channel ORA_AUX_DISK_1: piece handle=/u02/backup/arch_0fm9ga48_1_1_20110411 tag=TAG20110411T084912

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/flash_recovery_area/ORCL/archivelog/2011_04_11/o1_mf_1_9_6t63v6q8_.arc thread=1 sequence=9

channel clone_default: deleting archived log(s)

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_04_11/o1_mf_1_9_6t63v6q8_.arc RECID=6 STAMP=748171542

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=10

channel ORA_AUX_DISK_1: reading from backup piece /u02/backup/arch_0gm9ga48_1_1_20110411

channel ORA_AUX_DISK_1: piece handle=/u02/backup/arch_0gm9ga48_1_1_20110411 tag=TAG20110411T084912

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/flash_recovery_area/ORCL/archivelog/2011_04_11/o1_mf_1_10_6t63v7ys_.arc thread=1 sequence=10

channel clone_default: deleting archived log(s)

archived log file name=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_04_11/o1_mf_1_10_6t63v7ys_.arc RECID=7 STAMP=748171543

media recovery complete, elapsed time: 00:00:00

Finished recover at 11-APR-11

contents of Memory Script:

{

   shutdown clone immediate;

   startup clone nomount;

   sql clone "alter system set  db_name = 

 ''ORCL'' 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    6847938560 bytes

Fixed Size                     2219808 bytes

Variable Size               3556770016 bytes

Database Buffers            3271557120 bytes

Redo Buffers                  17391616 bytes

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

Fixed Size                     2219808 bytes

Variable Size               3556770016 bytes

Database Buffers            3271557120 bytes

Redo Buffers                  17391616 bytes

sql statement: CREATE CONTROLFILE REUSE SET DATABASE "ORCL" RESETLOGS ARCHIVELOG -- 建立新的控制檔案

  MAXLOGFILES     16

  MAXLOGMEMBERS      3

  MAXDATAFILES      100

  MAXINSTANCES     8

  MAXLOGHISTORY      292

 LOGFILE

  GROUP  1 '/u01/app/oracle/oradata/orcl/redo01.dbf' SIZE 50 M ,

  GROUP  2 '/u01/app/oracle/oradata/orcl/redo02.dbf' SIZE 50 M ,

  GROUP  3 '/u01/app/oracle/oradata/orcl/redo03.dbf' SIZE 50 M 

 DATAFILE

  '/u01/app/oracle/oradata/orcl/system01.dbf'

 CHARACTER SET AL32UTF8

contents of Memory Script:

{

   set newname for tempfile  1 to 

 "/u01/app/oracle/oradata/orcl/temp01.dbf";

   switch clone tempfile all;

   catalog clone datafilecopy  "/u01/app/oracle/oradata/orcl/sysaux01.dbf", 

 "/u01/app/oracle/oradata/orcl/undotbs01.dbf", 

 "/u01/app/oracle/oradata/orcl/users01.dbf", 

 "/u01/app/oracle/oradata/orcl/example01.dbf";

   switch clone datafile all;

}

executing Memory Script

executing command: SET NEWNAME

renamed tempfile 1 to /u01/app/oracle/oradata/orcl/temp01.dbf in control file

cataloged datafile copy

datafile copy file name=/u01/app/oracle/oradata/orcl/sysaux01.dbf RECID=1 STAMP=748171563

cataloged datafile copy

datafile copy file name=/u01/app/oracle/oradata/orcl/undotbs01.dbf RECID=2 STAMP=748171563

cataloged datafile copy

datafile copy file name=/u01/app/oracle/oradata/orcl/users01.dbf RECID=3 STAMP=748171563

cataloged datafile copy

datafile copy file name=/u01/app/oracle/oradata/orcl/example01.dbf RECID=4 STAMP=748171563

datafile 2 switched to datafile copy

input datafile copy RECID=1 STAMP=748171563 file name=/u01/app/oracle/oradata/orcl/sysaux01.dbf

datafile 3 switched to datafile copy

input datafile copy RECID=2 STAMP=748171563 file name=/u01/app/oracle/oradata/orcl/undotbs01.dbf

datafile 4 switched to datafile copy

input datafile copy RECID=3 STAMP=748171563 file name=/u01/app/oracle/oradata/orcl/users01.dbf

datafile 5 switched to datafile copy

input datafile copy RECID=4 STAMP=748171563 file name=/u01/app/oracle/oradata/orcl/example01.dbf

contents of Memory Script:

{

   Alter clone database open resetlogs;

}

executing Memory Script

database opened

Finished Duplicate Db at 11-APR-11

RMAN> 

注明: 這裡地方有2個地方需要說明:

(1) nofilenamecheck 參數: 

如果在複制時,位置不同時,我們會用參數db_file_name_convert 對檔案位置進行轉換。 但是在這個複制示例中我們用的是相同的位置。 是以這裡必須加上nofilenamecheck參數。 該參數通知複制操作不必在執行還原操作前确認檔案名是不同的。如果沒有指定nofilenamecheck參數,rman會給出如下錯誤:

RMAN-05001: auxiliary filename /u01/app/oracle/oradata/orcl/example01.dbf conflicts with a file used by the target database

RMAN-05001: auxiliary filename /u01/app/oracle/oradata/orcl/users01.dbf conflicts with a file used by the target database

(2) logfile 參數:

在完成複制程序并執行最後一條open resetlogs指令時,RMAN 必須為輔助資料庫建構全新的日志檔案。 如上面指令所示,我們可以在duplicate 指令中指定logfile參數,并指定使用的日志檔案的大小,數目和位置。 還可以在pfile裡指定log_file_name_convert 參數來進行轉換。 這種方法相對而言要簡單一點。 

九.建立spfile,并驗證資料庫

通過上面8步的操作,複制操作已經完成,我們現在建立一個spfile。

SQL> create spfile from pfile='/u01/app/oracle/product/11.2.0/db_1/dbs/initorcl.ora';

File created.

SQL> select name from v$database;

NAME

---------

ORCL

SQL> select tablespace_name,file_name from dba_data_files;

TABLESPACE_NAME    FILE_NAME

------------------ --------------------------------------------------

SYSTEM             /u01/app/oracle/oradata/orcl/system01.dbf

SYSAUX             /u01/app/oracle/oradata/orcl/sysaux01.dbf

UNDOTBS1           /u01/app/oracle/oradata/orcl/undotbs01.dbf

USERS              /u01/app/oracle/oradata/orcl/users01.dbf

EXAMPLE            /u01/app/oracle/oradata/orcl/example01.dbf

到此,Oracle 11g 異機duplicate資料庫實驗完成。