一、项目需求
由于项目需要,需要将部署在 Linux 系统上的 Oracle 19c 的RMAN 备份集恢复到Window同一版本的数据库上。那么问题来了,rman是否支持这种异构的恢复呢?答案是支持的,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
Note: Backup must be cold/consistent backup. I.e. cannot apply redo between Windows and Linux(虽然基本备份和恢复过程和同平台rman备份恢复无差异,但是因为跨平台不能读取redo、archivelog信息。)
具体可以查看以下文档:
Clone Database from Windows To Linux (Lower patchset to Higher) using RMAN (文档 ID 2143991.1)
RMAN DUPLICATE/RESTORE/RECOVER Mixed Platform Support (文档 ID 1079563.1)
二、实施环境
源端: Red Hat Linux 8.9 Oracle 19.22
目标端: Windows Server 2012 R2 Standard Oracle 19.22
三、实施过程
3.1 前期准备
做恢复之前,首先我们要查看数据库自带的试图,来判断一下两平台如果传输备份数据是否需要转换字符,我是从Linux x86 64-bit恢复到Microsoft Windows x86 64-bit,很显然它们都属于little字节,所以不需要转换。
sys@orcl(1769)> col PLATFORM_ID for 999
sys@orcl(1769)> col PLATFORM_NAME for a40
sys@orcl(1769)> col ENDIAN_FORMAT for a10
sys@orcl(1769)> set linesize 200;
sys@orcl(1769)> select * from v$transportable_platform order by platform_id;
PLATFORM_ID PLATFORM_NAME ENDIAN_FOR
----------- ---------------------------------------- ----------
1 Solaris[tm] OE (32-bit) Big
2 Solaris[tm] OE (64-bit) Big
3 HP-UX (64-bit) Big
4 HP-UX IA (64-bit) Big
5 HP Tru64 UNIX Little
6 AIX-Based Systems (64-bit) Big
7 Microsoft Windows IA (32-bit) Little
8 Microsoft Windows IA (64-bit) Little
9 IBM zSeries Based Linux Big
10 Linux IA (32-bit) Little
11 Linux IA (64-bit) Little
12 Microsoft Windows x86 64-bit Little
13 Linux x86 64-bit Little
15 HP Open VMS Little
16 Apple Mac OS Big
17 Solaris Operating System (x86) Little
18 IBM Power Based Linux Big
19 HP IA Open VMS Little
20 Solaris Operating System (x86-64) Little
21 Apple Mac OS (x86-64) Little
3.2 源端数据备份
备份脚本如下:
rman target /
run {
allocate channel c1 device type disk maxpiecesize 500M;
allocate channel c2 device type disk maxpiecesize 500M;
crosscheck backup;
crosscheck archivelog all;
sql"alter system archive log current";
backup database format '/data/backup/rman/db_%d_%T_%s_%U.bak';
backup as compressed BACKUPSET tag '_arch' format '/data/backup/rman/arc_%d_%T_s%s_p%p_%U.bak' archivelog all;
backup current controlfile tag='ctl' format='/data/backup/rman/ctl_%d_%U_%T.bak';
backup spfile tag='_spfile' format='/data/backup/rman/spfile_%d_%U_%T.bak';
release channel ch1;
release channel ch2;
}
3.3 拷贝备份集到windows下
将备份文件拷贝到 Windows 目录下(c:\backup)
3.4 创建pfile
pfile文件内容如下:
C:\app\administrator\product\19.3.0\db\database\INITORCL.ORA
*.audit_file_dest='C:\app\administrator\admin\orcl\adump'
*.audit_trail='NONE'
*.compatible='19.0.0'
*.control_file_record_keep_time=31
*.control_files='C:\data\ORCL\control01.ctl','C:\data\ORCL\control02.ctl'
*.db_block_size=8192
*.db_create_file_dest='C:\data'
*.db_files=5000
*.db_name='orcl'
*.deferred_segment_creation=FALSE
*.diagnostic_dest='C:\app\administrator'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
*.local_listener='(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.101.207)(PORT=1521))'
*.log_archive_dest_1='location=C:\arch'
*.log_archive_format='%t_%s_%r.dbf'
*.nls_language='AMERICAN'
*.nls_territory='AMERICA'
*.open_cursors=1000
*.parallel_max_servers=64
*.pga_aggregate_target=322122547
*.processes=2000
*.remote_login_passwordfile='EXCLUSIVE'
*.session_cached_cursors=300
*.sga_max_size=858993459
*.sga_target=858993459
*.undo_retention=10800
*.undo_tablespace='UNDOTBS1'
3.5 创建相关路径
目标环境创建pfile中几个参数的路径:包括audit_file_dest、数据文件路径、归档路径。
mkdir C:\app\administrator\admin\orcl\adump
mkdir C:\data\ORCL
mkdir C:\arch
3.6 数据库启动nomount
目标数据库启动数据库到nomount状态,如报错,根据报错排查对应错误。
sqlplus / as sysdba
startup nomount;
create spfile from pfile;
shutdown abort;
startup nomount;
3.7 恢复控制文件
首先进行控制文件的还原,然后启动到mount状态
rman target /
# list backup of controlfile;
restore controlfile from 'C:\backup\ctl_ORCL_0n2qv2jb_23_1_1_20240516.bak';
alter database mount;
3.8 catalog备份集
备份文件存放的位置是记录在控制文件中的,前面做了控制文件的还原,能查询到所有的备份信息。但是记录的备份位置都是Linux的路径,此处主要做了备份的校验删除失效的备份信息,加载传输到Window系统上的备份文件信息。
####清理RMAN记录的catalog的失效记录
crosscheck archivelog all;
crosscheck backup;
delete noprompt expired backup;
delete noprompt expired archivelog all;
###将RMAN备份文件加入到catalog
catalog start with 'C:\backup\';
3.9 redo日志的调整
redo日志记录的是Linux下的路径,需要调整到Window相应路径
sqlplus / as sysdba
select member from v$logfile;
MEMBER
--------------------------------------------------------------------------------
/data/ORCL/redo03.log
/data/ORCL/redo02.log
/data/ORCL/redo01.log
/data/ORCL/onlinelog/o1_mf_11_m24cx451_.log
/data/ORCL/onlinelog/o1_mf_12_m24cx4qj_.log
/data/ORCL/onlinelog/o1_mf_13_m24cx73y_.log
/data/ORCL/onlinelog/o1_mf_14_m24cx91k_.log
/data/ORCL/onlinelog/o1_mf_15_m24cxc2h_.log
已选择 8 行。
alter database rename file '/data/ORCL/redo03.log' to 'C:\data\ORCL\redo03_.log';
alter database rename file '/data/ORCL/redo02.log' to 'C:\data\ORCL\redo02_.log';
alter database rename file '/data/ORCL/redo01.log' to 'C:\data\ORCL\redo01_.log';
alter database rename file '/data/ORCL/onlinelog/o1_mf_11_m24cx451_.log' to 'C:\data\ORCL\ONLINELOG\o1_mf_11_m24cx451_.log';
alter database rename file '/data/ORCL/onlinelog/o1_mf_12_m24cx4qj_.log' to 'C:\data\ORCL\ONLINELOG\o1_mf_12_m24cx4qj_.log';
alter database rename file '/data/ORCL/onlinelog/o1_mf_13_m24cx73y_.log' to 'C:\data\ORCL\ONLINELOG\o1_mf_13_m24cx73y_.log';
alter database rename file '/data/ORCL/onlinelog/o1_mf_14_m24cx91k_.log' to 'C:\data\ORCL\ONLINELOG\o1_mf_14_m24cx91k_.log';
alter database rename file '/data/ORCL/onlinelog/o1_mf_15_m24cxc2h_.log' to 'C:\data\ORCL\ONLINELOG\o1_mf_15_m24cxc2h_.log';
select member from v$logfile;
MEMBER
--------------------------------------------------------------------------------
C:\DATA\ORCL\REDO03_.LOG
C:\DATA\ORCL\REDO02_.LOG
C:\DATA\ORCL\REDO01_.LOG
C:\DATA\ORCL\O1_MF_11_M24CX451_.LOG
C:\DATA\ORCL\O1_MF_12_M24CX4QJ_.LOG
C:\DATA\ORCL\O1_MF_13_M24CX73Y_.LOG
C:\DATA\ORCL\O1_MF_14_M24CX91K_.LOG
C:\DATA\ORCL\O1_MF_15_M24CXC2H_.LOG
已选择 8 行。
3.10 还原数据库
rman target /
# 寻找备份归档日志里面最大的 scn 号
list backup of archivelog all;
8105387
RUN
{
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
allocate channel c4 type disk;
set until scn 8105387;
SET NEWNAME FOR DATAFILE 1 TO 'C:\data\ORCL\system01.dbf';
SET NEWNAME FOR DATAFILE 2 TO 'C:\data\ORCL\NNC_INDEX01.DBF';
SET NEWNAME FOR DATAFILE 3 TO 'C:\data\ORCL\sysaux01.dbf';
SET NEWNAME FOR DATAFILE 4 TO 'C:\data\ORCL\undotbs01.dbf';
SET NEWNAME FOR DATAFILE 5 TO 'C:\data\ORCL\NNC_DATA01.DBF';
SET NEWNAME FOR DATAFILE 7 TO 'C:\data\ORCL\users01.dbf';
SET NEWNAME FOR TEMPFILE 1 TO 'C:\data\ORCL\temp01.dbf';
restore database;
SWITCH DATAFILE ALL;
SWITCH TEMPFILE ALL;
recover database;
release channel c1;
release channel c2;
release channel c3;
release channel c4;
}
3.11 打开数据库
sqlplus / as sysdba
alter database open resetlogs;
3.12 编译无效对象
运行@?/rdbms/admin/utlrp.sql;重新编译一下无效对象
sqlplus / as sysdba
SQL> @?/rdbms/admin/utlrp.sql