ITPub博客

首页 > 数据库 > Oracle > 使用RMAN在ASM和文件系统之间拷贝数据

使用RMAN在ASM和文件系统之间拷贝数据

原创 Oracle 作者:尛样儿 时间:2013-11-06 17:19:35 0 删除 编辑

        这篇文章简单讨论如何利用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
http://docs.oracle.com/cd/B19306_01/backup.102/b14191/dbxptrn.htm#CHDCFCIB

使用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/23135684/viewspace-775905/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
Oracle数据库管理员,Oracle数据库系统构架员;2012年7月出版《构建最高可用Oracle数据库系统:Oracle 11gR2 RAC管理、维护与性能优化》一书;Oracle 10g OCM。

注册时间:2010-01-05

  • 博文量
    483
  • 访问量
    5314179