原 【DB宝52】Oracle异构平台迁移利器之XTTS(使用rman方式)
Tags: Oracle原创LinuxDocker小麦苗迁移XTTS
- 2.3、XTTS 第1~n次增量前滚
- 2.3.1、产生增量数据
- 2.3.2、源端做增量备份
- 2.3.3、将源端的增量数据传到目标端
- 2.3.4、目标端进行增量转换和数据写入同步
- 2.3.5、源端确定下一个增量备份的FROM_SCN
- 2.4、XTTS 最后一次增量前滚
- 2.4.1、将表空间置为RO状态
- 2.4.2、源端做增量备份
- 2.4.3、将源端的增量数据传到目标端
- 2.4.4、目标端进行增量转换和数据写入同步
- 2.5、迁移元数据
- 2.5.1、在目标库创建业务用户
- 2.5.2、导入xtts的元数据
- 2.5.3、导入存储过程、触发器、函数、包、视图、序列
- 2.5.4、导入公共同义词和dblink等其它对象
- 2.6、迁移完成后的收尾工作
- 2.6.1、查看源端、目标端的数据一致性
- 2.6.2、更改用户默认表空间
- 2.6.3、目标库的表空间修改为读写模式
- 2.6.4、校验数据文件完整性
- 2.6.5、收集统计信息
- 2.7、总结
2.3、XTTS 第1~n次增量前滚
在此阶段,在源端做增量数据,从源数据库创建增量备份(内部其实是仍然使用rman增量备份),将其传输到目标端,在目标端转换为目标系统Endian格式,然后应用于转换后的目标数据文件副本,将其前滚。此阶段可以多次重复运行。每次连续的增量备份都应该比以前的增量备份花费更少的时间,并且将使目标数据文件副本与源数据库更加一致。这样对于目标库上的数据文件拷贝,通过一次次应用增量数据就可以逐渐追上源库的生产数据。
这个阶段中的步骤可以运行多次,以使目标中的datafiles更接近源文件的时间/ SCN。在此阶段,源数据库完全可访问。
2.3.1、产生增量数据
1 2 3 | -- 产生增量数据 create table lhr.testxtts6 tablespace users as select * from dual; |
2.3.2、源端做增量备份
开始做增量备份:
1 2 3 | cd /home/oracle/scripts export TMPDIR=/home/oracle/scripts $ORACLE_HOME/perl/bin/perl xttdriver.pl -i |
上面的操作还会在 TMPDIR 目录下产生xttplan.txt.new、tsbkupmap.txt和incrbackups.txt文件:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | [oracle@lhrora11203 scripts]$ cd /home/oracle/scripts [oracle@lhrora11203 scripts]$ export TMPDIR=/home/oracle/scripts [oracle@lhrora11203 scripts]$ $ORACLE_HOME/perl/bin/perl xttdriver.pl -i ============================================================ trace file is /home/oracle/scripts/incremental_Apr13_Tue_10_41_37_372//Apr13_Tue_10_41_37_372_.log ============================================================= -------------------------------------------------------------------- Parsing properties -------------------------------------------------------------------- -------------------------------------------------------------------- Done parsing properties -------------------------------------------------------------------- -------------------------------------------------------------------- Checking properties -------------------------------------------------------------------- -------------------------------------------------------------------- Done checking properties -------------------------------------------------------------------- -------------------------------------------------------------------- Backup incremental -------------------------------------------------------------------- ============================================================ No new datafiles added ============================================================= Prepare newscn for Tablespaces: 'TS_LHR' Prepare newscn for Tablespaces: 'TS_XXT' Prepare newscn for Tablespaces: 'USERS' Prepare newscn for Tablespaces: '''' Prepare newscn for Tablespaces: '''' -------------------------------------------------------------------- Starting incremental backup -------------------------------------------------------------------- -------------------------------------------------------------------- Done backing up incrementals -------------------------------------------------------------------- [oracle@lhrora11203 scripts]$ more xttplan.txt.new TS_LHR::::2921361 6 TS_XXT::::2921387 7 USERS::::2921413 4 [oracle@lhrora11203 scripts]$ more tsbkupmap.txt USERS::4:::1=32vs6cfc_1_1 TS_XXT::7:::1=30vs6cf9_1_1 TS_LHR::6:::1=2uvs6cf5_1_1 [oracle@lhrora11203 scripts]$ more incrbackups.txt /u01/app/xtts/inc_bk/32vs6cfc_1_1 /u01/app/xtts/inc_bk/30vs6cf9_1_1 /u01/app/xtts/inc_bk/2uvs6cf5_1_1 [oracle@lhrora11203 scripts]$ ll /u01/app/xtts/inc_bk/ -h total 29M -rw-r----- 1 oracle oinstall 40K Apr 13 10:41 2uvs6cf5_1_1 -rw-r----- 1 oracle oinstall 9.5M Apr 13 10:41 2vvs6cf6_1_1 -rw-r----- 1 oracle oinstall 40K Apr 13 10:41 30vs6cf9_1_1 -rw-r----- 1 oracle oinstall 9.5M Apr 13 10:41 31vs6cfa_1_1 -rw-r----- 1 oracle oinstall 88K Apr 13 10:41 32vs6cfc_1_1 -rw-r----- 1 oracle oinstall 9.5M Apr 13 10:41 33vs6cfe_1_1 [oracle@lhrora11203 scripts]$ rman target / Recovery Manager: Release 11.2.0.3.0 - Production on Tue Apr 13 10:46:27 2021 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. connected to target database: LHR11G (DBID=2006729750) RMAN> list backupset; using target database control file instead of recovery catalog List of Backup Sets =================== BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ ------------------- 66 Incr 32.00K DISK 00:00:00 2021-04-13 10:41:41 BP Key: 66 Status: AVAILABLE Compressed: NO Tag: TTS_INCR_UPDATE Piece Name: /u01/app/xtts/inc_bk/2uvs6cf5_1_1 Keep: NOLOGS Until: 2021-04-20 10:41:41 List of Datafiles in backup set 66 File LV Type Ckp SCN Ckp Time Name ---- -- ---- ---------- ------------------- ---- 6 Incr 2922376 2021-04-13 10:41:41 /u01/app/oracle/oradata/LHR11G/ts_lhr01.dbf BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ ------------------- 67 Incr 9.39M DISK 00:00:01 2021-04-13 10:41:43 BP Key: 67 Status: AVAILABLE Compressed: NO Tag: TTS_INCR_UPDATE Piece Name: /u01/app/xtts/inc_bk/2vvs6cf6_1_1 Keep: NOLOGS Until: 2021-04-20 10:41:42 Control File Included: Ckp SCN: 2922379 Ckp time: 2021-04-13 10:41:42 BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ ------------------- 68 Incr 32.00K DISK 00:00:00 2021-04-13 10:41:45 BP Key: 68 Status: AVAILABLE Compressed: NO Tag: TTS_INCR_UPDATE Piece Name: /u01/app/xtts/inc_bk/30vs6cf9_1_1 Keep: NOLOGS Until: 2021-04-20 10:41:44 List of Datafiles in backup set 68 File LV Type Ckp SCN Ckp Time Name ---- -- ---- ---------- ------------------- ---- 7 Incr 2922404 2021-04-13 10:41:45 /u01/app/oracle/oradata/LHR11G/ts_xxt01.dbf BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ ------------------- 69 Incr 9.39M DISK 00:00:01 2021-04-13 10:41:47 BP Key: 69 Status: AVAILABLE Compressed: NO Tag: TTS_INCR_UPDATE Piece Name: /u01/app/xtts/inc_bk/31vs6cfa_1_1 Keep: NOLOGS Until: 2021-04-20 10:41:46 Control File Included: Ckp SCN: 2922408 Ckp time: 2021-04-13 10:41:46 BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ ------------------- 70 Incr 80.00K DISK 00:00:00 2021-04-13 10:41:48 BP Key: 70 Status: AVAILABLE Compressed: NO Tag: TTS_INCR_UPDATE Piece Name: /u01/app/xtts/inc_bk/32vs6cfc_1_1 Keep: NOLOGS Until: 2021-04-20 10:41:48 List of Datafiles in backup set 70 File LV Type Ckp SCN Ckp Time Name ---- -- ---- ---------- ------------------- ---- 4 Incr 2922432 2021-04-13 10:41:48 /u01/app/oracle/oradata/LHR11G/users01.dbf BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ ------------------- 71 Incr 9.39M DISK 00:00:01 2021-04-13 10:41:51 BP Key: 71 Status: AVAILABLE Compressed: NO Tag: TTS_INCR_UPDATE Piece Name: /u01/app/xtts/inc_bk/33vs6cfe_1_1 Keep: NOLOGS Until: 2021-04-20 10:41:49 Control File Included: Ckp SCN: 2922436 Ckp time: 2021-04-13 10:41:50 RMAN> |
2.3.3、将源端的增量数据传到目标端
这里传递增量数据的时候,还需要将源端/home/oracle/scripts/目录下的 xttplan.txt、 tsbkupmap.txt和incrbackups.txt文件都传输到目标端。每当你进行一次增量的备份操作,这 3个文件的内容都会发现变化 。
每一次增量操作之后,都需要将这 3个文件传到目标端数据库的 /home/oracle/scripts/目录中。
1 2 3 4 5 6 | -- 注意:增量内容应该拷贝到目标端的全量备份路径下 scp /u01/app/xtts/inc_bk/* 172.17.0.4:/u01/app/xtts/df_bk/ scp /home/oracle/scripts/xttplan.txt 172.17.0.4:/home/oracle/scripts/ scp /home/oracle/scripts/tsbkupmap.txt 172.17.0.4:/home/oracle/scripts/ scp /home/oracle/scripts/incrbackups.txt 172.17.0.4:/home/oracle/scripts/ |
2.3.4、目标端进行增量转换和数据写入同步
1 2 3 4 | export XTTDEBUG=1 cd /home/oracle/scripts export TMPDIR=/home/oracle/scripts $ORACLE_HOME/perl/bin/perl xttdriver.pl -r |
如果一套库上有多个实例的话,在执行该步骤之前,需要对环境变量进行确认,如检查当前ORACLE_SID是否是需要执行的SID,否则可能会恢复到其他实例上。(并非是真实的恢复,因为其他实例跟这个备份集没有任何关系,但恢复的过程会在其他实例上进行一遍,如关闭/启动数据库,包括增量恢复的日志都会在另一个数据库上显示。)如果发生了这种事情,不用紧张,调整好环境变量,再执行一次perl xttdriver.pl –r即可。误操作的实例不受影响。
注:
1.每次增量时都必须复制xttplan.txt、tsbkupmap.txt和incrbackups.txt,因为它们的内容在每次增量时都是不同的。
2.不修改、不复制文件incrbackups.txt.new。
3.该过程每次执行都会重启目标数据库。
4.如果重新开始,那么需要删除/home/oracle/scripts/FAILED
5.XTTDEBUG=1为打开debug模式,进行调试。Debug 模式可以打印更多的屏幕输出,并且开启 RMAN 的 debug 模式。要启用 debug 模式,或者以 -d 参数运行 xttdriver.pl 或者在运行 xttdriver.pl 前设置环境变量 XTTDEBUG=1。这个参数接受3种级别,-d[1/2/3]级别3会显示最多的信息。
执行过程:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | [oracle@lhrora11204 scripts]$ cd /home/oracle/scripts [oracle@lhrora11204 scripts]$ export TMPDIR=/home/oracle/scripts [oracle@lhrora11204 scripts]$ $ORACLE_HOME/perl/bin/perl xttdriver.pl -r ============================================================ trace file is /home/oracle/scripts/rollforward_Apr13_Tue_10_50_27_215//Apr13_Tue_10_50_27_215_.log ============================================================= -------------------------------------------------------------------- Parsing properties -------------------------------------------------------------------- -------------------------------------------------------------------- Done parsing properties -------------------------------------------------------------------- -------------------------------------------------------------------- Checking properties -------------------------------------------------------------------- -------------------------------------------------------------------- Done checking properties -------------------------------------------------------------------- -------------------------------------------------------------------- Start rollforward -------------------------------------------------------------------- -------------------------------------------------------------------- End of rollforward phase -------------------------------------------------------------------- |
2.3.5、源端确定下一个增量备份的FROM_SCN
1 2 3 | cd /home/oracle/scripts export TMPDIR=/home/oracle/scripts $ORACLE_HOME/perl/bin/perl xttdriver.pl -s |
该步骤会计算下一个FROM_SCN,将其记录在xttplan.txt文件中,然后在创建下一个增量备份时使用该SCN。
源库执行第一次增量,报错
RMAN-03023: executing command: SET NOCFAU
RMAN-06009: using target database control file instead of recovery catalog
ts::APP_IDX
RMAN-06134: host command complete
RMAN-03090: Starting backup at 2022-06-30 16:29:14
RMAN-08030: allocated channel: ORA_DISK_1
RMAN-08500: channel ORA_DISK_1: SID=17307 device type=DISK
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of backup command at 06/30/2022 16:29:14
RMAN-20202: Tablespace not found in the recovery catalog
RMAN-06019: could not translate tablespace name "APP_IDX"
nice
脚本下载位置:https://share.weiyun.com/57HUxNi , 路径:小麦苗分享的资料>数据库系列>Oracle数据库>Oracle工具。
很不错哈