手把手XTTS_V4迁移

最近公司Oracle升级,考虑到停机时间等综合因数,最终选择了xtts数据迁移方案。

[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:9888c6f3-fcf2-4053-916d-c565a2fdf292

[En]

[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:ed7e21db-82d9-4854-85ad-467d89f9853a

关于xtts的介绍可以参见这篇文章:

《XTTS,又一个值得你重视的Oracle数据库迁移升级利器》

https://blog.csdn.net/weixin_34064653/article/details/90584543

需要注意的是,引文使用的是xtts2,而我采用的xtts4对配置文件和步骤有很大简化。

[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:7ff56b1f-59f2-4cde-813e-235ce6188192

[En]

[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:e8ac89f0-c816-4d70-9bcb-5c64a67a3099

一、 使用场景:

源库: Linux RAC ASM 11.2.0.4

目标库:Linux RAC ASM 19.6.0.0.0

XTTS版本:xttsV4

二、 操作步骤:

1、 准备阶段

1) 校验环境信息,为备份做前期准备

2、 传输阶段

1) 源库创建备份

2) 目标库恢复备份

3、 增量阶段

1) 源库做增量备份,可以多次执行,目的是让目标库和源库尽可能接近

2) 目标库同步增量

4、 停机阶段

1) 源库创建验证表,并写入一条数据

2) 源库表空间切换至read only

3) 源库做最后一次增量备份

4) 复制增量到目标库

5) 目标库同步增量

6) 导入角色、用户信息(若准备阶段已经处理,则跳过)

7) 目标库导入表空间元数据

8) 确认表空间已导入

9) rman下检查表空间是否有物理和逻辑错误

10) 修改目标库表空间read write

11) 导入profile

12) 导入其他对象

13) 手动收集统计信息(如果导入表空间元数据时排除了统计信息)

5、 验证阶段

1) 查询目标库验证表数据是否和源库一致

2) 验证数据对象

三、 准备阶段

1、 检查数据库版本:目标必须>=源>=11.2.0.4

SELECT * FROM v$version;

2、 确认compatible版本:目标必须>=源>=11.2.0.4

SELECT * FROM v$parameter WHERE NAME = ‘compatible’;

3、 确认instance_name,archive模式必须开启

SELECT * FROM v$instance;

4、 确认rman备份策略必须为disk(关键字:TO DISK)

rman target/

show default device type;

5、 确认rman未开启压缩(关键字:TO BACKUPSET)

show device type;

6、 目标库db_files必须大于源库

SELECT * FROM v$parameter WHERE NAME = ‘ db_files ‘;

7、 确认源和目标的字符集一致

select * from nls_database_parameters t where t.parameter in (‘NLS_CHARACTERSET’, ‘NLS_NCHAR_CHARACTERSET’);

8、 确认时区一致

select dbtimezone from dual;

9、 要迁移的表空间都是online

select tablespace_name, status from dba_tablespaces t where tablespace_name = ‘ TESTDB ‘;

select file_name, online_status from dba_data_files where tablespace_name = ‘ TESTDB ‘;

10、 要迁移的表空间中没有sys,system用户的对象

select * from dba_segments where tablespace_name = ‘TESTDB’ and owner IN (‘SYS’, ‘SYSTEM’);

11、 用户对象没有存储在system,sysaux,users上

select * from dba_segments where tablespace_name in (‘SYSTEM’,’SYSAUX’,’USER’) and owner = ‘TEST’;

12、 是否存在外部表

select OWNER, TABLE_NAME from DBA_EXTERNAL_TABLES;

13、 是否存在加密列、加密表空间

select owner, table_name, count(*) from DBA_ENCRYPTED_COLUMNS group by owner, table_name;

select TABLESPACE_NAME, ENCRYPTED from dba_tablespaces where ENCRYPTED = ‘YES’;

14、 表空间是否自包含

execute dbms_tts.transport_set_check(‘TESTDB’, true);

select * from transport_set_violations;

15、 清空回收站

select count(*) from dba_recyclebin;

purge dba_recyclebin;

16、 为源库开启快跟踪(可以提升增量备份的效率)

alter database enable block change tracking using file ‘%ORACLE_HOME%/trace/trace.log’;

17、 检查无效对象

select owner, object_name, object_type, status from dba_objects where owner = ‘TEST’ and status <> ‘VALID’;

18、 检查无效索引

select index_name, table_name, tablespace_name, from dba_indexes where tablespace_name = ‘TESTDB’ and status <> ‘VALID’;

19、 创建目标库到源库的DBLINK(用于比对pfile,role,user和import表空间元数据)

create public database link TTSLINK connect to system identified by密码 using

‘(DESCRIPTION =

(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = 源库地址)(PORT = 1521)))

(CONNECT_DATA = (SERVICE_NAME = 源库服务名))

)’;

select 1 from dual@ TTSLINK;

20、 目标库创建directory(用于导入元数据)

create directory TTSDUMP as ‘工作目录/ttsdump’;

21、 目标库检查是否已存在欲复制的表空间和对象(存在则需重命名或删除)

select * from dba_tablespaces where tablespace_name = ‘TESTDB’;

select t1.*

from

(select owner, object_name, object_type from dba_objects where owner = ‘TEST’) t1,

(select owner, object_name, object_type from dba_objects@TTSLINK where owner = ‘TEST’) t2

where t1. owner = t2.owner and t1.object_name = t2.object_name and t1.object_type = t2.object_type;

22、 对比新旧库的profile

select distinct(t.pro) from

select s.profile pro, l.profile pro2

from dba_profiles@ TTSLINK s, dba_profiles l

where s.profile = l.profile(+)

) t

where t.pro2 is null

order by t.pro;

23、 对比新旧库的role

select ‘create role ‘||role ||’;’ from dba_roles@TTSLINK

minus

select ‘create role ‘||role ||’;’ from dba_roles;

24、 对比新旧库的user

select ‘create user “‘||a.username ||'” identified by values ”’||b.password||

”’ default tablespace ‘|| a.default_tablespace || ‘ temporary tablespace ‘|| a.temporary_tablespace||’;’

from dba_users@TTSLINK a, sys.user$@TTSLINK b, dba_users c

where a.username=b.name

and a.username = c.username(+) and c.username is null

order by a.username;

select ‘grant ‘ || GRANTED_ROLE || ‘ to ‘ || GRANTEE from DBA_ROLE_PRIVS

where GRANTEE IN(

SELECT username FROM dba_users b

WHERE b.username NOT IN (‘SYS’, ‘SYSTEM’, ‘SYSAUX’, ‘…….’)

) order by GRANTEE, GRANTED_ROLE;

四、 传输阶段

1、 源库部署rman_xttconvert_VER4.zip脚本

mkdir –p /home/db/oracle/xtts/backup

cd /home/db/oracle/xtts

unzip rman_xttconvert_VER4.zip

2、 修改xtt.properties配置文件:

[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:21d52218-82ac-4893-accc-3915bba8cd53

[En]

[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:64461966-2efb-41c4-962f-7bad6937d0e8

1) tablespaces:欲复制的表空间,多个表空间之间用”,”分隔。

2) platformid:源库platformid (SLECT platform_id FROM v$database;)

3) src_srcatch_location:源库创建备份的位置(使用nas目录)

4) dest_srcatch_location:目标库接受备份的位置(同上目录)

5) dest_datafile_location:目标库表空间文件的位置

3、 复制脚本到目标库

scp –r /home/db/oracle/xtts 目标库ip:/home/db/oracle/xtts

4、 源库目标库设置环境变量

1) 确认源库目标库的oralce_sid,避免一台服务器有多个实例的情况导错库

echo $ORACHE_SID

2) 源库目标库设置xtts工作目录、开启debug

export TMPDIR=/home/db/oracle/xtts

export XTTDEBUG=1

3) 切换工作目录

cd /home/db/oracle/xtts

5、 源库创建备份

cd /home/db/oracle/xtts

nohup $ORACLE_HOME/perl/bin/perl xttdriver.pl –backup &

6、 复制到目标库

scp –r backup res.txt 目标库ip:/home/db/oracle/xtts/

7、 目标库应用备份

nohup $ORACLE_HOME/perl/bin/perl xttdriver.pl –restore &

五、 增量阶段

[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:07ca50f8-4c4f-456c-9fef-20d1da902316

[En]

[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:2ace3b33-6c18-4451-9675-e1bcdf94d6c4

1、 源库创建增量备份

cd /home/db/oracle/xtts

nohup $ORACLE_HOME/perl/bin/perl xttdriver.pl –backup &

2、 复制到目标库

scp –r backup res.txt 目标库ip:/home/db/oracle/xtts/

3、 目标库应用备份

nohup $ORACLE_HOME/perl/bin/perl xttdriver.pl –restore &

六、 停机阶段

1、 源库创建验证表,并写入一条数据

create table TEST.XTTS_TEST tablespace TESTDB as select 1 C1 from DUAL;

2、 源库表空间切换至read only

ALTER TABLESPACE TESTDB READ ONLY;

ALTER TABLESPACE TESTDB2 READ ONLY;

3、 源库做最后一次增量备份

cd /home/db/oracle/xtts

export TMPDIR=/home/db/oracle/xtts

export XTTDEBUG=1

nohup $ORACLE_HOME/perl/bin/perl xttdriver.pl –backup &

4、 复制到目标库

scp –r backup res.txt 目标库ip:/home/db/oracle/xtts/

5、 目标库同步增量

cd /home/db/oracle/xtts

export TMPDIR=/home/db/oracle/xtts

export XTTDEBUG=1

nohup $ORACLE_HOME/perl/bin/perl xttdriver.pl –restore &

6、 导入角色、用户信息(免得导入表空间元素据报错,若准备阶段已经处理,则跳过)

impdp system/oracle metrics=yes network_link=TTSLINK include=role,user full=y content=metadata_only > other.log

7、 目标库导入表空间元数据

1) 复制xttplan.txt,xttnewdatafiles.txt

scp xttplan.txt xttnewdatafiles.txt目标库ip:/home/db/oracle/xtts/

2) 生成DataPump 导入模板文件xttplugin.txt

nohup $ORACLE_HOME/perl/bin/perl xttdriver.pl -e &

3) 修改xttplugin.txt

修改以下内容

1、 用户名/密码

2、 dmp目录

3、 network_link

可选配置:exclude=(TABLE_STATISTICS,INDEX_STATISTICS)

[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:b6252ccb-ec30-4b89-b91e-178f4832bb82

[En]

[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:64db4343-fd5a-48f6-b37b-f229886df74f

8、 确认表空间已导入

SELECT * FROM dba_segments WHERE tablespace IN (‘TESTDB’,’TESTDB2′);

SELECT * FROM TEST.xtts_test;

9、 rman下检查表空间是否有物理和逻辑错误

RMAN> validate tablespace TESTDB, TESTDB2 check logical;

10、 修改目标库表空间read write

ALTER TABLESPACE TESTDB READ WRITE;

ALTER TABLESPACE TESTDB2 READ WRITE;

11、 导入profile

impdp system/oracle metrics=yes network_link=TTSLINK include=profile full=y content=metadata_only > other.log

12、 导入其他对象

impdp system/oracle metrics=yes network_link=TTSLINK include=view,sequence,fuction,procedure schemas=(TEST,TEST2) content=metadata_only > other.log

13、 手动收集统计信息(如果导入表空间元数据时排除了统计信息)

select ‘EXEC DBMS_STATS.GATHER_TABLE_STATS(”’||owner||”’,”’||table_name||”’,estimate_percent=>1,method_opt=>”FOR ALL COLUMNS SIZE AUTO”,degree=>12,cascade=>TRUE);’ from dba_tables where owner in(‘TEST’,’TEST2′) ;

七、 验证阶段

通知应用切换ip,验证应用服务是否正常

Original: https://www.cnblogs.com/zhuisuidefeng/p/15485565.html
Author: 追随的风
Title: 手把手XTTS_V4迁移

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/562199/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球