RMAN异构迁移及异构DataGuard
1、Rman工具将Windows数据库迁移到Linux上。
rman可以实现跨操作系统平台备份恢复,但是必须符合如下标准,且数据库版本要一致。
For Oracle Database 10g Release 2 and above releases:
Solaris x86-64 <-> Linux x86-64
HP-PA <-> HP-IA
Windows IA (64-bit) / Windows (64-bit Itanium) <-> Windows 64-bit for AMD /
For Oracle Database 11g Release 1 and above releases (requires minimum 11.1 compatible setting):
Linux <-> Windows
另外虽然基本备份和恢复过程和同平台rman备份恢复无差异,但是因为跨平台不能读取redo、archivelog信息,所以需要原端数据库启动到mount状态,然后执行rman全备。
11g支持set newname for database to 可以方便的将全库数据文件进行自动重命名。
run {
set newname for database to '/home/oracle/app/oracle/oradata/ora/%U';
restore database;
switch datafile all;
}
启动数据库
alter database open resetlogs;
修改temp表空间文件路径
SQL>alter database tempfile '/oradata/datafiles/ora/temp01.dbf' drop;
Database altered.
SQL>alter tablespace temp add tempfile '/oradata/datafiles/ora/temp01.dbf' reuse; --需要数据库是open 或open read only状态
修改redo存放路径
此时redo默认会放到$ORACLE_HOME/dbs目录中,参考《Oracle 修改redo日志》重新生成新的redo到指定位置。
失败测试记录:
记录1;
尝试使用关库冷备份的方法将windows文件直接复制到linux中并尝试修改文件名,从而直接拉起数据库, 但是alter database rename file 命令无法执行成功。
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
C:\APP\ADMINISTRATOR\ORADATA\ORA\SYSTEM02.DBF
C:\APP\ADMINISTRATOR\ORADATA\ORA\SYSAUX01.DBF
C:\APP\ADMINISTRATOR\ORADATA\ORA\UNDOTBS01.DBF
C:\APP\ADMINISTRATOR\ORADATA\ORA\USERS01.DBF
C:\APP\ADMINISTRATOR\ORADATA\ORA\EXAMPLE01.DBF
SQL> alter database rename file 'C:\APP\ADMINISTRATOR\ORADATA\ORA\SYSTEM02.DBF' to '/home/oracle/app/oracle/oradata/ora/SYSTEM02.DBF';
alter database rename file 'C:\APP\ADMINISTRATOR\ORADATA\ORA\SYSTEM02.DBF' to '/home/oracle/app/oracle/oradata/ora/SYSTEM02.DBF'
*
ERROR at line 1:
ORA-01511: error in renaming log/data files
ORA-01516: nonexistent log file, data file, or temporary file
"C:\APP\ADMINISTRATOR\ORADATA\ORA\SYSTEM02.DBF"
原因:怀疑是和跨平台文件名无法正常识别有关。
记录2;
如果不将原库处于mount状态,而是直接open状态下备份,然后备份归档,当目标端恢复时可以成功restore database,但是recover database时就无法成功,报如下错误。根据mos介绍这种跨平台场景下,redo 、archivelog 不支持传统的方式进行介质恢复。
RMAN> recover database;
Starting recover at 23-NOV-16
using channel ORA_DISK_1
starting media recovery
channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=95
channel ORA_DISK_1: reading from backup piece /tmp/backup/a/ARCHIVE0DRLLO42_1_1.BAK
channel ORA_DISK_1: piece handle=/tmp/backup/a/ARCHIVE0DRLLO42_1_1.BAK tag=TAG20161123T205634
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_95_925028740.dbf thread=1 sequence=95
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 11/23/2016 21:11:20
RMAN-11003: failure during parse/execution of SQL statement: alter database recover logfile '/home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_95_925028740.dbf'
ORA-10562: Error occurred while applying redo to data block (file# 2, block# 61511)
ORA-10564: tablespace SYSAUX
ORA-01110: data file 2: '/home/oracle/app/oracle/oradata/ora/data_D-ORA_TS-SYSAUX_FNO-2'
ORA-10561: block type 'TRANSACTION MANAGED DATA BLOCK', data object# 67714
ORA-00600: internal error code, arguments: [ktbrcl:CDLC not in CR], [228], [], [], [], [], [], [], [], [], [], []
2、跨平台Dataguard
每种操作系统平台都有platform_id ,如
SQL> select platform_id, platform_name from v$database;
PLATFORM_ID PLATFORM_NAME
----------- -----------------------------------------------------
13 Linux x86 64-bit
如下表中的各种platform_id组合可进行Dataguard配置,有些组合需要满足特定的条件,虽然跨平台不能将原端的归档直接在新库recover,但是可以部署特定异构平台的Dataguard,并实现实时同步。
PLATFORM_ID | PLATFORM_NAME | PLATFORM_IDs supported within the same Data Guard configuration when using Data Guard Redo Apply (Physical Standby) |
2 | Solaris[tm] OE (64-bit) | 2 |
3 | HP-UX (64-bit) | 3 |
4 | HP-UX IA (64-bit) | 4 |
5 | HP Tru64 UNIX | 5 |
6 | IBM AIX on POWER Systems (64-bit) | 2 - See Support Note: 1982638.1 and Note: 414043.1 |
7 | Microsoft Windows (32-bit) | 7 |
8 | Microsoft Windows IA (64-bit) | 7 - Oracle 10g onward, see Support Note: 414043.1 |
9 | IBM zSeries Based Linux | 9 |
10 | Linux (32-bit) | 7 - Oracle 11g onward, requires Patch 13104881 |
11 | Linux IA (64-bit) | 10 - Oracle 10g onward, see Support Note: 414043.1 |
12 | Microsoft Windows 64-bit for AMD | 7 - Oracle 10g onward, see Support Note Note: 414043.1 |
13 | Linux 64-bit for AMD | 7 - Oracle 11g onward, see Support Note: 414043.1, also requires Patch 13104881 |
15 | HP Open VMS | 15 |
16 | Apple Mac OS | 16 |
17 | Solaris Operating System (x86) | 17 |
18 | IBM Power Based Linux | 9 (64-bit zSeries only) |
20 | Solaris Operating System (AMD64) | 13 - Oracle 11g onward |
配置过程和普通Dataguard无差别,需要注意的是经过测试,需要将备机的*_FILE_NAME_CONVERT两个参数设置上 ,且rman恢复的时候直接recover而不要通过 set newname 的形式去指定新文件的路径,在使用rman进行初始化同步的时候会自动按照转换参数修改redo和temp文件的路径,否则会导致恢复后temp和redo仍然使用原windows路径格式,且无法手动修改。
注意事项:
SQL> alter system set DB_FILE_NAME_CONVERT='C:\APP\ADMINISTRATOR\ORADATA\ORA\','/home/oracle/app/oracle/oradata/ora/' scope=spfile;
System altered.
SQL> alter system set LOG_FILE_NAME_CONVERT='C:\APP\ADMINISTRATOR\ORADATA\ORA\','/home/oracle/app/oracle/oradata/ora/' scope=spfile;
System altered.
特别要特别以上转换参数中,windows路径的最后一个字符应该是\,linux的最后一样应该是/,否则转换后的数据文件就会是
/home/oracle/app/oracle/oradata/ora\EXAMPLE01.DBF
关于rman恢复的总结:
rman restore database还原时,无论新环境的控制文件是for standby的还是普通的控制文件,生成的数据文件的路径并不受OMF影响.
但如果restore 出来的控制文件是 for standby 的那restore database的时候如果不指定set netname 会按照*_file_name_convert 参数的转换值来生成数据文件、temp文件、redo文件等。
但如果restore 出来的控制文件是普通的控制文件,那restore database的时候如果不指定set netname ,也不会按照*_file_name_convert 参数的转换值来生成数据文件、temp文件、redo文件。如果是windows环境,会生成到$ORALCE_HOME/dbs目录下,文件名如:C:APPADMINISTRATORORADATAORAEXAMPLE01.DBF。
如果是linux则会生成到原路径下,如果路径不存在这直接报错,中断还原。
当创建好了Dataguard后,如果主端添加数据文件,则备端处理情况如下:
当备机设置了db_file_name_convert参数,并同时启动了OMF功能是,OMF的优先级要高于db_file_name_convert参数,备机OMF启动的情况下会 忽略db_file_name_convert参数。
参考文档:
Data Guard Support for Heterogeneous Primary and Physical Standbys in Same Data Guard Configuration (文档 ID 413484.1)
RMAN DUPLICATE/RESTORE/RECOVER Mixed Platform Support (文档 ID 1079563.1)
Restore From Windows To Linux using RMAN Fails (文档 ID 2003327.1)
Dataguard DB/LOG FILE NAME CONVERT has been set but files are created in a different directory (文档 ID 1348512.1)