使用RMAN在ASM和檔案系統之間複製資料

路途中的人2012發表於2017-05-23

        這篇文章簡單討論如何利用RMAN工具中的backup as copy、copy、convert命令在ASM和檔案系統之間複製資料。

一.從ASM複製資料到檔案系統。

1).複製資料檔案:

RMAN> backup as copy datafile '+data01/orcl/datafile/USERS.263.829729669' format '/u01/app/oracle/bak/user01.dbf';


Starting backup at 2013-10-28 02:16:59
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=18 instance=orcl1 device type=DISK
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004 name=+DATA01/orcl/datafile/users.263.829729669
output file name=/u01/app/oracle/bak/user01.dbf tag=TAG20131028T021700 RECID=1 STAMP=829966621
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:00
Finished backup at 2013-10-28 02:17:01

        format指定複製的目的地。

2).複製控制檔案:

RMAN> backup as copy current controlfile  format '/u01/app/oracle/bak/control01.ctl';


Starting backup at 2013-10-28 02:19:24
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
copying current control file
output file name=/u01/app/oracle/bak/control01.ctl tag=TAG20131028T021925 RECID=2 STAMP=829966769
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
Finished backup at 2013-10-28 02:19:31

3).複製引數檔案:

RMAN> backup as copy spfile format '/u01/app/oracle/bak/spfileorcl.ora';


Starting backup at 2013-10-28 02:19:50
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 2013-10-28 02:19:50
channel ORA_DISK_1: finished piece 1 at 2013-10-28 02:19:51
piece handle=/u01/app/oracle/bak/spfileorcl.ora tag=TAG20131028T021950 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2013-10-28 02:19:51

4).複製資訊會在catalog中進行記錄:

RMAN> list copy;


List of Datafile Copies
=======================

Key     File S Completion Time     Ckp SCN    Ckp Time           
------- ---- - ------------------- ---------- -------------------
1       4    A 2013-10-28 02:17:01 1751169    2013-10-28 02:14:28
        Name: /u01/app/oracle/bak/user01.dbf
        Tag: TAG20131028T021700

List of Control File Copies
===========================

Key     S Completion Time     Ckp SCN    Ckp Time           
------- - ------------------- ---------- -------------------
2       A 2013-10-28 02:19:29 1751169    2013-10-28 02:14:28
        Name: /u01/app/oracle/bak/control01.ctl
        Tag: TAG20131028T021925

        spfile複製資訊沒有在catalog中留下記錄。

5).使用convert命令同樣可以完成複製:

RMAN> convert datafile '+data01/orcl/datafile/USERS.263.829729669' format '/u01/app/oracle/bak/user02.dbf';


Starting conversion at target at 2013-10-28 02:25:46
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile conversion
input file name=+DATA01/orcl/datafile/users.263.829729669
converted datafile=/u01/app/oracle/bak/user02.dbf
channel ORA_DISK_1: datafile conversion complete, elapsed time: 00:00:01
Finished conversion at target at 2013-10-28 02:25:47

RMAN> list datafilecopy all;

List of Datafile Copies
=======================

Key     File S Completion Time     Ckp SCN    Ckp Time           
------- ---- - ------------------- ---------- -------------------
1       4    A 2013-10-28 02:17:01 1751169    2013-10-28 02:14:28
        Name: /u01/app/oracle/bak/user01.dbf
        Tag: TAG20131028T021700

        使用convert命令複製資料檔案,不會在catalog中留下記錄,但該命令僅能用於資料檔案的複製。

6).複製歸檔重做日誌檔案:

下面三條複製命令效果是相同的:
RMAN> backup as copy archivelog sequence 88 thread 1 format '/u01/app/oracle/bak/thread_1_seq_88.357.829964339';

Starting backup at 2013-10-28 03:04:24
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log copy
input archived log thread=1 sequence=88 RECID=90 STAMP=829964343
output file name=/u01/app/oracle/bak/thread_1_seq_88.357.829964339 RECID=91 STAMP=829969466
channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:03
Finished backup at 2013-10-28 03:04:27

RMAN> backup as copy archivelog from sequence 88 thread 1 format '+FRA01';

Starting backup at 2013-10-28 03:08:07
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log copy
input archived log thread=1 sequence=88 RECID=92 STAMP=829969656
output file name=+FRA01/orcl/archivelog/2013_10_28/thread_1_seq_88.268.829969687 RECID=93 STAMP=829969689
channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:03
Finished backup at 2013-10-28 03:08:10

RMAN> copy archivelog '+DATA01/orcl/archivelog/2013_10_28/thread_1_seq_87.354.829964133' to '/u01/app/oracle/bak/thread_1_seq_87.354.829964133';

Starting backup at 2013-10-28 03:17:11
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log copy
input archived log thread=1 sequence=87 RECID=87 STAMP=829964135
output file name=/u01/app/oracle/bak/thread_1_seq_87.354.829964133 RECID=96 STAMP=829970233
channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:03
Finished backup at 2013-10-28 03:17:15

        可以直接使用copy命令對支援的檔案型別進行複製,注意使用RMAN的copy命令是透過to指定目的地,而不是透過format指定目的地。

7).複製備份檔案:

RMAN> backup datafile 4 format '+FRA01';

Starting backup at 2013-10-28 03:38:51
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00004 name=+DATA01/orcl/datafile/users.263.829729669
channel ORA_DISK_1: starting piece 1 at 2013-10-28 03:38:52
channel ORA_DISK_1: finished piece 1 at 2013-10-28 03:38:53
piece handle=+FRA01/orcl/backupset/2013_10_28/nnndf0_tag20131028t033852_0.269.829971533 tag=TAG20131028T033852 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2013-10-28 03:38:53

RMAN> list backup of datafile 4;

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

BS Key  Type LV Size       Device Type Elapsed Time Completion Time    
------- ---- -- ---------- ----------- ------------ -------------------
3       Full    368.00K    DISK        00:00:00     2013-10-28 03:38:52
        BP Key: 4   Status: AVAILABLE  Compressed: NO  Tag: TAG20131028T033852
        Piece Name: +FRA01/orcl/backupset/2013_10_28/nnndf0_tag20131028t033852_0.269.829971533
  List of Datafiles in backup set 3
  File LV Type Ckp SCN    Ckp Time            Name
  ---- -- ---- ---------- ------------------- ----
  4       Full 1751169    2013-10-28 02:14:28 +DATA01/orcl/datafile/users.263.829729669

RMAN> backup as copy backupset 3 format '/u01/app/oracle/bak/backupdatafil4.rman';

Starting backup at 2013-10-28 03:39:29
using channel ORA_DISK_1
channel ORA_DISK_1: input backup set: count=19, stamp=829971532, piece=1
channel ORA_DISK_1: starting piece 1 at 2013-10-28 03:39:29
channel ORA_DISK_1: backup piece +FRA01/orcl/backupset/2013_10_28/nnndf0_tag20131028t033852_0.269.829971533
piece handle=/u01/app/oracle/bak/backupdatafil4.rman comment=NONE
channel ORA_DISK_1: finished piece 1 at 2013-10-28 03:39:30
channel ORA_DISK_1: backup piece complete, elapsed time: 00:00:01
Finished backup at 2013-10-28 03:39:30

二.從檔案系統複製資料到ASM。

1).複製資料檔案到ASM:

RMAN> backup as copy datafile '/u01/app/oracle/bak/user02.dbf' format '+FRA01';

Starting backup at 2013-10-28 02:31:31
using channel ORA_DISK_1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of backup command at 10/28/2013 02:31:31
RMAN-20201: datafile not found in the recovery catalog
RMAN-06010: error while looking up datafile: /u01/app/oracle/bak/user02.dbf

RMAN> backup as copy datafilecopy '/u01/app/oracle/bak/user02.dbf' format '+FRA01';

Starting backup at 2013-10-28 02:34:20
using channel ORA_DISK_1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of backup command at 10/28/2013 02:34:20
RMAN-20230: datafile copy not found in the repository
RMAN-06015: error while looking up datafile copy name: /u01/app/oracle/bak/user02.dbf

        user02.dbf是上面透過convert datafile複製出來的,沒有在catalog中留下記錄,這裡提示在catalog中找不到該檔案,執行以下命令收集該檔案:

RMAN> catalog datafilecopy '/u01/app/oracle/bak/user02.dbf';

cataloged datafile copy
datafile copy file name=/u01/app/oracle/bak/user02.dbf RECID=7 STAMP=829967677

再次執行複製命令:

RMAN> backup as copy datafilecopy '/u01/app/oracle/bak/user02.dbf' format '+FRA01';

Starting backup at 2013-10-28 02:34:40
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input is copy of datafile 00004: /u01/app/oracle/bak/user02.dbf
output file name=+FRA01/orcl/datafile/users.263.829967681 RECID=8 STAMP=829967680
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 2013-10-28 02:34:41

        成功完成資料檔案從檔案系統到ASM的複製。

2).複製控制檔案到ASM中:

        對控制檔案的複製道理相同,注意backup as copy後面關鍵字的變化:

RMAN> backup as copy controlfilecopy '/u01/app/oracle/bak/control02.ctl' format '+FRA01';

Starting backup at 2013-10-28 02:37:54
using channel ORA_DISK_1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of backup command at 10/28/2013 02:37:54
RMAN-20220: control file copy not found in the repository
RMAN-06090: error while looking up control file copy: /u01/app/oracle/bak/control02.ctl

RMAN> catalog controlfilecopy '/u01/app/oracle/bak/control02.ctl';

cataloged control file copy
control file copy file name=/u01/app/oracle/bak/control02.ctl RECID=10 STAMP=829967892

RMAN> backup as copy controlfilecopy '/u01/app/oracle/bak/control02.ctl' format '+FRA01';

Starting backup at 2013-10-28 02:38:17
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input control file copy name=/u01/app/oracle/bak/control02.ctl
output file name=+FRA01/orcl/controlfile/backup.265.829967899 tag=TAG20131028T021925 RECID=11 STAMP=829967899
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 2013-10-28 02:38:19

3).使用convert命令複製資料檔案到ASM中:

        使用convert命令同樣可以完成將資料檔案複製到ASM中,並且這不需要在catalog中有記錄:

RMAN> convert datafile '/u01/app/oracle/bak/user03.dbf' format '+FRA01';

Starting conversion at target at 2013-10-28 02:42:32
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile conversion
input file name=/u01/app/oracle/bak/user03.dbf
converted datafile=+FRA01/orcl/datafile/users.266.829968153
channel ORA_DISK_1: datafile conversion complete, elapsed time: 00:00:01
Finished conversion at target at 2013-10-28 02:42:33

        但這僅限於對資料檔案的操作。

4).複製歸檔重做日誌檔案:

        在系統層面執行了一下複製命令:
$cp /u01/app/oracle/bak/thread_1_seq_88.357.829964339 /u01/app/oracle/bak/archivelog_1_seq88.arc

RMAN> copy archivelog '/u01/app/oracle/bak/archivelog_1_seq88.arc' to '+FRA01';

Starting backup at 2013-10-28 03:10:08
using channel ORA_DISK_1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of backup command at 10/28/2013 03:10:08
RMAN-20240: archived log not found in the repository
RMAN-06046: archived log name: /u01/app/oracle/bak/archivelog_1_seq88.arc

RMAN> catalog start with '/u01/app/oracle/bak';

searching for all files that match the pattern /u01/app/oracle/bak

List of Files Unknown to the Database
=====================================
File Name: /u01/app/oracle/bak/user03.dbf
File Name: /u01/app/oracle/bak/archivelog_1_seq88.arc

Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: /u01/app/oracle/bak/user03.dbf
File Name: /u01/app/oracle/bak/archivelog_1_seq88.arc

RMAN> list archivelog sequence 88 thread 1;

List of Archived Log Copies for database with db_unique_name ORCL
=====================================================================

Key     Thrd Seq     S Low Time           
------- ---- ------- - -------------------
94      1    88      A 2013-10-28 01:35:30
............
        Name: /u01/app/oracle/bak/archivelog_1_seq88.arc

RMAN> copy archivelog '/u01/app/oracle/bak/archivelog_1_seq88.arc' to '+FRA01';

Starting backup at 2013-10-28 03:12:19
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log copy
input archived log thread=1 sequence=88 RECID=94 STAMP=829969853
output file name=+FRA01/orcl/archivelog/2013_10_28/thread_1_seq_88.267.829969941 RECID=95 STAMP=829969940
channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:01
Finished backup at 2013-10-28 03:12:21

5).複製備份檔案:

RMAN> backup datafile 4 format '/u01/app/oracle/bak/backupdatafile4.bak';


Starting backup at 2013-10-28 03:31:33
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00004 name=+DATA01/orcl/datafile/users.263.829729669
channel ORA_DISK_1: starting piece 1 at 2013-10-28 03:31:33
channel ORA_DISK_1: finished piece 1 at 2013-10-28 03:31:34
piece handle=/u01/app/oracle/bak/backupdatafile4.bak tag=TAG20131028T033133 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2013-10-28 03:31:34

RMAN> list backup of datafile 4;

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

BS Key  Type LV Size       Device Type Elapsed Time Completion Time    
------- ---- -- ---------- ----------- ------------ -------------------
2       Full    368.00K    DISK        00:00:01     2013-10-28 03:31:34
        BP Key: 2   Status: AVAILABLE  Compressed: NO  Tag: TAG20131028T033133
        Piece Name: /u01/app/oracle/bak/backupdatafile4.bak
  List of Datafiles in backup set 2
  File LV Type Ckp SCN    Ckp Time            Name
  ---- -- ---- ---------- ------------------- ----
  4       Full 1751169    2013-10-28 02:14:28 +DATA01/orcl/datafile/users.263.829729669

RMAN> backup as copy backupset 2 format '+FRA01';

Starting backup at 2013-10-28 03:33:25
using channel ORA_DISK_1
channel ORA_DISK_1: input backup set: count=18, stamp=829971093, piece=1
channel ORA_DISK_1: starting piece 1 at 2013-10-28 03:33:26
channel ORA_DISK_1: backup piece /u01/app/oracle/bak/backupdatafile4.bak
piece handle=+FRA01/orcl/backupset/2013_10_28/nnndf0_0.269.829971207 comment=NONE
channel ORA_DISK_1: finished piece 1 at 2013-10-28 03:33:27
channel ORA_DISK_1: backup piece complete, elapsed time: 00:00:01
Finished backup at 2013-10-28 03:33:27


總結:
       1).Oracle Database 10g中,在檔案系統和ASM磁碟組之間複製初始化引數檔案、控制檔案、資料檔案、歸檔日誌檔案比較容易,但遷移Redo Log檔案較困難,可以透過為日誌組新增成員、刪除成員的手段達到遷移的目的,例如:

SQL> startup mount
ORACLE 例程已經啟動。

Total System Global Area  535662592 bytes
Fixed Size                  1385840 bytes
Variable Size             327158416 bytes
Database Buffers          201326592 bytes
Redo Buffers                5791744 bytes
資料庫裝載完畢。
SQL> select group#,member from v$logfile;

    GROUP#
----------
MEMBER
--------------------------------------------------------------------------------
         3
E:\APP\ORADATA\TEST\REDO03.LOG

         2
E:\APP\ORADATA\TEST\REDO02.LOG

         1
E:\APP\ORADATA\TEST\REDO01.LOG

SQL> alter database add logfile member 'E:\APP\ORADATA\TEST\REDO0101.LOG' to group 1;

資料庫已更改。

SQL> alter database add logfile member 'E:\APP\ORADATA\TEST\REDO0201.LOG' to group 2;

資料庫已更改。

SQL> alter database add logfile member 'E:\APP\ORADATA\TEST\REDO0301.LOG' to group 3;

資料庫已更改。

   資料庫在MOUNT狀態即可完成日誌組成員的新增,但是在OPEN RESETLOGS的時候必須要確保所有日誌組成員的全路徑目錄都存在才能正常的開啟,資料庫開啟之後可以正常的DROP日誌組成員,如果是非CURRENT日誌組也可以在MOUNT狀態下DROP日誌成員,但CURRENT日誌組在任何情況下都不能DROP成員。

       2).使用RMAN在ASM和檔案系統之間複製資料,只支援Oracle資料庫自身的檔案型別,包括:資料檔案、控制檔案、引數檔案、重做日誌檔案、備份檔案、資料檔案複製、控制檔案複製等,其它第三方的檔案是無法透過RMAN複製到ASM中的。

       3).使用RMAN的backup as copy、copy命令在ASM和檔案系統之間複製資料,要求複製的物件必須在catalog中有記錄,沒有記錄必須使用catalog datafilecopy|controlfilecopy|catalog start with|...命令進行採集。
       4).除了使用RMAN的backup as copy、copy命令在ASM和檔案系統之間複製資料,還可以使用convert命令在ASM和檔案系統之間複製資料,但該命令僅限對資料檔案進行複製。
       5).使用RMAN的backup as copy、copy命令和convert命令進行複製還有一點區別在於,backup as copy和copy命令會在catalog中留下複製記錄,convert命令不會在catalog中留下任何記錄。
       6).透過RMAN的backup as copy、copy、convert命令進行複製主要用於資料檔案和重做日誌檔案的複製,引數檔案可以使用create spfile和restore命令,控制檔案可以使用restore命令進行雙向的複製。
       7).為了簡化操作命令可以直接使用RMAN的copy命令複製支援的資料檔案型別。


有關使用RMAN的CONVERT命令在ASM和非ASM儲存之間複製資料的詳情可以參考如下文件:
Using RMAN CONVERT to Copy Files Between ASM和Non-ASM Storage


使用DBMS_FILE_TRANSFER包在ASM和檔案系統之間傳遞資料》:http://blog.itpub.net/23135684/viewspace-662098/

這裡再簡單提一下透過ASMCMD cp命令在ASM和檔案系統之間複製資料:

    從檔案系統複製檔案到ASM磁碟組,例如,將/u01/bak/onlinelog/group_1.261.786500755檔案複製到+DBFILE1/ractest/onlinelog/目錄下。

首先使用ASMCMD的mkdir命令將+DBFILE1/ractest/onlinelog/目錄結構建立好。

之後執行下面的cp命令:

ASMCMD [+] > cp /u01/bak/onlinelog/group_1.261.786500755 +DBFILE1/ractest/onlinelog/group_1.261.786500755
copying /u01/bak/onlinelog/group_1.261.786500755 -> +DBFILE1/ractest/onlinelog/group_1.261.786500755
ASMCMD-08016: copy source->'/u01/bak/onlinelog/group_1.261.786500755' and target->'+DBFILE1/ractest/onlinelog/group_1.261.786500755' failed
ORA-15056: additional error message
ORA-15046: ASM file name '+DBFILE1/ractest/onlinelog/group_1.261.786500755' is not in single-file creation form
ORA-06512: at "SYS.X$DBMS_DISKGROUP", line 410
ORA-06512: at line 3 (DBD ERROR: OCIStmtExecute)

由於ASM是OMF自動化管理及命名,所以不能為redo檔案指定group_1.261.786500755自動命名規則的名稱,指定一個唯一的檔名:

ASMCMD [+] > cp /u01/bak/onlinelog/group_1.261.786500755 +DBFILE1/ractest/onlinelog/redo101.log
copying /u01/bak/onlinelog/group_1.261.786500755 -> +DBFILE1/ractest/onlinelog/redo101.log

對引數檔案、控制檔案等的複製也需要遵守這樣的規則。
從ASM磁碟組複製到檔案系統較簡單,在ASMCMD執行help cp檢視幫助。

    參考文章:RAC中誤將資料檔案建立在本地盤時的修正》:https://blogs.oracle.com/Database4CN/entry/rac%E4%B8%AD%E8%AF%AF%E5%B0%86%E6%95%B0%E6%8D%AE%E6%96%87%E4%BB%B6%E5%88%9B%E5%BB%BA%E5%9C%A8%E6%9C%AC%E5%9C%B0%E7%9B%98%E6%97%B6%E7%9A%84%E4%BF%AE%E6%AD%A3

--end--

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

相關文章