您的位置:首页 > 运维架构

使用switch copy命令对普通文件和ASM文件的相互迁移

2018-03-20 14:54 302 查看
创建测试用的表空间及数据SYS@racdb3>create tablespace test_tbs datafile '/u01/app/oracle/test_tbs01.dbf' size 10M ;

Tablespace created.

SYS@racdb3>create table test_tbs_t1 (id number) tablespace test_tbs;

Table created.

SYS@racdb3>insert into test_tbs_t1 values(1);

1 row created.

SYS@racdb3>commit;

Commit complete.

SYS@racdb3>进行备份backup as copy tablespace test_tbs format '+DATA';

[oracle@host03 ~]$ rman target /

Recovery Manager: Release 11.2.0.4.0 - Production on Tue Mar 20 14:36:04 2018

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

connected to target database: RACDB (DBID=960841425)

RMAN> backup as copy tablespace test_tbs format '+DATA';

Starting backup at 20-MAR-18
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=67 instance=racdb3 device type=DISK
channel ORA_DISK_1: starting datafile copy
input datafile file number=00008 name=/u01/app/oracle/test_tbs01.dbf
output file name=+DATA/racdb/datafile/test_tbs.701.971274979 tag=TAG20180320T143618 RECID=3 STAMP=971274979
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 20-MAR-18

Starting Control File and SPFILE Autobackup at 20-MAR-18
piece handle=/home/oracle/control_c-960841425-20180320-00 comment=NONE
Finished Control File and SPFILE Autobackup at 20-MAR-18表空间offlinealter tablespace test_tbs offline;

SYS@racdb3>alter tablespace test_tbs offline;
进行切换,并查看状态switch tablespace test_tbs to copy;
RMAN> switch tablespace test_tbs to copy;

datafile 8 switched to datafile copy "+DATA/racdb/datafile/test_tbs.701.971274979"

SYS@racdb3>recover tablespace test_tbs;
Media recovery complete.
SYS@racdb3>alter tablespace test_tbs online;

Tablespace altered.

SYS@racdb3>

SYS@racdb3>select file_name from dba_data_files;

FILE_NAME
--------------------------------------------------------------------------------
+DATA/racdb/undotbs01.dbf
+DATA/racdb/users01.dbf
+DATA/racdb/sysaux01.dbf
+DATA/racdb/system01.dbf
+DATA/racdb/example01.dbf
+DATA/racdb/undotbs02.dbf
+DATA/racdb/datafile/abc.448.966705497
+DATA/racdb/datafile/test_tbs.701.971274979

8 rows selected.

SYS@racdb3>select * from test_tbs_t1;

ID
----------
1

SYS@racdb3>下面测试,将ASM上的数据文件,迁移到普通路径上
创建测试数据create tablespace asm_tbs datafile '+DATA' size 10M;
create table asm_t1(id number) tablespace asm_tbs;
insert into asm_t1 values(2);
commit;

SYS@racdb3>create tablespace asm_tbs datafile '+DATA' size 10M;

Tablespace created.

SYS@racdb3>create table asm_t1(id number) tablespace asm_tbs;

Table created.

SYS@racdb3>insert into asm_t1 values(2);

1 row created.

SYS@racdb3>commit;

Commit complete.

SYS@racdb3>步骤如下:backup as copy tablespace asm_tbs format '/u01/app/oracle/asm_tbs.dbf' ;
alter tablespace asm_tbs offline;
switch tablespace asm_tbs to copy;
recover tablespace asm_tbs;
alter tablespace asm_tbs online;过程RMAN> backup as copy tablespace asm_tbs format '/u01/app/oracle/asm_tbs.dbf' ;

Starting backup at 20-MAR-18
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile file number=00009 name=+DATA/racdb/datafile/asm_tbs.702.971275499
output file name=/u01/app/oracle/asm_tbs.dbf tag=TAG20180320T144539 RECID=5 STAMP=971275541
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
Finished backup at 20-MAR-18

Starting Control File and SPFILE Autobackup at 20-MAR-18
piece handle=/home/oracle/control_c-960841425-20180320-01 comment=NONE
Finished Control File and SPFILE Autobackup at 20-MAR-18

RMAN>

RMAN> sql 'alter tablespace asm_tbs offline';

sql statement: alter tablespace asm_tbs offline

RMAN> switch tablespace asm_tbs to copy;

datafile 9 switched to datafile copy "/u01/app/oracle/asm_tbs.dbf"

RMAN> recover tablespace asm_tbs;

Starting recover at 20-MAR-18
using channel ORA_DISK_1

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

Finished recover at 20-MAR-18

RMAN> sql 'alter tablespace asm_tbs online';

sql statement: alter tablespace asm_tbs online

RMAN>

SYS@racdb3>select file_name from dba_data_files;

FILE_NAME
--------------------------------------------------------------------------------
+DATA/racdb/undotbs01.dbf
+DATA/racdb/users01.dbf
+DATA/racdb/sysaux01.dbf
+DATA/racdb/system01.dbf
+DATA/racdb/example01.dbf
+DATA/racdb/undotbs02.dbf
+DATA/racdb/datafile/abc.448.966705497
+DATA/racdb/datafile/test_tbs.701.971274979
/u01/app/oracle/asm_tbs.dbf

9 rows selected.

SYS@racdb3>
SYS@racdb3>select * from asm_t1;

ID
----------
2

SYS@racdb3>
end 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: