使用RMAN Convert Database命令实现跨平台的数据库迁移

  下面是一段使用RMAN Convert Database命令将Oracle 11.2.0.3 Database for Windows 64bit环境下的数据库迁移到Oracle 11.2.0.3 Database for Linux 64bit的实验。

1.以只读方式打开数据库。
SQL> shutdown immediate
数据库已经关闭。
已经卸载数据库。
ORACLE 例程已经关闭。
SQL> startup mount
ORACLE 例程已经启动。

Total System Global Area  304807936 bytes
Fixed Size                  2254704 bytes
Variable Size             104859792 bytes
Database Buffers          192937984 bytes
Redo Buffers                4755456 bytes
数据库装载完毕。
SQL> alter database open read only;

数据库已更改。

2.检查可转换性和标示外部对象。
使用DBMS_TDB.CHECK_DB检查数据库状态。
使用DBMS_TDB包的CHECK_DB函数检查数据库是否准备好了。
set serveroutput on
declare
    db_ready boolean;
  begin
    /* db_ready is ignored, but with SERVEROUTPUT set to ON any 
     * conditions preventing transport will be output to console */
    db_ready := dbms_tdb.check_db('Microsoft Windows IA (32-bit)',
        dbms_tdb.skip_none);
  end;

使用DBMS_TDB.CHECK_EXTERNAL标识外部对象。
SQL> set serveroutput on
SQL> declare
     external boolean;
  begin
    /* value of external is ignored, but with SERVEROUTPUT set to ON
     * dbms_tdb.check_external displays report of external objects
     * on console */
    external := dbms_tdb.check_external;
  end;

3.执行CONVERT DATABASE命令。
C:\Documents and Settings\Administrator>rman target /

恢复管理器: Release 11.2.0.3.0 - Production on 星期二 3月 26 01:11:16 2013

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

已连接到目标数据库: ORCL (DBID=1338818727)

RMAN> CONVERT DATABASE NEW DATABASE 'orcl'
transport script 'c:\convertdb\transportscript.sql'
to platform 'Linux x86 64-bit'
PARALLELISM 4
db_file_name_convert 'C:\APP\ORADATA\ORCL\','c:\convertdb\';

NEW DATABASE=新数据库名称
transport script=迁移过程需要执行的步骤及脚本
to platform=迁移的目标平台
db_file_name_convert='源数据库数据文件的存储位置' '转换后的文件存储位置' (注意:存储位置最后一定加上'\'符号)
如果'源数据库数据文件的存储位置'下存在子目录,只需要在'转换后的文件存储位置'下创建相应的子目录即可,不需要在db_file_name_convert进行子目录的指定。

单进程的转换通常较慢,可以适当增加并行度,提高转换速度。

如果CONVERT DATABASE执行失败以后,再次执行可能收到如下的报错:
在口令文件中找到用户 SYS (具有 SYSDBA and SYSOPER 权限)
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03009: conversion at source 命令 (ORA_DISK_1 通道上, 在 08/20/2015 09:32:25 上) 失败
ORA-19926: 此时无法转换数据库

尝试重启数据库实例再次执行。
在目的地不能有重复的文件存在,否则会报错。

CONVERT DATABASE命令还可以在目标端执行:
CONVERT DATABASE on target platform
convert script 'E:\app\oradata\hello_linux\convertscript.sql'
transport script 'E:\app\oradata\hello_linux\transportscript.sql'
NEW DATABASE 'hello'
PARALLELISM 4
db_file_name_convert 'E:\app\oradata\hello\','E:\app\oradata\hello_linux\';

详情参考文章:
RMAN跨平台传输数据库和表空间》:http://blog.itpub.net/23135684/viewspace-776048/

启动 conversion at source 于 26-3月 -13
使用目标数据库控制文件替代恢复目录
分配的通道: ORA_DISK_1
通道 ORA_DISK_1: SID=21 设备类型=DISK

在数据库中找到目录 SYS.ORACLE_OCM_CONFIG_DIR
在数据库中找到目录 SYS.DATA_PUMP_DIR
在数据库中找到目录 SYS.XMLDIR

在口令文件中找到用户 SYS (具有 SYSDBA and SYSOPER 权限)
通道 ORA_DISK_1: 启动数据文件转换
输入数据文件: 文件号=00001 名称=C:\APP\ORADATA\ORCL\SYSTEM01.DBF
已转换的数据文件 = C:\CONVERTDB\SYSTEM01.DBF
通道 ORA_DISK_1: 数据文件转换完毕, 经过时间: 00:00:07
通道 ORA_DISK_1: 启动数据文件转换
输入数据文件: 文件号=00002 名称=C:\APP\ORADATA\ORCL\SYSAUX01.DBF
已转换的数据文件 = C:\CONVERTDB\SYSAUX01.DBF
通道 ORA_DISK_1: 数据文件转换完毕, 经过时间: 00:00:25
通道 ORA_DISK_1: 启动数据文件转换
输入数据文件: 文件号=00003 名称=C:\APP\ORADATA\ORCL\UNDOTBS01.DBF
已转换的数据文件 = C:\CONVERTDB\UNDOTBS01.DBF
通道 ORA_DISK_1: 数据文件转换完毕, 经过时间: 00:00:01
通道 ORA_DISK_1: 启动数据文件转换
输入数据文件: 文件号=00004 名称=C:\APP\ORADATA\ORCL\USERS01.DBF
已转换的数据文件 = C:\CONVERTDB\USERS01.DBF
通道 ORA_DISK_1: 数据文件转换完毕, 经过时间: 00:00:01
编辑 init.ora 文件 C:\APP\PRODUCT\11.2.0\DB_1\DATABASE\INIT_00O5F09R_1_0.ORA。此
 PFILE 将用于在目标平台上创建数据库据
在目标平台上运行 SQL 脚本 C:\CONVERTDB\TRANSPORTSCRIPT.SQL 以创建数据库
要重新编译所有 PL/SQL 模块, 请在目标平台上运行 utlirp.sql 和 utlrp.sql
要更改内部数据库标识符, 请使用 DBNEWID 实用程序
完成 conversion at source 于 26-3月 -13


transportscript.sql的内容如下:
-- The following commands will create a new control file and use it
-- to open the database.
-- Data used by Recovery Manager will be lost.
-- The contents of online logs will be lost and all backups will
-- be invalidated. Use this only if online logs are damaged.

-- After mounting the created controlfile, the following SQL
-- statement will place the database in the appropriate
-- protection mode:
--  ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE PERFORMANCE

STARTUP NOMOUNT PFILE='C:\APP\PRODUCT\11.2.0\DB_1\DATABASE\INIT_00O5F09R_1_0.ORA'
CREATE CONTROLFILE REUSE SET DATABASE "ORCL" RESETLOGS  NOARCHIVELOG
    MAXLOGFILES 16
    MAXLOGMEMBERS 3
    MAXDATAFILES 100
    MAXINSTANCES 8
    MAXLOGHISTORY 292
LOGFILE
  GROUP 1 'C:\APP\PRODUCT\11.2.0\DB_1\DATABASE\ARCH_D-ORCL_ID-1338818727_S-4_T-1_A-811037993_03O5F09R'  SIZE 50M BLOCKSIZE 512,
  GROUP 2 'C:\APP\PRODUCT\11.2.0\DB_1\DATABASE\ARCH_D-ORCL_ID-1338818727_S-5_T-1_A-811037993_04O5F09R'  SIZE 50M BLOCKSIZE 512,
  GROUP 3 'C:\APP\PRODUCT\11.2.0\DB_1\DATABASE\ARCH_D-ORCL_ID-1338818727_S-6_T-1_A-811037993_05O5F09R'  SIZE 50M BLOCKSIZE 512
DATAFILE
  'C:\CONVERTDB\SYSTEM01.DBF',
  'C:\CONVERTDB\SYSAUX01.DBF',
  'C:\CONVERTDB\UNDOTBS01.DBF',
  'C:\CONVERTDB\USERS01.DBF'
CHARACTER SET ZHS16GBK
;

-- Database can now be opened zeroing the online logs.
ALTER DATABASE OPEN RESETLOGS;

-- Commands to add tempfiles to temporary tablespaces.
-- Online tempfiles have complete space information.
-- Other tempfiles may require adjustment.
ALTER TABLESPACE TEMP ADD TEMPFILE 'C:\APP\PRODUCT\11.2.0\DB_1\DATABASE\DATA_D-ORCL_I-1338818727_TS-TEMP_FNO-1_06O5F09R'
     SIZE 30408704  AUTOEXTEND ON NEXT 655360  MAXSIZE 32767M;
-- End of tempfile additions.
--

set echo off
prompt ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
prompt * Your database has been created successfully!
prompt * There are many things to think about for the new database. Here
prompt * is a checklist to help you stay on track:
prompt * 1. You may want to redefine the location of the directory objects.
prompt * 2. You may want to change the internal database identifier (DBID) 
prompt *    or the global database name for this database. Use the 
prompt *    NEWDBID Utility (nid).
prompt ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

SHUTDOWN IMMEDIATE 
STARTUP UPGRADE PFILE='C:\APP\PRODUCT\11.2.0\DB_1\DATABASE\INIT_00O5F09R_1_0.ORA'
@@ ?/rdbms/admin/utlirp.sql 
SHUTDOWN IMMEDIATE 
STARTUP PFILE='C:\APP\PRODUCT\11.2.0\DB_1\DATABASE\INIT_00O5F09R_1_0.ORA'
-- The following step will recompile all PL/SQL modules.
-- It may take serveral hours to complete.
@@ ?/rdbms/admin/utlrp.sql 
set feedback 6;

    严格按照transportscript.sql的描述,修改相应路径按步骤执行即可完成迁移工作。

    相同ENDIAN平台之间的数据库迁移也可以直接拷贝完整的数据文件、控制文件、日志文件、参数文件、密码文件,通过手动的方式同样可以打开数据库,但必须确保拷贝的数据库是一致的,否则在新环境的实例恢复将失败:
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01113: file 1 needs media recovery
ORA-01110: data file 1: '/u01/app/oracle/oradata/orcl/SYSTEM01.DBF'


SQL> recover database;
ORA-00283: recovery session canceled due to errors
ORA-10562: Error occurred while applying redo to data block (file# 2, block#
6595)
ORA-10564: tablespace SYSAUX
ORA-01110: data file 2: '/u01/app/oracle/oradata/orcl/SYSAUX01.DBF'
ORA-10561: block type 'TRANSACTION MANAGED DATA BLOCK', data object# 6651
ORA-00600: internal error code, arguments: [4502], [0], [], [], [], [], [], [],
[], [], [], []


告警日志:
2013-03-25 16:42:39.551000 +08:00
ALTER DATABASE RECOVER  database
Media Recovery Start
Serial Media Recovery started
Recovery of Online Redo Log: Thread 1 Group 1 Seq 4 Reading mem 0
  Mem# 0: /u01/app/oracle/oradata/orcl/REDO01.LOG
2013-03-25 16:42:40.718000 +08:00
Errors in file /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_2623.trc  (incident=2553):
ORA-00600: internal error code, arguments: [4502], [0], [], [], [], [], [], [], [], [], [], []
Incident details in: /u01/app/oracle/diag/rdbms/orcl/orcl/incident/incdir_2553/orcl_ora_2623_i2553.trc
2013-03-25 16:42:41.882000 +08:00
Use ADRCI or Support Workbench to package the incident.
See Note 411.1 at My Oracle Support for error and packaging details.
Dumping diagnostic data in directory=[cdmp_20130325164242], requested by (instance=1, sid=2623), summary=[incident=2553].
2013-03-25 16:42:44.437000 +08:00
Media Recovery failed with error 10562
ORA-283 signalled during: ALTER DATABASE RECOVER  database  ...
Sweep [inc][2553]: completed
Sweep [inc2][2553]: completed
2013-03-25 16:43:15.731000 +08:00
Shutting down instance (abort)
License high water mark = 1
USER (ospid: 2623): terminating the instance
2013-03-25 16:43:16.744000 +08:00
Instance terminated by USER, pid = 2623
Instance shutdown complete

    采用Oracle RMAN convert Database迁移数据库,那么在以read only打开数据库的时候就确保了数据库的一致性。

你可能感兴趣的:(Oracle,RMAN和备份恢复)