1. 完全关闭数据库。
2. 关闭数据库并修改服务器参数文件,以使用Oracle Managed Files (OMF)。
3. 编辑并执行以下RMAN 脚本:
STARTUP NOMOUNT;
RESTORE CONTROLFILE FROM '/u1/c1.ctl';
ALTER DATABASE MOUNT;
BACKUP AS COPY DATABASE FORMAT '+dgroup1';
SWITCH DATABASE TO COPY;
SQL "ALTER DATABASE RENAME '/u1/log1'TO '+dgroup1' ";
# Repeat RENAME command for all online redo log members
...
ALTER DATABASE OPEN RESETLOGS;
SQL "ALTER DATABASE TEMPFILE '/u1/temp1' DROP";
- 将数据库移植到ASM 存储区
由于ASM 文件无法通过正常的操作系统界面访问,因此RMAN 是复制ASM 文件的唯一途径。虽然由于表空间的历史原因,表空间中的文件既可以是ASM 文件,也可以
是非ASM 文件,但是RMAN 命令会将非ASM 文件移到ASM 磁盘组中。通过以下过程,可以将整个数据库移到ASM 磁盘组中:(假定你使用的是服务器参数文件。)
1. 使用V$CONTROLFILE和V$LOGFILE,获取当前控制文件和联机重做日志的文件名。
2. 像平常一样关闭数据库。按如下所述,修改数据库的服务器参数文件:
- 将必要的OMF 目标参数设置为所需的ASM 磁盘组。
- 删除CONTROL_FILES参数。
3. 编辑和运行RMAN 命令文件,这将备份数据库、将当前数据文件移到备份中并重命名联机重做日志。使用BACKUP AS COPY命令只能移动表空间或数据文件。
4. 删除旧的数据库文件。
注:如果创建一个OMF 控制文件,并且有一个服务器参数文件,则会在该服务器参数文件中创建一个CONTROL_FILES初始化参数条目。
- 将表空间移植到ASM 存储中
移植表空间,使其可以使用ASM 存储。
1. 使用SQL*Plus,以 SYSDBA 用户身份连接到数据库实例,然后创建一个名为TBSASMMIG 的新的表空间。此表空间应当只包含一个存储于文件系统中的10 MB
大小的文件(不使用ASM)。请确保连接的是 test0924(我本机的测试实例)实例,而不是ASM 实例。
2. 创建一个名为 T2、存储在新的表空间 TBSASMMIG 中的表。在 T2 中插入一行。 提交你所做的操作。
3. 将 TBSASMMIG 移植到ASM 存储中。完成操作后,请检查移植是否成功,并且该表空间中的表是否保持原样。
- sys@TEST0924> select FILE_NAME,TABLESPACE_NAME from dba_data_files;
- FILE_NAME TABLESPACE_NAME
- -------------------------------------------------- ------------------------------
- /u01/app/oracle/oradata/test0924/users01.dbf USERS
- /u01/app/oracle/oradata/test0924/sysaux01.dbf SYSAUX
- /u01/app/oracle/oradata/test0924/system01.dbf SYSTEM
- /u01/app/oracle/oradata/test0924/example01.dbf EXAMPLE
- /u01/app/oracle/oradata/test0924/undotbs01.dbf UNDOTBS1
- sys@TEST0924> create tablespace TBSASMMIG datafile '/u01/app/oracle/oradata/test0924/tbsasmmig01.dbf' size 10m;
- Tablespace created.
- sys@TEST0924> create table t2 (id number,name varchar2(20)) tablespace TBSASMMIG;
- Table created.
- sys@TEST0924> insert into t2 values (1,'a1');
- 1 row created.
- sys@TEST0924> commit;
- Commit complete.
- sys@TEST0924> select file_id,file_name,tablespace_name from dba_data_files;
- FILE_ID FILE_NAME TABLESPACE_NAME
- ---------- -------------------------------------------------- ------------------------------
- 4 /u01/app/oracle/oradata/test0924/users01.dbf USERS
- 3 /u01/app/oracle/oradata/test0924/tbsasmmig01.dbf TBSASMMIG
- 2 /u01/app/oracle/oradata/test0924/sysaux01.dbf SYSAUX
- 1 /u01/app/oracle/oradata/test0924/system01.dbf SYSTEM
- 5 /u01/app/oracle/oradata/test0924/example01.dbf EXAMPLE
- 9 /u01/app/oracle/oradata/test0924/undotbs01.dbf UNDOTBS1
- 6 rows selected.
- [oracle@rtest ~]$ rman target /
- Recovery Manager: Release 11.2.0.3.0 - Production on Sun Nov 3 17:02:51 2013
- Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
- connected to target database: TEST0924 (DBID=2720875862)
- RMAN> sql 'alter database datafile 3 offline';
- sql statement: alter database datafile 3 offline
- RMAN> backup as copy datafile 3 format '+DATA';
- Starting backup at 03-NOV-13
- allocated channel: ORA_DISK_1
- channel ORA_DISK_1: SID=127 device type=DISK
- allocated channel: ORA_DISK_2
- channel ORA_DISK_2: SID=191 device type=DISK
- allocated channel: ORA_DISK_3
- channel ORA_DISK_3: SID=157 device type=DISK
- channel ORA_DISK_1: starting datafile copy
- input datafile file number=00003 name=/u01/app/oracle/oradata/test0924/tbsasmmig01.dbf
- output file name=+DATA/test0924/datafile/tbsasmmig.264.830538365 tag=TAG20131103T170603 RECID=13 STAMP=830538366
- channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07
- Finished backup at 03-NOV-13
- Starting Control File and SPFILE Autobackup at 03-NOV-13
- piece handle=/u01/app/oracle/fast_recovery_area/TEST0924/autobackup/2013_11_03/o1_mf_s_830538370_97fl6mr9_.bkp comment=NONE
- Finished Control File and SPFILE Autobackup at 03-NOV-13
- RMAN> switch datafile 3 to copy;
- datafile 3 switched to datafile copy "+DATA/test0924/datafile/tbsasmmig.264.830538365"
- RMAN> recover datafile 3;
- Starting recover at 03-NOV-13
- using channel ORA_DISK_1
- using channel ORA_DISK_2
- using channel ORA_DISK_3
- starting media recovery
- media recovery complete, elapsed time: 00:00:00
- Finished recover at 03-NOV-13
- RMAN> sql 'alter database datafile 3 online';
- sql statement: alter database datafile 3 online
- sys@TEST0924> select file_id,file_name,tablespace_name from dba_data_files;
- FILE_ID FILE_NAME TABLESPACE_NAME
- ---------- -------------------------------------------------- ------------------------------
- 4 /u01/app/oracle/oradata/test0924/users01.dbf USERS
- 3 +DATA/test0924/datafile/tbsasmmig.264.830538365 TBSASMMIG
- 2 /u01/app/oracle/oradata/test0924/sysaux01.dbf SYSAUX
- 1 /u01/app/oracle/oradata/test0924/system01.dbf SYSTEM
- 5 /u01/app/oracle/oradata/test0924/example01.dbf EXAMPLE
- 9 /u01/app/oracle/oradata/test0924/undotbs01.dbf UNDOTBS1
- 6 rows selected.
- sys@TEST0924> select * from t2
- 2 ;
- ID NAME
- ---------- --------------------
- 1 a1
另一种转换方法:
- RMAN> backup tablespace users;
- Starting backup at 24-OCT-13
- using target database control file instead of recovery catalog
- allocated channel: ORA_DISK_1
- channel ORA_DISK_1: SID=163 device type=DISK
- allocated channel: ORA_DISK_2
- channel ORA_DISK_2: SID=226 device type=DISK
- allocated channel: ORA_DISK_3
- channel ORA_DISK_3: SID=9 device type=DISK
- 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=/u01/app/oracle/oradata/test0924/users01.dbf
- channel ORA_DISK_1: starting piece 1 at 24-OCT-13
- channel ORA_DISK_1: finished piece 1 at 24-OCT-13
- piece handle=/u01/app/oracle/fast_recovery_area/TEST0924/backupset/2013_10_24/o1_mf_nnndf_TAG20131024T101748_96lc0dxh_.bkp tag=TAG20131024T101748 comment=NONE
- channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07
- Finished backup at 24-OCT-13
- Starting Control File and SPFILE Autobackup at 24-OCT-13
- piece handle=/u01/app/oracle/fast_recovery_area/TEST0924/autobackup/2013_10_24/o1_mf_s_829649875_96lc0obm_.bkp comment=NONE
- Finished Control File and SPFILE Autobackup at 24-OCT-13
- RMAN> run
- 2> {sql 'alter tablespace users offline immediate';
- 3> set newname for datafile 4 to '+DATA';
- 4> restore tablespace users;
- 5> switch datafile 4;
- 6> recover tablespace users;
- 7> sql 'alter tablespace users online';
- 8> }
- sql statement: alter tablespace users offline immediate
- executing command: SET NEWNAME
- Starting restore at 24-OCT-13
- using channel ORA_DISK_1
- using channel ORA_DISK_2
- using channel ORA_DISK_3
- channel ORA_DISK_1: starting datafile backup set restore
- channel ORA_DISK_1: specifying datafile(s) to restore from backup set
- channel ORA_DISK_1: restoring datafile 00004 to +DATA
- channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/TEST0924/backupset/2013_10_24/o1_mf_nnndf_TAG20131024T101748_96lc0dxh_.bkp
- channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/TEST0924/backupset/2013_10_24/o1_mf_nnndf_TAG20131024T101748_96lc0dxh_.bkp tag=TAG20131024T101748
- channel ORA_DISK_1: restored backup piece 1
- channel ORA_DISK_1: restore complete, elapsed time: 00:00:07
- Finished restore at 24-OCT-13
- datafile 4 switched to datafile copy
- input datafile copy RECID=6 STAMP=829650049 file name=+DATA/test0924/datafile/users.260.829650045
- Starting recover at 24-OCT-13
- using channel ORA_DISK_1
- using channel ORA_DISK_2
- using channel ORA_DISK_3
- starting media recovery
- media recovery complete, elapsed time: 00:00:01
- Finished recover at 24-OCT-13
- sql statement: alter tablespace users online
- sys@TEST0924> select file_name from dba_data_files;
- FILE_NAME
- ----------------------------------------------------------------------------------------------------
- +DATA/test0924/datafile/users.260.829650045
- /u01/app/oracle/oradata/test0924/sysaux01.dbf
- /u01/app/oracle/oradata/test0924/system01.dbf
- /u01/app/oracle/oradata/test0924/example01.dbf
- /u01/app/oracle/oradata/test0924/undotbs02.dbf
- /u01/app/oracle/oradata/test0924/undotbs01.dbf
- /u01/app/oracle/oradata/test0924/inventory01.dbf
- 7 rows selected.
来源:http://blog.csdn.net/rlhua/article/details/14107309