使用具有 RMAN 增量备份的 M5 跨 Endian XTTS 将 Oracle Database 迁移到 OCI
简介
本教程介绍了如何使用 M5 Cross Endian Platform Migration 以及完全可传输数据泵和 RMAN 增量备份将 Oracle Database 迁移到 Oracle Cloud Infrastructure (OCI)。
此方法支持在采用不同 endian 格式的系统之间迁移,同时最大限度地减少应用停机时间。
该过程从从源到目标的完整备份副本开始。然后,应用增量备份,使目标与源保持几乎同步。仅在最终增量备份和元数据导出/导入期间需要停机。
环境详细信息
- 源数据库 (NON-CDB):
- 数据库版本:
19.29.0.0 - 操作系统:
AIX
- 数据库版本:
- 目标数据库 (NON-CDB):
- 数据库版本:
19.29.0.0 (OCI) - 操作系统:
Oracle Linux
- 数据库版本:
目标
- 将跨平台可传输表空间 (Cross Platform Transportable Tablespaces,XTTS) 与 RMAN 增量备份结合使用,以在极短的停机时间内跨 Endian 平台迁移数据。
Prerequisites
-
源数据库和目标数据库必须处于
ARCHIVELOG模式。 -
此过程支持源数据库的最低版本 v19.18。支持升级到 Oracle Database 26ai。
-
排除表空间
SYSTEM、SYSAUX、UNDO和TEMP。所有其他表空间必须包括在dbmig_ts_list.txt中。 -
跨平台仅在 Enterprise Edition 中可用。此过程不能与 Standard Edition 一起使用。
-
源数据库和目标数据库上的字符集必须相同。
-
必须在目标数据库上设置
db_create_file_dest参数。 -
查看 MOS 简讯 Data Pump Recommended Proactive Patches For 19.10 and Above KB107134 并应用源和目标上 19.18 或更高版本的数据库的所有必需修复。
-
查看 MOS 简讯 Data Pump Recommended Proactive Patches For 23ai / 26ai KB160561 并应用目标上 26ai 或更高版本的数据库所需的所有修复程序。
-
启用块更改跟踪以提高增量备份的性能(可选)。
-
表空间必须处于
READ WRITE模式。 -
可以使用标准 XTTS 迁移处于
READ ONLY模式的表空间。 -
COMPATIBLE参数在源和目标上必须相同(至少为19.0.0.0)。 -
RMAN 必须使用
BACKUPSET。不得使用COPY。
任务 1:准备源数据库
-
运行以下查询以检查源数据库上的 endian 格式。
col PLATFORM_NAME for a50 select platform_name, platform_id, endian_format from v$transportable_platform; -
标识将传输的源数据库中的表空间。如果要迁移所有表空间,请运行以下查询。
select tablespace_name from dba_tablespaces where contents='PERMANENT' and tablespace_name not in ('SYSTEM','SYSAUX'); -
检查传输集违规:
exec dbms_tts.transport_set_check('<comma-separated tablespace list>'); SELECT * FROM SYS.TRANSPORT_SET_VIOLATIONS; -
(可选)在源数据库上启用块更改跟踪,以提高增量备份的性能。
-
验证源数据库上的所有表空间是否都处于联机状态。
任务 2:准备目标数据库
-
创建新用户表空间。
select TABLESPACE_NAME from dba_tablespaces where TABLESPACE_NAME='USERS_OCI'; select TABLESPACE_NAME from dba_tablespaces order by 1; set long 99999 SELECT DBMS_METADATA.GET_DDL ('TABLESPACE','USERS') from dual;使用上述数据定义语言 (Data Definition Language,DDL) 输出并按如下所示替换磁盘组名称,然后创建新的用户表空间。
CREATE BIGFILE TABLESPACE USERS_OCI DATAFILE '+DATAC2' SIZE 1073741824 AUTOEXTEND ON NEXT 17179869184 MAXSIZE 33554431M LOGGING ONLINE PERMANENT BLOCKSIZE 8192 EXTENT MANAGEMENT LOCAL AUTOALLOCATE ENCRYPTION USING 'AES256' ENCRYPT DEFAULT NOCOMPRESS SEGMENT SPACE MANAGEMENT AUTO;使用以下查询将新用户表空间 USERS_OCI 分配给具有默认表空间 USERS 的所有数据库用户。
select 'alter user '||username||' default tablespace USERS_OCI;' from dba_users where default_tablespace='USERS';上面的选择查询的输出必须在重新分配新用户表空间后返回 0 。
select count(*) from dba_users where default_tablespace='USERS'; ALTER DATABASE DEFAULT TABLESPACE USERS_OCI; drop tablespace users including contents and datafiles; select TABLESPACE_NAME from dba_tablespaces where TABLESPACE_NAME='USERS'; -
在目标数据库上创建临时表空间。对源运行以下查询并收集表空间详细信息。
对源运行以下查询:
select TABLESPACE_NAME from dba_tablespaces where CONTENTS='TEMPORARY';然后在目标数据库上创建临时表空间。例如:
create bigfile temporary tablespace USER_TEMP tempfile size 672m autoextend on next 672m extent management local;
任务 3:增量 M5 XTTS 步骤
任务 3.1:初始阶段
-
从此处下载最新的 M5 脚本和解压缩: M5 Cross Endian Platform Migration using Full Transportable Data Pump Export/Import and RMAN Incremental Backups (Doc ID 2999157.1) 。在源和目标之间共享的 NFS 共享上创建工作目录。NFS 共享资源的路径在源和目标上应相同。
如果无法使用 NFS 共享,请使用任何本地存储。在源主机上创建目录并将其复制到目标主机。这需要在整个过程中多次重复。源主机和目标主机上的路径应相同。如果不是,则需要对超出此过程范围的脚本进行各种更改。
mkdir -p <Shared_location>/XTTS_Migration mkdir -p <Shared_location>/XTTS_Migration/Backup mkdir -p <Shared_location>/XTTS_Migration/DPPUMP cd <Shared_location> unzip DBMIG.zip该文件包含:
dbmig_driver_m5.sh:迁移驱动程序脚本。impdp.sh:导入驱动程序脚本。log目录:在运行时创建。存储 RMAN 备份日志、迁移日志和其他日志。rman_mig_bkp.log:集中迁移日志文件。rman_mig_bkp.lck:在每个备份开始时创建的锁定文件,以防止并发驱动程序执行。如果驱动程序执行中止,则不会删除锁定。在移除锁之前,应调查并解决该问题。
cmd目录:在运行时创建。存储 RMAN 备份和恢复脚本。dbmig_driver.properties:环境变量。dbmig_ts_list.txt:以逗号分隔的表空间列表。
-
修改 dbmig_driver.properties 中的变量(在 cmd 目录中)以反映您使用的环境,请参见配置文件
dbmig_driver.properties中的参数说明,此处为: M5 Cross Endian Platform Migration using Full Transportable Data Pump Export/Import and RMAN Incremental Backups 。dbmig_driver.properties 示例文件
############################################################ #Source database properties #my_M5_prop_version=2 # - # - ORACLE_HOME Path to Oracle Home # - ORACLE_SID SID of the source database # - SRC_SCAN Connect string to source database via SCAN. # If no SCAN, specify source database network name. # Enclose in single quotes # Example: '@myhost-scan/db1' # Example: '@localhost/pdb1' # - MIG_PDB Accepted values: 0, 1 # Choose 0 if source is non-CDB # Choose 1 if source is a PDB # - PDB_NAME If source is a PDB, specify PDB name. # Else leave blank # Example: PDB1 # - BKP_FROM_STDBY Accepted values: 0, 1 # Choose 0 to back up from primary database, # or if Data Guard is not in use. # Choose 1 to back up from standby database. ############################################################ export ORACLE_HOME=/u01/app/oracle/product/19.0.0.0/dbhome_1 export PATH=$PATH:$ORACLE_HOME/bin export ORACLE_SID=soldb1918 export SRC_SCAN='@scan1/soldb1918' export MIG_PDB=0 export PDB_NAME= export BKP_FROM_STDBY=0 ############################################################ #Source Data Pump settings # - SOURCE_DPDMP Directory path of the directory DATA_PUMP_DIR # Example: /u01/app/oracle/m5/data_pump_dir # - SOURCE_DPIR Data Pump Directory, typically DATA_PUMP_DIR # - SYSTEM_USR Username for Data Pump export. # Do not use SYS AS SYSDBA # Example: SYSTEM # - DP_TRACE Data Pump trace level. # Use 0 to disable trace. # Use 3FF0300 to full transportable tracing # See MOS Doc ID 286496.1 for details. # - DP_PARALLEL Data Pump parallel setting. # Accepted values: 1 to 999 # Example: 16 ############################################################ export SOURCE_DPDMP=<Shared_location>/XTTS_Migration/DPPUMP export SOURCE_DPDIR=DATA_PUMP_DIR export SYSTEM_USR=SYSTEM export DP_TRACE=0 export DP_PARALLEL=1 export DP_ENC_PROMPT=N ############################################################ #Source RMAN settings # - BKP_DEST_TYPE Accepted values: DISK, SBT_TAPE # Choose DISK to backup up to local storage # Choose SBT_TAPE to use ZDLRA # - BKP_DEST_PARM If BKP_DEST_TYPE=DISK, enter location for backup: # Example: /u01/app/oracle/m5/rman # If BKP_DEST_TYPE=SBT_TAPE, enter channel configuration: # Example: "'%d_%U' PARMS \"SBT_LIBRARY=<oracle_home>/lib/libra.so,SBT_PARMS=(RA_WALLET='location=file:<oracle_home>/dbs/zdlra credential_alias=<zdlra-connect-string>')\"" # - CAT_CRED If you use RMAN catalog or ZDLRA, specify connect string to catalog database # Example: <scan-name>:<port>/<service> # - SECTION_SIZE Section size used in RMAN backups # - CHN Number of RMAN channels allocated ############################################################ export BKP_DEST_TYPE=DISK export BKP_DEST_PARM=<Shared_location>/XTTS_Migration/Backup export CAT_CRED= export SECTION_SIZE=64G export CHN=8 ############################################################ #Destination host settings #If specified, the script transfers the RMAN backups and #Data Pump dump file to the destination via over SSH. #SSH equivalence is required. # - DEST_SERVER Network name of the destination server. # Leave blank if you manually transfer # backups and dump files # - DEST_USER User for SSH connection # Example: oracle # - DEST_WORKDIR The script working directory on destination # Example: /u01/app/oracle/m5 # - DEST_DPDMP The directory path used by DATA_PUMP_DIR # in destination database # Example: /u01/app/oracle/m5/data_pump_dir ############################################################ export DEST_SERVER=srvadm01 export DEST_USER=oracle export DEST_WORKDIR=<Shared_location>/XTTS_Migration export DEST_DPDMP=<Shared_location>/XTTS_Migration/DPDUMP ############################################################ #Advanced settings #Normally, you don't need to edit this section ############################################################ export WORKDIR=$PWD export LOG_DIR=${WORKDIR}/log export CMD_DIR=${WORKDIR}/cmd export PATH=$PATH:$ORACLE_HOME/bin export DT='date +%y%m%d%H%M%S' export CMD_MKDIR='which mkdir' export CMD_TOUCH='which touch' export CMD_CAT='which cat' export CMD_RM='which rm' export CMD_AWK='which awk' export CMD_SCP='which scp' export CMD_CUT='which cut' export CMD_PLATFORM='uname' if [[ "$CMD_PLATFORM" = "Linux" ]]; then export CMD_GREP="/usr/bin/grep" else if [[ "$CMD_PLATFORM" = "AIX" ]]; then export CMD_GREP="/usr/bin/grep" else if [[ "$CMD_PLATFORM" = "HPUX" ]]; then export CMD_GREP="/usr/bin/grep" else export CMD_GREP='which ggrep' fi fi fi export my_M5_prop_version=2为源数据库和目标数据库上的数据泵转储文件创建目录。
create directory M5_XTTS_MIG as '<Shared_Location>/XTTS_Migration/DPDUMP'; grant read,write on directory M5_XTTS_MIG to sys,system;
任务 3.2:0 级备份和恢复
-
在源系统上,以 Oracle 用户身份登录,并将环境变量(
ORACLE_HOME和ORACLE_SID)设置为源数据库,然后运行备份:cd <Shared_location> nohup sh dbmig_driver_m5.sh L0 & -
如果不使用共享 NFS,请将工作目录复制到目标主机。
-
恢复目标系统上的数据文件。
在目标上,将环境设置为目标数据库。驱动程序脚本将创建恢复脚本。它存储在 cmd 目录中:
cd <Shared_location>/XTTS_Migration cp nohup.out nohup.out_L0 ls -ltra cmd/restore_L0_* rman target / cmdfile=<restore_cmdfile_name>检查 RMAN 日志文件:
egrep "WARN-|ORA-" log/restore_*.log
任务 3.3:前滚阶段
在此阶段,将在源数据库上创建增量备份,并将其传输到目标系统。
备份将转换为目标 endian 格式并应用于目标数据文件。可以多次重复此过程以使目标数据库保持同步。
每个增量备份都比上一个备份小,并减少最终停机时间窗口。
注:可以在不将多个备份应用于目标的情况下针对源执行多个备份。
- 在源上,执行源数据库的级别 1 (L1) 增量备份:
cd <Shared_location>/XTTS_Migration
cp nohup.out nohup.out_1
nohup sh dbmig_driver_m5.sh L1 &
-
如果不使用共享 NFS,请将工作目录复制到目标主机。
-
将增量备份应用于目标系统上的数据文件副本。在目标系统上,以设置了相应环境变量的 Oracle 用户身份登录,按如下方式运行“前滚数据文件”步骤。
在目标系统上,以设置了相应环境变量的 Oracle 用户身份登录。驱动程序脚本将创建恢复脚本。它存储在 cmd 目录中:使用最新的还原脚本在目标数据库上还原级别 1 (L1) 备份。
cd <Shared_location>/XTTS_Migration
ls -ltra cmd/restore_L1_*
cp nohup.out nohup.out_3
rman target / cmdfile=<restore_cmdfile_name>
检查 RMAN 日志文件:
egrep "WARN-|ORA-" log/restore_*.log
前滚步骤连接到目标数据库,并对所传输的每个表空间的数据文件应用增量备份。
重复前滚阶段,直到数据库切换窗口。
任务 3.4:最终增量备份阶段
- 在导入完成之前,在源和目标上禁用以下审计相关参数。在导入完成后重新启用它们:
show parameter audit_sys_operations
show parameter audit_trail
alter system set audit_trail=none scope=spfile sid='*';
alter system set audit_sys_operations=FALSE scope=spfile sid='*';
srvctl stop database -d ${ORACLE_UNQNAME}
srvctl start database -d ${ORACLE_UNQNAME}
show parameter audit_sys_operations
show parameter audit_trail
- 在源上,执行源数据库的最终级别 1 (L1) 增量备份:
该脚本执行以下操作:- 系统密码提示 - 将表空间设置为只读模式 - 执行最终增量备份 - 运行数据泵导出
cd <Shared_location>/XTTS_Migration
cp nohup.out nohup.out_1
nohup sh dbmig_driver_m5.sh L1F &
-
如果不使用共享 NFS,请将工作目录复制到目标主机。
-
将上次增量备份应用于目标数据文件。
在目标上,将环境设置为目标数据库。驱动程序脚本将创建恢复脚本。它存储在 cmd 目录中:
cd <Shared_location>/XTTS_Migration
ls -ltra cmd/restore_L1F_*
使用最终还原脚本在目标数据库上还原最终级别 1 (L1) 备份。
cd <Shared_location>/XTTS_Migration
cp nohup.out nohup.out_5
nohup rman target / cmdfile=<restore_cmdfile_name> &
检查 RMAN 日志文件:
egrep "WARN-|ORA-" log/restore_*.log
任务 3.5:数据泵导入
-
在目标上,编辑导入驱动程序脚本 (impdp.sh)。使用有关目标数据库的信息填充变量。
ORACLE_HOME:Oracle 主目录路径ORACLE_SID:目标数据库 SIDORACLE_CONNECT_STRING:连接字符串DATA_PUMP_PARALLEL:并行级别DATA_PUMP_TRACE:跟踪级别
导入驱动程序脚本接受四个参数:
expdp_dumpfile: Name of the Data Pump dump file, e.g., exp_UP19_240206134155.dmp
rman_last_restore_log: Relative path to the last RMAN restore log
run-mode: One of the below:
test: Generates the Data Pump parameter file. Does not start Data Pump.
test-readonly. Generates the Data Pump parameter file and adds TRANSPORTABLE=KEEP_READ_ONLY to the Data Pump parameter file. Review the documentation for the usage of this parameter. Does not start Data Pump.
run: Generates the Data Pump parameter file. Starts Data Pump to perform the import.
run-readonly: Generates the Data Pump parameter file and adds TRANSPORTABLE=KEEP_READ_ONLY to the Data Pump parameter file. Review the documentation for the usage of this parameter. Starts Data Pump to perform the import.
DP_ENC_PROMPT:
One of the below
Y: Will prompt the user for an encryption password in case one was used for the export
N: Will not prompt the user for an encryption password.
在测试模式下启动导入驱动程序脚本,以验证生成的数据泵参数文件的正确性:
cd <Shared_location>/XTTS_Migration
sh impdp.sh <expdp_dumpfile> <rman_last_restore_log> test N
驱动程序脚本会在当前目录中生成参数文件。查看它。
$ vi imp_<oracle_sid>_<timestamp>_xtts.par
请勿更改生成的数据泵参数文件。如果需要更改参数文件,请更改驱动程序脚本中的代码,以便生成所需的参数文件。
在运行模式下启动导入驱动程序脚本以执行数据泵导入:
cd <Shared_location>/XTTS_Migration
sh impdp.sh <expdp_dumpfile> <rman_last_restore_log> run N
始终查看数据泵日志文件。即使数据泵被列为成功,也应始终检查数据泵日志文件是否存在任何严重错误。
- 导入完成后,在源数据库和目标数据库上重新启用审计参数。
show parameter audit_sys_operations
show parameter audit_trail
alter system set audit_trail=<value before migration taken above> scope=spfile sid='*';
alter system set audit_sys_operations=<value before migration taken above> scope=spfile sid='*';
srvctl stop database -d ${ORACLE_UNQNAME}
srvctl start database -d ${ORACLE_UNQNAME}
show parameter audit_sys_operations
show parameter audit_trail
- 验证传输的数据。
rman target sys/<password>@<target_db_name> trace=rman_trace.trc log=<backup_location>/tablespace_validate.log
validate tablespace <comma-separated tablespace list> check logical;
- 分配用户表空间以恢复在目标数据库准备过程中所做的更改。
select 'alter user '||username||' default tablespace users;' from dba_users where default_tablespace='USERS_OCI';
Execute the alter commands generated by above select query.
select count(*) from dba_users where default_tablespace='USERS_OCI';
ALTER DATABASE DEFAULT TABLESPACE USERS;
drop tablespace USERS_OCI including contents and datafiles;
select TABLESPACE_NAME from dba_tablespaces where TABLESPACE_NAME='USERS';
验证源数据库和目标数据库中的数据。
相关链接
确认
- 作者 — Pavan Yennampelli(首席云工程师)
更多学习资源
通过 docs.oracle.com/learn 浏览其他实验室,或者通过 Oracle Learning YouTube 频道访问更多免费学习内容。此外,请访问 education.oracle.com/learning-explorer 以成为 Oracle Learning Explorer。
有关产品文档,请访问 Oracle 帮助中心。
Migrate Oracle Database to OCI Using M5 Cross-Endian XTTS with RMAN Incremental Backups
G56678-01