Oracle从windows迁移至linux 使用RMAN

实验环境:windows 2008 R2 & RHEL 6.5

Oracle版本:11.2.0.4

参考文档:

Clone Database from Windows To Linux (Lower patchset to Higher) using RMAN (文档 ID 2143991.1)

 

1. 将windows数据库shutdown immediate,然后启动到mount模式下

2. 生成pfile文件

create pfile='d:\rmanbackup\pfile.ora' from spfile;

3. 进行RMAN备份数据库和控制文件

rman target /

backup database format 'd:\rmanbackup\full_%U';

backup current controlfile format 'd:\rmanbackup\control_%U';

 

4. 将pfile.ora和RMAN备份的数据文件和控制文件传到linux上

 

5. 修改传送过去的pfile.ora文件,将一系列目录改为linux上的对应目录,注意sga和PGA的修改

startup nomount pfile='/tmp/rmanbackup/pfile.ora';

假如报错,根据报错排查对应错误

SQL> set linesize 999
SQL> col member format a80;
SQL> select * from v$logfile;

    GROUP# STATUS     TYPE    MEMBER									       IS_
---------- ---------- ------- -------------------------------------------------------------------------------- ---
	 1	      ONLINE  /u01/app/oracle/product/11.2.0/db_1/dbs/D:ORACLEPRODUCTORADATAORCLREDO01.LOG     NO
	 3	      ONLINE  /u01/app/oracle/product/11.2.0/db_1/dbs/D:ORACLEPRODUCTORADATAORCLREDO03.LOG     NO
	 2	      ONLINE  /u01/app/oracle/product/11.2.0/db_1/dbs/D:ORACLEPRODUCTORADATAORCLREDO02.LOG     NO

6. 恢复控制文件并且mount数据库

rman target /

RMAN>  restore controlfile from '/tmp/rmanbackup/CONTROL_03RMSH55_1_1';

RMAN> sql 'alter database mount';

示例:

[oracle@oratest ~]$  rman target /

Recovery Manager: Release 11.2.0.4.0 - Production on Wed Dec 7 14:48:47 2016

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

connected to target database: ORCL (not mounted)

RMAN>  restore controlfile from '/tmp/rmanbackup/CONTROL_03RMSH55_1_1';

Starting restore at 07-DEC-16
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
output file name=/oradata/CONTROL01.CTL
output file name=/oradata/CONTROL02.CTL
output file name=/oradata/CONTROL03.CTL
Finished restore at 07-DEC-16

RMAN> sql 'alter database mount';

sql statement: alter database mount
released channel: ORA_DISK_1

7. 清理RMAN记录的catalog的失效记录

RMAN> crosscheck backup;

RMAN> delete expired backup;

RMAN> crosscheck backup;

Starting implicit crosscheck backup at 07-DEC-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK
Crosschecked 2 objects
Finished implicit crosscheck backup at 07-DEC-16

Starting implicit crosscheck copy at 07-DEC-16
using channel ORA_DISK_1
Finished implicit crosscheck copy at 07-DEC-16

searching for all files in the recovery area
cataloging files...
no files cataloged

using channel ORA_DISK_1
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=D:\RMANBACKUP\FULL_01RMSH1N_1_1 RECID=1 STAMP=929973303
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=D:\RMANBACKUP\FULL_02RMSH3P_1_1 RECID=2 STAMP=929973370
Crosschecked 2 objects


RMAN> delete expired backup;                      

using channel ORA_DISK_1

List of Backup Pieces
BP Key  BS Key  Pc# Cp# Status      Device Type Piece Name
------- ------- --- --- ----------- ----------- ----------
1       1       1   1   EXPIRED     DISK        D:\RMANBACKUP\FULL_01RMSH1N_1_1
2       2       1   1   EXPIRED     DISK        D:\RMANBACKUP\FULL_02RMSH3P_1_1

Do you really want to delete the above objects (enter YES or NO)? yes
deleted backup piece
backup piece handle=D:\RMANBACKUP\FULL_01RMSH1N_1_1 RECID=1 STAMP=929973303
deleted backup piece
backup piece handle=D:\RMANBACKUP\FULL_02RMSH3P_1_1 RECID=2 STAMP=929973370
Deleted 2 EXPIRED objects

8. 将RMAN备份文件加入到catalog

catalog backuppiece '/tmp/rmanbackup/FULL_01RMSH1N_1_1','/tmp/rmanbackup/FULL_02RMSH3P_1_1';

有几个加几个,或者假如备份文件很多,那么用下面的命令

catalog start with '/tmp/rmanbackup/FULL_';

注意假如是直接指定了一个目录,那么最后必须接/表示这是一个目录,否则会被认为是一个前缀

9.开始在RMAN中从catalog中恢复数据库,并且set newname来指定新的路径,switch来将新的路径写到控制文件

run {
set newname for database to '/oradata/orcl/datafile/dbf_%U';
restore database;
}
switch database to copy;

10.开启数据库,使用resetlogs upgrade参数来重建redo文件

SQL> alter database open resetlogs upgrade;

顺便生成一下spfile

SQL> create spfile from pfile='/tmp/rmanbackup/pfile.ora';

重新编译一下无效对象

@?/rdbms/admin/utlrp.sql;

NOTE:

遇到了一个问题,是进行数据库迁移之后,temp数据文件因为不被RMAN所保护,需要检查tempfile:

ERROR at line 7:
ORA-01187: cannot read from file  because it failed verification tests
ORA-01110: data file 201: '/u01/app/oracle/product/11.2.0/db_1/dbs/D:ORACLEPRODUCTORADATAORCLTEMP01.DBF'
col name for a50;
select file#, ts#, name, status from v$tempfile;
     FILE#	  TS# NAME						 STATUS
---------- ---------- -------------------------------------------------- -------
	 1	    3 D:\ORACLE\PRODUCT\ORADATA\ORCL\TEMP01.DBF 	 ONLINE
SQL> alter database tempfile 'D:\ORACLE\PRODUCT\ORADATA\ORCL\TEMP01.DBF' drop;
alter database tempfile 'D:\ORACLE\PRODUCT\ORADATA\ORCL\TEMP01.DBF' drop
*
ERROR at line 1:
ORA-01516: nonexistent log file, data file, or temporary file "D:\ORACLE\PRODUCT\ORADATA\ORCL\TEMP01.DBF"

因为当前TEMP是默认临时表空间,所以想删掉这个临时数据文件,需要创建一个新的临时表空间,将其设置为默认,然后将TEMP表空间删掉,再新建TEMP表空间,将默认临时表空间改回来。

直接删除,会提示不能删除默认临时表空间:

SQL> drop tablespace temp;
drop tablespace temp
*
ERROR at line 1:
ORA-12906: cannot drop default temporary tablespace

解决方案:新建一个临时表空间,将其设置为默认临时表空间,再删除原本的临时表空间

(本人强迫症,所以删掉原来的temp之后,再重新建一个temp,将表空间设置回temp,看着顺眼)

需要数据库open状态

 

新建临时表空间temp2

CREATE TEMPORARY TABLESPACE temp2 TEMPFILE '/oradata/orcl/TEMP2.DBF' SIZE 200m AUTOEXTEND ON ;

设置temp2为默认临时表空间

ALTER DATABASE DEFAULT TEMPORARY TABLESPACE temp2;

 

删除原来的临时表空间temp

drop tablespace temp;

 

重新建临时表空间temp

CREATE TEMPORARY TABLESPACE temp TEMPFILE '/oradata/orcl/TEMP01.DBF' SIZE 1G REUSE AUTOEXTEND ON NEXT 200M  MAXSIZE 30G;

 

将temp设置为默认临时表空间(一些用户默认临时表空间就是temp,建议重建temp)

ALTER DATABASE DEFAULT TEMPORARY TABLESPACE temp;

 

注意:上一步修改完之后,假如想立即删除temp2表空间,那么此操作会宕住

需要

shutdown immediate 

退出再重新进sqlplus

startup

删除临时表空间temp2和数据文件

DROP TABLESPACE temp2 INCLUDING CONTENTS AND DATAFILES; 

再次检查一遍,OK

SQL> col name for a50;
SQL> select file#, ts#, name, status from v$tempfile;

     FILE#	  TS# NAME						 STATUS
---------- ---------- -------------------------------------------------- -------
	 1	    3 /oradata/orcl/TEMP01.DBF				 ONLINE

运行@?/rdbms/admin/utlrp.sql;重新编译一下无效对象

这次成功了

OK,数据库迁移完成

需要注意,假如两者版本不一致或者linux上打了新补丁,做完这一步之后照着README.html运行升级脚本,再次编译无效对象

再次重申:对数据库做迁移,升级之类的操作后编译无效对象是个好习惯

 

你可能感兴趣的:(Oracle)