Oracle异构平台迁移利器之XTTS(使用rman方式)

2022-11-07 18:57:25 浏览数 (2)

目录

代码语言:javascript复制
一、XTTS简介
  1.1、简介
  1.2、全量迁移方式
  1.3、脚本rman_xttconvert_v3.zip
    1.3.1、xttdriver.pl的选项
    1.3.2、xtt.properties参数
    1.3.3、文件介绍
  1.4、参考文档
  1.5、迁移过程导图
二、XTTS迁移示例
  2.1、数据库检查
    2.1.1、查询平台字节序和字符集
    2.1.2、获取需要迁移的业务表空间和业务用户
    2.1.3、表空间自包含
    2.1.4、获取用户及其权限的SQL
    2.1.5、检查环境变量
    2.1.6、开启块改变跟踪功能
    2.1.7、时区需要一致
    2.1.8、目标端补丁情况
    2.1.9、组件检查
    2.1.10、目标端的db_files参数不能小于源端
    2.1.11、迁移对象个数统计
  2.2、全量迁移
    2.2.1、源端和目标端都需要配置XTTS脚本
    2.2.2、源端调用 xttdriver.pl  -p做迁移准备
    2.2.3、将源端的数据文件副本和rmanconvert.cmd传到目标端
    2.2.4、在目标端对数据文件拷贝进行字节序的转换
  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、总结

一、XTTS简介

1.1、简介

XTTS(Cross Platform Transportable Tablespaces)属于跨平台迁移表空间,它是从Oracle 8i开始就引入的一种基于表空间传输的物理迁移方法,命名为TTS,经历各个版本的不断演进,从11gR2开始,在相对停机时间要求日益减少的情况,为了应对越来越大的数据量跨平台迁移,Oracle推出了新的解决方案—加强版TTS(以下简称XTTS),XTTS使用增量备份的方式实现跨平台的数据迁移,从真正意义上大大缩短停机时间。在U2L如火如荼的今天,通过XTTS快捷、高效、平稳、安全的将Oracle数据库“小型机 集中式存储”环境迁移至“X86架构平台 分布式存储”已然成为一大神技。

XTTS的发展历史:

  • 从8i,tts技术的诞生,引入了相同平台相同块大小之间的表空间传输。到了9i,tts开始支持同平台中,不同块大小的表空间传输。
  • 10g时代,不仅引入了跨平台的表空间传输方案,也就是我们说的xtts;10gR2开始支持传输整个数据库。
  • 11gR1开始,可以传输表空间中的某个特定分区。
  • 在11.2.0.4开始,为了应对越来越大的数据量,而停机时间甚至还在减少的情况,出现了新的解决方案—使用增量备份方式的xtts。

XTTS 各版本的功能比对如下:

在 Oracle11gR2(推荐使用 11.2.0.4 及之后版本)以后,Oracle 推出了通过前滚数据文件,拷贝数据后再进行多次增量备份的 XTTS 来完成迁移过程,在这个过程中通过开启块跟踪特性,根据 SCN 号来执行一系列的增量备份,并且通过对块跟踪文件的扫描,来完成增量数据的增量备份应用,最后在通过一定的停机时间,在源库 read only 的状态下进行最后一次增量备份转换应用,使得整个迁移过程的停机时间同源库数据块的变化率成正比。这样大大的缩短了停机时间。

为了减少正式的停机时间,oracle在xtts中引入了rman的增量备份前滚功能。通过一次又一次的增量备份,使停应用的时间主要包含四个方面:将表空间置为只读,最后进行一次增量前滚,元数据导入,数据文件校验。和传统的表空间传输相比,通过减少数据文件的传输时间,而大大减少了整体停机时间。

1.2、全量迁移方式

对于XTTS的全量操作,Oracle提供了2种方式来进行,分别如下: 1)dbms_file_transfer(DFT) -- (using xttdriver.pl -S and -G options)

DBMS_FILE_TRANSFER 包是 Oracle 提供的一个用于复制二进制数据库文件或在数据库之间传输二进制文件的程序包,在 XTTS 迁移中,利用不同的参数进行数据文件传输转换完成迁移。

要求:目标端数据库版本必须是11.2.0.4以及更新的版本。如果数据库版本低于11.2.0.4(大于Oracle10R1),那么目标端环境,仍然需要安装11.2.0.4以及更新版本的临时环境,因为XTTS增量的核心脚本功能必须是基于11.2.0.4( )版本。

如果准备使用DDBMS_FILE_TRANSFER 作为全量迁移方法,那么必须创建三个数据库对象:

  1. 源数据库中的数据库目录对象。
  2. 目标数据库中的数据库目录对象,放置数据文件的位置。
  3. 在目标数据库中创建指向源库的数据库链接。

2)RMAN(Recovery Manager )备份 -- (using xttdriver.pl -p and -c options)

通过使用 rman-xttconvert 包提供的参数,对数据库进行基于表空间的备份,将备份产生的备份集写到本地或者 NFS 盘上,然后再通过 rman-xttconvert 包中包含的不同平台之间数据文件格式转换的包对进行数据文件格式转换,最后通过记录的表空间 FILE_ID 号生产元数据的导入脚本,通过 db_link 执行完成。

1.3、脚本rman_xttconvert_v3.zip

XTTS基于一组 rman-xttconvert_3.0 的脚本文件包(Mos 1389592.1)来实现跨平台的数据迁移,主要包含 Perl脚本xttdriver 脚本。xttdriver.pl 是备份、转换和增量应用的执行脚本,xtt.properties 是属性文件,其中包含 XTTS 配置的路径、参数等。

脚本下载地址:11G - Reduce Transportable Tablespace Downtime using Cross Platform Incremental Backup (Doc ID 1389592.1),内容参考:http://blog.itpub.net/26736162/viewspace-2767429/

脚本rman_xttconvert_v3.zip在小麦苗的微云下载:https://share.weiyun.com/57HUxNi,路径:小麦苗分享的资料>数据库系列>Oracle数据库>Oracle工具。

1.3.1、xttdriver.pl的选项

1.3.2、xtt.properties参数

1.3.3、文件介绍

  • xttplan.txt - containing the tablespace names, their current SCNs and their datafile numbers
  • xttnewdatafiles.txt - containing the tablespace names, datafile numbers, the destination directory object name and the source filenames
  • getfile.sql - The PL/SQL script(formatting ours) that will be used at the destination to get the datafilesfrom the source
  • xttpreparesrc.sql - the PL/SQL scriptused to create the files in this step
  • xttprepareNaNd - the command
  • tsbkupmap.txt - containing the tablespace names, datafile numbers and the incremental backup pieces
  • incrbackups.txt - containing the actual location of the incremental backup pieces
  • rmanincrNaNd - containing the RMAN scripts used to create the incremental backups.
  • xttdetnewfromscnsrc.sql - the PL/SQLscript used to create the files in this step
  • xttplan.txt.new- after the first run of'xttdriver.pl -i' this is just a copy of the xttplan.txt

1.4、参考文档

  • 11G - Reduce Transportable Tablespace Downtime using Cross Platform Incremental Backup (文档 ID 1389592.1)
  • 12c – 使用跨平台增量备份来减少传输表空间的停机时间 (文档 ID 2102859.1)
  • 12C - Reduce Transportable Tablespace Downtime using Cross Platform Incremental Backup (文档 ID 2005729.1)

http://blog.itpub.net/26736162/viewspace-2767646/

http://blog.itpub.net/26736162/viewspace-2767429/

1.5、迁移过程导图

二、XTTS迁移示例

环境情况如下:

源库

目标库

版本

11.2.0.3

11.2.0.4

ORACLE_SID

LHR11G

LHR11G

用户表空间

TS_LHR、TS_XXT、USERS

TS_LHR、TS_XXT、USERS

业务用户

lhr、xxt

lhr、xxt

平台

Linux x86 64-bit

Linux x86 64-bit

字节序

Little

Little

IP地址

172.17.0.3

172.17.0.4

字符集

AMERICAN_CHINA.AL32UTF8

AMERICAN_CHINA.AL32UTF8

归档模式

归档模式

归档模式

注:虽然我这里使用的同构平台,但是异构平台下的步骤是一样的,例如从Aix到Linux,该过程完全适用。

2.1、数据库检查

  • 源库必须为归档模式
  • 源端和目标的字符集需要一致
  • 源库的操作系统不是Windows
  • 源库的compatible参数最低为11.1.0.0.0
  • 源库的RMAN 配置里DEVICE TYPE DISK不能设置为COMPRESSED
  • 源端和目标端必须支持可传输平台
  • 源端需要迁移的表空间需要自包含
  • 源库开启块改变跟踪功能,加快增量备份的速度
  • 源端和目标端时区需要保持一致
  • 目标端建议打最新的PSU补丁
  • 目标端的db_files参数不能小于源端
  • 要迁移的表空间的数据文件必须都是online或者不包含offline的数据文件
  • 检查源数据库和目标库具有重名的表空间
  • 检查是否存在应用用户建在system,sysaux,users上的情况
  • 基于XMLSchema的XMLType对象检查
  • 失效对象检查
  • 迁移对象统计
  • 无论是源还是目标,GLOGIN.sql的存在都可能导致语法错误
  • 源库的版本不能大于目标库的版本

2.1.1、查询平台字节序和字符集

代码语言:javascript复制
-- 查询平台和字节序
col PLATFORM_NAME format a30
SELECT d.PLATFORM_ID,d.PLATFORM_NAME, tp.ENDIAN_FORMAT
     FROM V$TRANSPORTABLE_PLATFORM tp, V$DATABASE d
     WHERE tp.PLATFORM_NAME = d.PLATFORM_NAME;

-- 查询字符集
select userenv('language') from dual;

2.1.2、获取需要迁移的业务表空间和业务用户

排除系统表空间,避免冲突:

代码语言:javascript复制
select TABLESPACE_NAME,BLOCK_SIZE,CONTENTS,STATUS
from dba_tablespaces
where tablespace_name not in ('SYSTEM','SYSAUX','UNDOTBS1','TEMP','EXAMPLE');


select owner,tablespace_name,count(*)
from dba_segments 
where  tablespace_name not in ('SYSTEM','SYSAUX','UNDOTBS1','TEMP','EXAMPLE')
group by owner,tablespace_name order by tablespace_name;

目标端需要删除已存在的和源库同名的表空间:

代码语言:javascript复制
drop tablespace users including contents and datafiles;
drop tablespace ts_lhr including contents and datafiles;
drop tablespace ts_xxt including contents and datafiles;

select tablespace_name,status from dba_tablespaces;

2.1.3、表空间自包含

需要传输的表空间为TS_LHR、TS_XXT、USERS,要确保这3个表空间为自包含的表空间。

代码语言:javascript复制
-- 自包含检查
exec dbms_tts.transport_set_check('TS_LHR,TS_XXT,USERS',true);

-- 查看结果,结果为空,表示为自包含
col violations for a70
select * from transport_set_violations;

在表空间传输的中,要求表空间集为自包含的,自包含表示用于传输的内部表空间集没有引用指向外部表空间集。

2.1.4、获取用户及其权限的SQL

代码语言:javascript复制
SET LONG 9999
SELECT DBMS_METADATA.GET_DDL('USER', USERNAME) DDL_SQL FROM DBA_USERS 
WHERE USERNAME IN (select owner  from dba_segments 
where  tablespace_name not in ('SYSTEM','SYSAUX','UNDOTBS1','TEMP','EXAMPLE') 
group by owner,tablespace_name) AND USERNAME NOT IN ('SYS');


SELECT DBMS_METADATA.GET_GRANTED_DDL('SYSTEM_GRANT', USERNAME) DDL_SQL FROM DBA_USERS 
WHERE USERNAME IN (select owner  from dba_segments 
where  tablespace_name not in ('SYSTEM','SYSAUX','UNDOTBS1','TEMP','EXAMPLE') 
group by owner,tablespace_name) AND USERNAME NOT IN ('SYS');


SELECT DBMS_METADATA.GET_GRANTED_DDL('ROLE_GRANT', USERNAME) DDL_SQL FROM DBA_USERS 
WHERE USERNAME IN (select owner  from dba_segments 
where  tablespace_name not in ('SYSTEM','SYSAUX','UNDOTBS1','TEMP','EXAMPLE') 
group by owner,tablespace_name) AND USERNAME NOT IN ('SYS');



SELECT DBMS_METADATA.GET_GRANTED_DDL('OBJECT_GRANT', USERNAME) DDL_SQL FROM DBA_USERS 
WHERE USERNAME IN (select owner  from dba_segments 
where  tablespace_name not in ('SYSTEM','SYSAUX','UNDOTBS1','TEMP','EXAMPLE') 
group by owner,tablespace_name) AND USERNAME NOT IN ('SYS');

2.1.5、检查环境变量

确保环境变量配置正确:

代码语言:javascript复制
env | egrep "ORACLE_SID|ORACLE_HOME"

结果:

代码语言:javascript复制
[oracle@lhrora11204 ~]$ env | egrep "ORACLE_SID|ORACLE_HOME"
ORACLE_SID=LHR11G
ORACLE_HOME=/u01/app/oracle/product/11.2.0.4/dbhome_1

2.1.6、开启块改变跟踪功能

Block change tracking 进程记录自从上一次0级备份以来数据块的变化,并把这些信息记录在跟踪文件中。RMAN 使用这个文件判断增量备份中需要备份的变更数据。这极大的提高了备份性能和速度,RMAN 可以不再扫描整个文件以查找变更数据。

代码语言:javascript复制
ALTER DATABASE ENABLE BLOCK CHANGE TRACKING USING  FILE '/u01/app/oracle/changetracking.chg';

col filename format a100
select status, filename from v$block_change_tracking;

2.1.7、时区需要一致

代码语言:javascript复制
select dbtimezone from dual;

2.1.8、目标端补丁情况

建议目标端打最新的PSU补丁。

代码语言:javascript复制
SELECT * FROM dba_registry_history;

2.1.9、组件检查

目标端需要包含源端的所有组件。

代码语言:javascript复制
select comp_id,comp_name,version,status from dba_registry;

2.1.10、目标端的db_files参数不能小于源端

代码语言:javascript复制
show parameter db_files

2.1.11、迁移对象个数统计

需要确认,非业务用户下是否有业务数据,例如SYS用户是否有业务数据:

代码语言:javascript复制
-- 需要迁移的对象和数量
select owner, object_type, count(*)
 from dba_objects
where object_name not like 'BIN%'
 and owner in ('LHR','XXT')
group by owner, object_type
order by 1,2 desc;

-- 无效对象
select owner, object_type, count(*)
 from dba_objects
where status <> 'VALID'
 and owner in ('LHR','XXT')
group by owner, object_type
order by 1, 2 desc;




-- 非业务用户下是否有业务数据
SELECT *
  FROM dba_objects d
 where d.created >= sysdate - 10
   and d.object_name not like 'WR%' 
     and d.owner IN ('SYS','SYSTEM')
 order by d.created desc;

执行过程:

代码语言:javascript复制
SYS@LHR11G> select owner, object_type, count(*)
  2   from dba_objects
  3  where object_name not like 'BIN%'
 and owner in ('LHR','XXT')
group by owner, object_type
  6  order by 1,2 desc;

OWNER                                                        OBJECT_TYPE                              COUNT(*)
------------------------------------------------------------ -------------------------------------- ----------
LHR                                                          VIEW                                            1
LHR                                                          TABLE                                           9
LHR                                                          SYNONYM                                         1
LHR                                                          SEQUENCE                                        1
LHR                                                          PROCEDURE                                       2
XXT                                                          TABLE                                           2

6 rows selected.

SYS@LHR11G> 
SYS@LHR11G> select owner, object_type, count(*)
  2   from dba_objects
where status <> 'VALID'
 and owner in ('LHR','XXT')
group by owner, object_type
  6  order by 1, 2 desc;

OWNER                                                        OBJECT_TYPE                              COUNT(*)
------------------------------------------------------------ -------------------------------------- ----------
LHR                                                          PROCEDURE                                       1

2.2、全量迁移

在此步骤中,表空间的数据文件将从源端数据库传输到目标端数据库,本步骤只需要执行一次,数据文件传输过程中不影响源端数据库正常访问。

此处有2种方法:dbms_file_transfer和rman方法。对于数据文件很多的情况下来说,dbms_file_transfer是推荐的方法。

此处使用rman方式。

2.2.1、源端和目标端都需要配置XTTS脚本

代码语言:javascript复制
rm -rf /u01/app/xtts/
rm -rf /home/oracle/scripts

mkdir -p /u01/app/xtts/inc_bk*
mkdir -p /u01/app/xtts/df_bk

mkdir -p /home/oracle/scripts
cd /home/oracle/scripts

cp ~/rman_xttconvert_v3.zip /home/oracle/scripts
unzip rman_xttconvert_v3.zip


-- 注意修改相应参数
cat > /home/oracle/scripts/xtt.properties  <<"EOF"
tablespaces=TS_LHR,TS_XXT,USERS
platformid=13
#srcdir=SOURCEDIR
#dstdir=DESTDIR
#srclink=ttslink
dfcopydir=/u01/app/xtts/df_bk
backupformat=/u01/app/xtts/inc_bk
stageondest=/u01/app/xtts/df_bk
storageondest=/u01/app/oracle/oradata/LHR11G
backupondest=/u01/app/xtts/inc_bk
#cnvinst_home=/oracle/app/oracle/product/11.2.0/dbhome_1
#cnvinst_sid=targetdb
EOF

2.2.2、源端调用 xttdriver.pl -p做迁移准备

首先,确保源库处于OPEN阶段,所有表空间都处于online状态:

代码语言:javascript复制
select 'ALTER TABLESPACE '||name||' READ WRITE;' exec_sql
from v$tablespace 
where NAME not in ('SYSTEM','SYSAUX','UNDOTBS1','TEMP');


SYS@LHR11G> select tablespace_name,status from dba_tablespaces;

TABLESPACE_NAME                                              STATUS
------------------------------------------------------------ ------------------
SYSTEM                                                       ONLINE
SYSAUX                                                       ONLINE
UNDOTBS1                                                     ONLINE
TEMP                                                         ONLINE
USERS                                                        ONLINE
EXAMPLE                                                      ONLINE
TS_LHR                                                       ONLINE
TS_XXT                                                       ONLINE

8 rows selected.

在源端执行 xttdriver.pl -p做迁移准备:

代码语言:javascript复制
cd /home/oracle/scripts
export TMPDIR=/home/oracle/scripts
$ORACLE_HOME/perl/bin/perl xttdriver.pl -p

过程:

代码语言:javascript复制
[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 -p
============================================================
trace file is /home/oracle/scripts/prepare_Apr13_Tue_10_25_02_720//Apr13_Tue_10_25_02_720_.log
=============================================================

--------------------------------------------------------------------
Parsing properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Done parsing properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Checking properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Done checking properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Starting prepare phase
--------------------------------------------------------------------

Prepare source for Tablespaces:
                  'TS_LHR'  /u01/app/xtts/df_bk
xttpreparesrc.sql for 'TS_LHR' started at Tue Apr 13 10:25:02 2021
xttpreparesrc.sql for  ended at Tue Apr 13 10:25:02 2021
Prepare source for Tablespaces:
                  'TS_XXT'  /u01/app/xtts/df_bk
xttpreparesrc.sql for 'TS_XXT' started at Tue Apr 13 10:25:06 2021
xttpreparesrc.sql for  ended at Tue Apr 13 10:25:06 2021
Prepare source for Tablespaces:
                  'USERS'  /u01/app/xtts/df_bk
xttpreparesrc.sql for 'USERS' started at Tue Apr 13 10:25:10 2021
xttpreparesrc.sql for  ended at Tue Apr 13 10:25:10 2021
Prepare source for Tablespaces:
                  ''''  /u01/app/xtts/df_bk
xttpreparesrc.sql for '''' started at Tue Apr 13 10:25:13 2021
xttpreparesrc.sql for  ended at Tue Apr 13 10:25:14 2021
Prepare source for Tablespaces:
                  ''''  /u01/app/xtts/df_bk
xttpreparesrc.sql for '''' started at Tue Apr 13 10:25:15 2021
xttpreparesrc.sql for  ended at Tue Apr 13 10:25:15 2021

--------------------------------------------------------------------
Done with prepare phase
--------------------------------------------------------------------


--------------------------------------------------------------------
Find list of datafiles in system
--------------------------------------------------------------------


--------------------------------------------------------------------
Done finding list of datafiles in system
--------------------------------------------------------------------


[oracle@lhrora11203 scripts]$ ll /u01/app/xtts/df_bk/*
-rw-r----- 1 oracle oinstall 10493952 Apr 13 10:25 /u01/app/xtts/df_bk/TS_LHR_6.tf
-rw-r----- 1 oracle oinstall 31465472 Apr 13 10:25 /u01/app/xtts/df_bk/TS_XXT_7.tf
-rw-r----- 1 oracle oinstall  5251072 Apr 13 10:25 /u01/app/xtts/df_bk/USERS_4.tf

该操作执行过程包括以下内容:

1、此过程会将相关的表空间文件执行一次镜像拷贝过程,可以认为是全备,可以在rman中执行“list copy;”查看。此处会把数据文件拷贝一份到/u01/app/xtts/df_bk目录。需要注意目录/u01/app/xtts/df_bk的空间。

代码语言:javascript复制
RMAN> list copy;

specification does not match any control file copy in the repository
specification does not match any archived log in the repository
List of Datafile Copies
=======================

Key     File S Completion Time     Ckp SCN    Ckp Time           
------- ---- - ------------------- ---------- -------------------
28      4    A 2021-04-13 10:25:12 2921413    2021-04-13 10:25:12
        Name: /u01/app/xtts/df_bk/USERS_4.tf
        Tag: PREPARE

26      6    A 2021-04-13 10:25:05 2921361    2021-04-13 10:25:04
        Name: /u01/app/xtts/df_bk/TS_LHR_6.tf
        Tag: PREPARE

27      7    A 2021-04-13 10:25:09 2921387    2021-04-13 10:25:08
        Name: /u01/app/xtts/df_bk/TS_XXT_7.tf
        Tag: PREPARE

2、会在/home/oracle/scripts 目录下产生几个文件,xttplan.txt、rmanconvert.cmd和xttnewdatafiles.txt:

代码语言:javascript复制
[oracle@lhrora11203 scripts]$  ll -lrt
total 220
-rw-r--r-- 1 oracle oinstall   1390 May 24  2017 xttcnvrtbkupdest.sql
-rw-r--r-- 1 oracle oinstall     52 May 24  2017 xttstartupnomount.sql
-rw-r--r-- 1 oracle oinstall  11710 May 24  2017 xttprep.tmpl
-rw-r--r-- 1 oracle oinstall     71 May 24  2017 xttdbopen.sql
-rw-r--r-- 1 oracle oinstall 142020 Sep 20  2018 xttdriver.pl
-rw-r--r-- 1 oracle oinstall  34672 Apr 13 10:24 rman_xttconvert_v3.zip
-rw-r--r-- 1 oracle oinstall    351 Apr 13 10:24 xtt.properties
-rw-r--r-- 1 oracle oinstall     59 Apr 13 10:25 xttplan.txt
-rw-r--r-- 1 oracle oinstall    565 Apr 13 10:25 rmanconvert.cmd
-rw-r--r-- 1 oracle oinstall    163 Apr 13 10:25 xttnewdatafiles.txt
drwxr-xr-x 2 oracle oinstall   4096 Apr 13 10:25 prepare_Apr13_Tue_10_25_02_720

其中 xttplan.txt 文件中的内容如下:

代码语言:javascript复制
[oracle@lhrora11203 scripts]$  more xttplan.txt
TS_LHR::::2921092
6
TS_XXT::::2921119
7
USERS::::2921145
4

该文件中的数值代表数据库的 SCN。如果后面再次运行脚本进行增量操作时,该值会发现改变。

再来看看脚本rmanconvert.cmd的内容:

代码语言:javascript复制
[oracle@lhrora11203 scripts]$ more rmanconvert.cmd
host 'echo ts::TS_LHR'; 
  convert from platform 'Linux x86 64-bit' 
  datafile 
   '/u01/app/xtts/df_bk/TS_LHR_6.tf' 
  format '/u01/app/oracle/oradata/LHR11G/%N_%f.dbf' 
 parallelism 8; 
host 'echo ts::TS_XXT'; 
  convert from platform 'Linux x86 64-bit' 
  datafile 
   '/u01/app/xtts/df_bk/TS_XXT_7.tf' 
  format '/u01/app/oracle/oradata/LHR11G/%N_%f.dbf' 
 parallelism 8; 
host 'echo ts::USERS'; 
  convert from platform 'Linux x86 64-bit' 
  datafile 
   '/u01/app/xtts/df_bk/USERS_4.tf' 
  format '/u01/app/oracle/oradata/LHR11G/%N_%f.dbf' 
 parallelism 8;  

上述脚本是 perl 脚本产生的 rman convert 脚本,需要将该脚本传递到目标端主机。注意,上述脚本文件格式需要注意,同时并行度是默认的,可以进行调整。

2.2.3、将源端的数据文件副本和rmanconvert.cmd传到目标端

将数据文件副本和rmanconvert.cmd文件拷贝到目标端。注意目标端的剩余空间:

代码语言:javascript复制
scp /u01/app/xtts/df_bk/* 172.17.0.4:/u01/app/xtts/df_bk/

scp /home/oracle/scripts/rmanconvert.cmd 172.17.0.4:/home/oracle/scripts/

2.2.4、在目标端对数据文件拷贝进行字节序的转换

注意目标端的空间:

代码语言:javascript复制
cd /home/oracle/scripts
export TMPDIR=/home/oracle/scripts
$ORACLE_HOME/perl/bin/perl xttdriver.pl -c

过程:

代码语言:javascript复制
[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 -c
============================================================
trace file is /home/oracle/scripts/convert_Apr13_Tue_10_31_13_677//Apr13_Tue_10_31_13_677_.log
=============================================================

--------------------------------------------------------------------
Parsing properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Done parsing properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Checking properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Done checking properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Performing convert
--------------------------------------------------------------------


--------------------------------------------------------------------
Converted datafiles listed in: /home/oracle/scripts/xttnewdatafiles.txt
--------------------------------------------------------------------

[oracle@lhrora11204 scripts]$ cat /home/oracle/scripts/xttnewdatafiles.txt
::TS_LHR
6,/u01/app/oracle/oradata/LHR11G/TS_LHR_6.dbf
::TS_XXT
7,/u01/app/oracle/oradata/LHR11G/TS_XXT_7.dbf
::USERS
4,/u01/app/oracle/oradata/LHR11G/USERS_4.dbf
[oracle@lhrora11204 scripts]$ ll -lrt /u01/app/oracle/oradata/LHR11G/*
-rw-r----- 1 oracle oinstall  52429312 Apr 12 22:10 /u01/app/oracle/oradata/LHR11G/redo02.log
-rw-r----- 1 oracle oinstall  52429312 Apr 13 06:00 /u01/app/oracle/oradata/LHR11G/redo03.log
-rw-r----- 1 oracle oinstall  30416896 Apr 13 07:44 /u01/app/oracle/oradata/LHR11G/temp01.dbf
-rw-r----- 1 oracle oinstall 817897472 Apr 13 10:30 /u01/app/oracle/oradata/LHR11G/system01.dbf
-rw-r----- 1 oracle oinstall  10493952 Apr 13 10:31 /u01/app/oracle/oradata/LHR11G/TS_LHR_6.dbf
-rw-r----- 1 oracle oinstall  31465472 Apr 13 10:31 /u01/app/oracle/oradata/LHR11G/TS_XXT_7.dbf
-rw-r----- 1 oracle oinstall   5251072 Apr 13 10:31 /u01/app/oracle/oradata/LHR11G/USERS_4.dbf
-rw-r----- 1 oracle oinstall 382738432 Apr 13 10:31 /u01/app/oracle/oradata/LHR11G/undotbs01.dbf
-rw-r----- 1 oracle oinstall 660611072 Apr 13 10:31 /u01/app/oracle/oradata/LHR11G/sysaux01.dbf
-rw-r----- 1 oracle oinstall   9781248 Apr 13 10:31 /u01/app/oracle/oradata/LHR11G/control01.ctl
-rw-r----- 1 oracle oinstall  52429312 Apr 13 10:31 /u01/app/oracle/oradata/LHR11G/redo01.log

转换后的数据文件拷贝会出现在 xtt.properties 文件中定义的参数 storageondest 下,即最终的数据文件目录。

2.3、XTTS 第1~n次增量前滚

在此阶段,在源端做增量数据,从源数据库创建增量备份(内部其实是仍然使用rman增量备份),将其传输到目标端,在目标端转换为目标系统Endian格式,然后应用于转换后的目标数据文件副本,将其前滚。此阶段可以多次重复运行。每次连续的增量备份都应该比以前的增量备份花费更少的时间,并且将使目标数据文件副本与源数据库更加一致。这样对于目标库上的数据文件拷贝,通过一次次应用增量数据就可以逐渐追上源库的生产数据。

这个阶段中的步骤可以运行多次,以使目标中的datafiles更接近源文件的时间/ SCN。在此阶段,源数据库完全可访问。

2.3.1、产生增量数据

代码语言:javascript复制
-- 产生增量数据
create table lhr.testxtts6 tablespace users as select * from dual;

2.3.2、源端做增量备份

开始做增量备份:

代码语言:javascript复制
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文件:

代码语言:javascript复制
[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/目录中。

代码语言:javascript复制
-- 注意:增量内容应该拷贝到目标端的全量备份路径下
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、目标端进行增量转换和数据写入同步

代码语言:javascript复制
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会显示最多的信息。

执行过程:

代码语言:javascript复制
[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

代码语言:javascript复制
cd /home/oracle/scripts
export TMPDIR=/home/oracle/scripts
$ORACLE_HOME/perl/bin/perl xttdriver.pl -s

该步骤会计算下一个FROM_SCN,将其记录在xttplan.txt文件中,然后在创建下一个增量备份时使用该SCN。

该步骤会将-i时生成的xttplan.txt.new改名为xttplan.txt,并将原来的xttplan.txt备份。

建议在目标端每次做完recover动作后,源端就执行一次该命令,以免遗忘。

代码语言:javascript复制
[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 -s
============================================================
trace file is /home/oracle/scripts/determinescn_Apr13_Tue_10_50_43_110//Apr13_Tue_10_50_43_110_.log
=============================================================

--------------------------------------------------------------------
Parsing properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Done parsing properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Checking properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Done checking properties
--------------------------------------------------------------------

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: ''''
New /home/oracle/scripts/xttplan.txt with FROM SCN's generated

2.4、XTTS 最后一次增量前滚

2.4.1、将表空间置为RO状态

假设我们进行了多次增量操作之后,在停机时间的时候,再将源端数据库中需要传输的表空间设置为只读模式 :

代码语言:javascript复制
-- 产生增量数据
create table lhr.testxtts66 tablespace users as select * from dual;

select 'ALTER TABLESPACE '||name||' READ ONLY;' exec_sql
from v$tablespace 
where NAME not in ('SYSTEM','SYSAUX','UNDOTBS1','TEMP');


SYS@LHR11G> select tablespace_name,status from dba_tablespaces;

TABLESPACE_NAME                                              STATUS
------------------------------------------------------------ ------------------
SYSTEM                                                       ONLINE
SYSAUX                                                       ONLINE
UNDOTBS1                                                     ONLINE
TEMP                                                         ONLINE
USERS                                                        READ ONLY
EXAMPLE                                                      ONLINE
TS_LHR                                                       READ ONLY
TS_XXT                                                       READ ONLY

2.4.2、源端做增量备份

首先对上一次的增量备份目录做迁移:

代码语言:javascript复制
mv /u01/app/xtts/inc_bk /u01/app/xtts/inc_bk1
mkdir -p /u01/app/xtts/inc_bk

开始做增量备份:

代码语言:javascript复制
cd /home/oracle/scripts
export TMPDIR=/home/oracle/scripts
$ORACLE_HOME/perl/bin/perl xttdriver.pl -i

2.4.3、将源端的增量数据传到目标端

这里传递增量数据的时候,还需要将源端/home/oracle/scripts/目录下的 xttplan.txt、 tsbkupmap.txt和incrbackups.txt文件都传输到目标端。每当你进行一次增量的备份操作,这 3个文件的内容都会发现变化 。

每一次增量操作之后,都需要将这 3个文件传到目标端数据库的 /home/oracle/scripts/目录中。

代码语言:javascript复制
-- 注意:增量内容应该拷贝到目标端的全量备份路径下
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.4.4、目标端进行增量转换和数据写入同步

代码语言:javascript复制
cd /home/oracle/scripts
export TMPDIR=/home/oracle/scripts
$ORACLE_HOME/perl/bin/perl xttdriver.pl -r

2.5、迁移元数据

注意在导出时,TRANSPORT_TABLESPACES参数需要的表空间要写全,别遗漏。 在目标端进行IMPDP时,transport_datafiles需要将所有的数据文件添加进去。 如果数据文件很多,人为添加容易出错,可以使用perl xttdriver.pl –e获取全部数据文件列表。

2.5.1、在目标库创建业务用户

相关脚本在前边的准备阶段已经准备好了:

代码语言:javascript复制
create user xxt identified by lhr;
create user lhr identified by lhr;
grant dba to xxt,lhr;

可以使用导出和导入分开来执行,也可以直接通过network_link来做远程导入,而不需要做导出操作:

2.5.2、导入xtts的元数据

生成导入脚本:

代码语言:javascript复制
-- 在目标端可以执行如下命令生成impdp,命令在xttplugin.txt文件
[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 -e
============================================================
trace file is /home/oracle/scripts/generate_Apr13_Tue_10_58_21_639//Apr13_Tue_10_58_21_639_.log
=============================================================

--------------------------------------------------------------------
Parsing properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Done parsing properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Checking properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Done checking properties
--------------------------------------------------------------------


--------------------------------------------------------------------
Generating plugin
--------------------------------------------------------------------


--------------------------------------------------------------------
Done generating plugin file /home/oracle/scripts/xttplugin.txt
--------------------------------------------------------------------

[oracle@lhrora11204 scripts]$ more /home/oracle/scripts/xttplugin.txt
impdp directory=<DATA_PUMP_DIR> logfile=<tts_imp.log> 
network_link=<ttslink> transport_full_check=no 
transport_tablespaces=TS_LHR,TS_XXT,USERS 
transport_datafiles='/u01/app/oracle/oradata/LHR11G/TS_LHR_6.dbf','/u01/app/oracle/oradata/LHR11G/TS_XXT_7.dbf','/u01/app/oracle/oradata/LHR11G/USERS_4.dbf'

在目标端开始导入:

代码语言:javascript复制
-- 目标端创建dblink
create public database link ttslink connect to system identified by lhr using '(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 172.17.0.3 )(PORT = 1521))  ) (CONNECT_DATA = (SERVICE_NAME = LHR11G) ) )';


-- 利用dblink直接迁移元数据,这里只会迁移表、索引、约束等,因为其它对象存储在系统表空间中
impdp system/lhr directory=DATA_PUMP_DIR logfile=tts_imp_lhr.log 
network_link=ttslink transport_full_check=no 
EXCLUDE=STATISTICS  
transport_tablespaces=TS_LHR,TS_XXT,USERS 
transport_datafiles='/u01/app/oracle/oradata/LHR11G/TS_LHR_6.dbf','/u01/app/oracle/oradata/LHR11G/TS_XXT_7.dbf','/u01/app/oracle/oradata/LHR11G/USERS_4.dbf'

执行过程:

代码语言:javascript复制
[oracle@lhrora11204 scripts]$ impdp system/lhr directory=DATA_PUMP_DIR logfile=tts_imp_lhr.log 
> network_link=ttslink transport_full_check=no 
> EXCLUDE=STATISTICS   
> transport_tablespaces=TS_LHR,TS_XXT,USERS 
> transport_datafiles='/u01/app/oracle/oradata/LHR11G/TS_LHR_6.dbf','/u01/app/oracle/oradata/LHR11G/TS_XXT_7.dbf','/u01/app/oracle/oradata/LHR11G/USERS_4.dbf'

Import: Release 11.2.0.4.0 - Production on Tue Apr 13 11:01:03 2021

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

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_01":  system/******** directory=DATA_PUMP_DIR logfile=tts_imp_lhr.log network_link=ttslink transport_full_check=no EXCLUDE=STATISTICS transport_tablespaces=TS_LHR,TS_XXT,USERS transport_datafiles=/u01/app/oracle/oradata/LHR11G/TS_LHR_6.dbf,/u01/app/oracle/oradata/LHR11G/TS_XXT_7.dbf,/u01/app/oracle/oradata/LHR11G/USERS_4.dbf 
Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
Processing object type TRANSPORTABLE_EXPORT/TABLE
Processing object type TRANSPORTABLE_EXPORT/INDEX/INDEX
Processing object type TRANSPORTABLE_EXPORT/CONSTRAINT/CONSTRAINT
Processing object type TRANSPORTABLE_EXPORT/INDEX_STATISTICS
Processing object type TRANSPORTABLE_EXPORT/CONSTRAINT/REF_CONSTRAINT
Processing object type TRANSPORTABLE_EXPORT/TABLE_STATISTICS
Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
Job "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_01" successfully completed at Tue Apr 13 11:02:14 2021 elapsed 0 00:01:04

2.5.3、导入存储过程、触发器、函数、包、视图、序列

代码语言:javascript复制
-- 导入存储过程、触发器、函数、包、视图、序列
impdp system/lhr directory=DATA_PUMP_DIR 
network_link=ttslink schemas=LHR,XXT content=metadata_only exclude=index,table,constraint parallel=8

执行过程:

代码语言:javascript复制
[oracle@lhrora11204 scripts]$ impdp system/lhr directory=DATA_PUMP_DIR 
> network_link=ttslink schemas=LHR,XXT content=metadata_only exclude=index,table,constraint parallel=8

Import: Release 11.2.0.4.0 - Production on Tue Apr 13 11:05:13 2021

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

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYSTEM"."SYS_IMPORT_SCHEMA_01":  system/******** directory=DATA_PUMP_DIR network_link=ttslink schemas=LHR,XXT content=metadata_only exclude=index,table,constraint parallel=8 
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/SYNONYM/SYNONYM
Processing object type SCHEMA_EXPORT/SEQUENCE/SEQUENCE
Processing object type SCHEMA_EXPORT/PROCEDURE/PROCEDURE
Processing object type SCHEMA_EXPORT/PROCEDURE/ALTER_PROCEDURE
Processing object type SCHEMA_EXPORT/VIEW/VIEW
Job "SYSTEM"."SYS_IMPORT_SCHEMA_01"  successfully completed at Tue Apr 13 11:05:37 2021 elapsed 0 00:00:21

2.5.4、导入公共同义词和dblink等其它对象

代码语言:javascript复制
-- 导入公共同义词
set long 9999
select dbms_metadata.get_ddl('SYNONYM',SYNONYM_NAME,OWNER) 
FROM dba_synonyms 
where owner='PUBLIC' and table_owner in  ('LHR','XXT');


-- 导入dblink
set long 9999
select dbms_metadata.get_ddl('DB_LINK',DB_LINK,OWNER) 
FROM DBA_DB_LINKS;

2.6、迁移完成后的收尾工作

2.6.1、查看源端、目标端的数据一致性

代码语言:javascript复制
select count(*) from lhr.testxtts6;
select count(*) from lhr.testxtts66;

select owner, object_type, count(*)
 from dba_objects
where object_name not like 'BIN%'
 and owner in ('LHR','XXT')
group by owner, object_type
order by 1,2 desc;

select owner, object_type, count(*)
 from dba_objects
where status <> 'VALID'
 and owner in ('LHR','XXT')
group by owner, object_type
order by 1, 2 desc;

执行过程:

代码语言:javascript复制
SYS@LHR11G> select owner, object_type, count(*)
  2   from dba_objects
where object_name not like 'BIN%'
group by owner, object_type
 and owner in ('LHR','XXT')
  5  group by owner, object_type
  6  order by 1,2 desc;

OWNER                                                        OBJECT_TYPE                              COUNT(*)
------------------------------------------------------------ -------------------------------------- ----------
LHR                                                          VIEW                                            1
LHR                                                          TABLE                                          11
LHR                                                          SYNONYM                                         1
LHR                                                          SEQUENCE                                        1
LHR                                                          PROCEDURE                                       2
XXT                                                          TABLE                                           2

6 rows selected.

SYS@LHR11G> 
SYS@LHR11G> select owner, object_type, count(*)
  2   from dba_objects
where status <> 'VALID'
 and owner in ('LHR','XXT')
  5  group by owner, object_type
  6  order by 1, 2 desc;

OWNER                                                        OBJECT_TYPE                              COUNT(*)
------------------------------------------------------------ -------------------------------------- ----------
LHR                                                          PROCEDURE                                       1

迁移后的对象个数和之前一致。

2.6.2、更改用户默认表空间

代码语言:javascript复制
alter user xxt default tablespace USERS;

2.6.3、目标库的表空间修改为读写模式

代码语言:javascript复制
select 'ALTER TABLESPACE '||name||' READ WRITE;' exec_sql
from v$tablespace 
where NAME not in ('SYSTEM','SYSAUX','UNDOTBS1','TEMP');


select tablespace_name,status from dba_tablespaces;

执行过程:

代码语言:javascript复制
SYS@LHR11G> select 'ALTER TABLESPACE '||name||' READ WRITE;' exec_sql
  2  from v$tablespace 
  3  where NAME not in ('SYSTEM','SYSAUX','UNDOTBS1','TEMP');

EXEC_SQL
----------------------------------------------------------------------------------------------------------------------
ALTER TABLESPACE TS_LHR READ WRITE;
ALTER TABLESPACE TS_XXT READ WRITE;
ALTER TABLESPACE USERS READ WRITE;


SYS@LHR11G> 
SYS@LHR11G> select tablespace_name,status from dba_tablespaces;

TABLESPACE_NAME                                              STATUS
------------------------------------------------------------ ------------------
SYSTEM                                                       ONLINE
SYSAUX                                                       ONLINE
UNDOTBS1                                                     ONLINE
TEMP                                                         ONLINE
USERS                                                        READ ONLY
TS_LHR                                                       READ ONLY
TS_XXT                                                       READ ONLY

7 rows selected.

SYS@LHR11G> ALTER TABLESPACE TS_LHR READ WRITE;
Tablespace altered.

SYS@LHR11G> ALTER TABLESPACE TS_XXT READ WRITE;
Tablespace altered.

SYS@LHR11G> ALTER TABLESPACE USERS READ WRITE;
Tablespace altered.

SYS@LHR11G> select tablespace_name,status from dba_tablespaces;

TABLESPACE_NAME                                              STATUS
------------------------------------------------------------ ------------------
SYSTEM                                                       ONLINE
SYSAUX                                                       ONLINE
UNDOTBS1                                                     ONLINE
TEMP                                                         ONLINE
USERS                                                        ONLINE
TS_LHR                                                       ONLINE
TS_XXT                                                       ONLINE

7 rows selected.

2.6.4、校验数据文件完整性

运行RMAN,通过运行VALIDATE TABLESPACE检查物理和逻辑块损坏情况,如下所示:

代码语言:javascript复制
RMAN> validate tablespace TS_LHR,TS_XXT,USERS check logical;

Starting validate at 2021-04-13 11:12:24
using channel ORA_DISK_1
channel ORA_DISK_1: starting validation of datafile
channel ORA_DISK_1: specifying datafile(s) for validation
input datafile file number=00005 name=/u01/app/oracle/oradata/LHR11G/TS_XXT_7.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/LHR11G/TS_LHR_6.dbf
input datafile file number=00006 name=/u01/app/oracle/oradata/LHR11G/USERS_4.dbf
channel ORA_DISK_1: validation complete, elapsed time: 00:00:01
List of Datafiles
=================
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
4    OK     0              53           1280            3040686   
  File Name: /u01/app/oracle/oradata/LHR11G/TS_LHR_6.dbf
  Block Type Blocks Failing Blocks Processed
  ---------- -------------- ----------------
  Data       0              1065            
  Index      0              0               
  Other      0              162             

File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
5    OK     0              3705         3840            2315459   
  File Name: /u01/app/oracle/oradata/LHR11G/TS_XXT_7.dbf
  Block Type Blocks Failing Blocks Processed
  ---------- -------------- ----------------
  Data       0              2               
  Index      0              0               
  Other      0              133             

File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
6    OK     0              17           672             2922828   
  File Name: /u01/app/oracle/oradata/LHR11G/USERS_4.dbf
  Block Type Blocks Failing Blocks Processed
  ---------- -------------- ----------------
  Data       0              99              
  Index      0              37              
  Other      0              487             

Finished validate at 2021-04-13 11:12:25

2.6.5、收集统计信息

代码语言:javascript复制
exec dbms_stats.gather_database_stats(degree => 8);
exec dbms_stats.gather_dictionary_stats(degree => 8);
exec dbms_stats.gather_fixed_objects_stats();

2.7、总结

1、若使用rman方式,则源端和目标端的文件系统需要留有足够的空间

2、本文所有操作,均在oracle用户下执行。

3、如果使用dbms_file_Transfer,那么dbms_file_Transfer准备阶段方法要求目标数据库为11.2.0.4。如果目标端是11.2.0.3或更早的版本,那么需要配置一个增量转换实例。

4、若执行xttdriver.pl脚本报错,要想重新执行,那么需要删除文件FAILED

5、每次执行增量恢复xttdriver.pl -r时,都会重启目标端数据库。如果目标端是一个在用的生产库,那么需要创建一个临时实例,这样就不会影响生产库。

代码语言:javascript复制
1[oracle@dest]$ export ORACLE_HOME=/u01/app/oracle/product/11.2.0.4/xtt_home
2[oracle@dest]$ export ORACLE_SID=xtt
3[oracle@dest]$ cat  > $ORACLE_HOME/dbs/init$ORACLE_SID.ora << "EOF"
4db_name=xtt
5compatible=11.2.0.4.0
6EOF
7
8[oracle@dest]$ sqlplus / as sysdba
9SQL> startup nomount

6、XTTS停机的关键的时间点是增量的备份和恢复的时间,以及元数据的导入时间。所以,可以通过如下手段减少XTTS的停机时间:

  • 在源库开启块改变跟踪功能BCT
  • 开启并行备份,例如:RMAN> configure device type disk parallelism 8;
  • 提升impdp导入元数据库的速度,例如排除统计信息,开启并行等
  • 临时提高源库到目标库的带宽网络

7、迁移时尽量减少增量的批次,因为操作批次越多越容易出错

8、导入元数据时,需要分2次导入,第1次导入表、索引等,第2次导入存储过程、触发器、函数、包、同义词、dblink、序列等。

9、只有被迁移表空间里物理存储的数据库对象才会被拷贝至目标系统;如果要迁移存储在其它表空间的其它类型的对象(比如存储在 SYSTEM 表空间内的 pl/sql 对象,sequences 等),你可以使用数据泵来拷贝这些对象至目标系统。

注意:本文所使用的的测试环境皆为docker环境,可以参考: 所有版本的Oracle环境:https://mp.weixin.qq.com/s/XJxgyCPcVTdhlPq7VcTMDg 11.2.0.4的Oracle环境: https://mp.weixin.qq.com/s/1Z630TbilkQ3aAyOcosl4w 11.2.0.3的Oracle环境:https://mp.weixin.qq.com/s/jb0hnhsCwyGWjOmP2biGJA

本文结束。

0 人点赞