跨平台表空间迁移(XTTS)

概述:跟同事聊天时说起,在数据库迁移中如果跨平台跨数据库版本除了数据泵、OGG、DSJ等第三方软件能否使用不花钱的技术实现大数据量的短时间迁移呢?很有幸,自己也在生产环境中使用过XTTS技术实践过;以下就做个测试实验记录下。

基本步骤:

1、确定需要传输的表空间;

2、建立相关目录;

3、配置xtt参数文件;

4、拷贝数据;

5、增量前滚;

6、最后的数据迁移;

7、数据比对及后续整理;

所需工具:

rman-xttconvert_2.0.zip

实验:

源端为:10G数据库

SQL>  select * from v$version where rownum<3;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi
PL/SQL Release 10.2.0.5.0 - Production

目标端为:11G数据库

SQL>  select * from v$version where rownum<3;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

PL/SQL Release 11.2.0.4.0 - Production

上传工具包并解压:

cd /home/oracle/xtt

unzip rman-xttconvert_2.0.zip

源端创建相关目录:

[oracle@cube1 xtt]$ pwd
/home/oracle/xtt

[oracle@cube1 xtt]$ mkdir tmp

[oracle@cube1 xtt]$ mkdir data

[oracle@cube1 xtt]$ export TMPDIR=/home/oracle/xtt/tmp/
[oracle@cube1 xtt]$ export PERL5LIB=$ORACLE_HOME/perl/lib
[oracle@cube1 xtt]$ export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK

[oracle@cube1 xtt]$ export XTTDEBUG=1 

确定需要将cube用户下的表空间进行迁移:一般用户下的存储都是分为数据表空间和索引表空间,如果还有其他的分区表空间也需要查找清楚;

SQL> select distinct tablespace_name from dba_indexes where owner='CUBE';
TABLESPACE_NAME
------------------------------
CUBE_INDX

SQL> select distinct tablespace_name from dba_tables where owner='CUBE';
TABLESPACE_NAME
------------------------------

CUBE_DATA

查看表空间的自包含性,如果自包含性不符合规定有报错的话传输将失败:

SQL> EXECUTE DBMS_TTS.TRANSPORT_SET_CHECK('CUBE_DATA',TRUE,TRUE);
PL/SQL procedure successfully completed.
SQL> SELECT * FROM TRANSPORT_SET_VIOLATIONS;
VIOLATIONS
--------------------------------------------------------------------------------
Index CUBE.CUBE_INDX1 in tablespace CUBE_INDX points to table CUBE.CUBE in table

space CUBE_DATA

(此说明cube_data表空间与cube_indx存在关联关系不是自包含)解决办法就是将相关连的表空间都打包在一个包中自然就不存在问题了。

SQL> EXECUTE DBMS_TTS.TRANSPORT_SET_CHECK('CUBE_DATA,CUBE_INDX',TRUE,TRUE);
PL/SQL procedure successfully completed.

SQL> SELECT * FROM TRANSPORT_SET_VIOLATIONS;

no rows selected

修改源库传输工具参数文件xtt.properties:

查看源库的platformid:

SQL> select PLATFORM_ID from v$database;
PLATFORM_ID
-----------

         13

此次修改的参数文件内容为:

platformid=13
dfcopydir=/home/oracle/xtt/data
backupformat=/home/oracle/xtt/data
stageondest=/home/oracle/xtt/data
storageondest=/u01/ora/app/oradata/cube
backupondest=/home/oracle/xtt/data

tablespaces=CUBE_DATA,CUBE_INDX

scp xtt.properties 192.0.2.202:/home/oracle/xtt/

源端进行初始备份:

/u01/ora/app/product/10.2.0/perl/bin/perl xttdriver.pl -p

将备份文件传输至cube2

[oracle@cube1 tmp]$ scp  rmanconvert.cmd xttplan.txt cube2:/home/oracle/xtt/
oracle@cube2's password: 
rmanconvert.cmd                                                          100%  384     0.4KB/s   00:00    
xttplan.txt

 scp  0* cube2:/home/oracle/xtt/data/
oracle@cube2's password: 
03t0qk4n_1_1                                                             100%  160KB 160.0KB/s   00:00    
04t0qk4o_1_1      

将备份文件转换到目标端:  

[oracle@cube2 xtt]$ /u01/ora/app/product/11.2.0/perl/bin/perl xttdriver.pl -c

PL/SQL procedure successfully completed.
Entering RollForward
After applySetDataFile
Done: applyDataFileTo
Done: applyDataFileTo
Done: RestoreSetPiece
Done: RestoreBackupPiece

PL/SQL procedure successfully completed.

--------------------------------------------------------------------
End of rollforward phase

源库数据增量前滚:当数据库的数据量很大时在进行备份过程中业务将在进行运行业务,为了是目标库数据与源库数据更加接近需要进行增量的操作;

SQL> insert into cube values (1000,'cube1');
1 row created.
SQL> commit;
Commit complete.
SQL> alter system switch logfile;
System altered.
SQL> /
System altered

[oracle@cube1 xtt]$ /u01/ora/app/product/10.2.0/perl/bin/perl xttdriver.pl -i

将增量备份的文件拷贝至目标库:

 scp 05t0qkn7_1_1 06t0qkn9_1_1 cube2:/home/oracle/xtt/data/
oracle@cube2's password: 
05t0qkn7_1_1                                                             100%  160KB 160.0KB/s   00:00    
06t0qkn9_1_1  

 scp incrbackups.txt tsbkupmap.txt rmanincr.cmd xttplan.txt.new cube2:/home/oracle/xtt/tmp/
oracle@cube2's password: 
incrbackups.txt                                                          100%   70     0.1KB/s   00:00    
tsbkupmap.txt                                                            100%   60     0.1KB/s   00:00    
rmanincr.cmd                                                             100%  314     0.3KB/s   00:00    
xttplan.txt.new

目标端进行增量备份应用:

[oracle@cube1 xtt]$ /u01/ora/app/product/10.2.0/perl/bin/perl xttdriver.pl -r

PL/SQL procedure successfully completed.
Entering RollForward
After applySetDataFile
Done: applyDataFileTo
Done: applyDataFileTo
Done: RestoreSetPiece
Done: RestoreBackupPiece
PL/SQL procedure successfully completed.
--------------------------------------------------------------------
End of rollforward phase

最后的增量同步:

SQL> alter tablespace cube_data read only;
Tablespace altered.
SQL> alter tablespace cube_indx read only;
Tablespace altered.
SQL> create directory xtts as '/home/oracle/xtt';
Directory created.
SQL> grant read,write on directory xtts to public;
Grant succeeded.

/u01/ora/app/product/10.2.0/perl/bin/perl xttdriver.pl -i

 scp incrbackups.txt tsbkupmap.txt rmanincr.cmd xttplan.txt.new cube2:/home/oracle/xtt/tmp/
oracle@cube2's password: 
incrbackups.txt                                                          100%   70     0.1KB/s   00:00    
tsbkupmap.txt                                                            100%   60     0.1KB/s   00:00    
rmanincr.cmd                                                             100%  314     0.3KB/s   00:00    
xttplan.txt.new    

 scp 05t0qkn7_1_1 06t0qkn9_1_1 cube2:/home/oracle/xtt/data/
oracle@cube2's password: 
05t0qkn7_1_1                                                             100%  160KB 160.0KB/s   00:00    
06t0qkn9_1_1 

备库应用最后的增量文件:

[oracle@cube2 xtt]$ /u01/ora/app/product/11.2.0/perl/bin/perl xttdriver.pl -r

目标端元数据进行同步:

[oracle@cube1 data]$ expdp \'/ as sysdba\' directory=xtts dumpfile=xttscube%U.dmp transport_tablespaces=cube_data,cube_indx transport_full_check=n


Export: Release 10.2.0.5.0 - 64bit Production on Friday, 20 April, 2018 14:16:04


Copyright (c) 2003, 2007, Oracle.  All rights reserved.


Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYS"."SYS_EXPORT_TRANSPORTABLE_01":  "/******** AS SYSDBA" directory=xtts dumpfile=xttscube%U.dmp transport_tablespaces=cube_data,cube_indx transport_full_check=n 
Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
Processing object type TRANSPORTABLE_EXPORT/TABLE
Processing object type TRANSPORTABLE_EXPORT/INDEX
Processing object type TRANSPORTABLE_EXPORT/INDEX_STATISTICS
Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
Master table "SYS"."SYS_EXPORT_TRANSPORTABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYS.SYS_EXPORT_TRANSPORTABLE_01 is:
  /home/oracle/xtt/xttscube01.dmp
Job "SYS"."SYS_EXPORT_TRANSPORTABLE_01" successfully completed at 14:16:24

[oracle@cube2 tmp]$ sqlplus / as sysdba


SQL*Plus: Release 11.2.0.4.0 Production on Fri Apr 20 14:16:43 2018


Copyright (c) 1982, 2013, Oracle.  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


SQL> create directory xtts as '/home/oracle/xtt';


Directory created.


SQL> grant read,write on directory xtts to public;


Grant succeeded.


SQL> select tablespace_name from dba_tablespaces;

[oracle@cube2 xtt]$ impdp \'/ as sysdba\' directory=xtts   dumpfile=xttscube%U.dmp transport_datafiles='/u01/ora/app/oradata/cube/CUBE_DATA_5.xtf','/u01/ora/app/oradata/cube/CUBE_INDX_6.xtf'


Import: Release 11.2.0.4.0 - Production on Fri Apr 20 14:23:50 2018


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
Master table "SYS"."SYS_IMPORT_TRANSPORTABLE_01" successfully loaded/unloaded
Starting "SYS"."SYS_IMPORT_TRANSPORTABLE_01":  "/******** AS SYSDBA" directory=xtts dumpfile=xttscube%U.dmp transport_datafiles=/u01/ora/app/oradata/cube/CUBE_DATA_5.xtf,/u01/ora/app/oradata/cube/CUBE_INDX_6.xtf 
Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
Processing object type TRANSPORTABLE_EXPORT/TABLE
Processing object type TRANSPORTABLE_EXPORT/INDEX
Processing object type TRANSPORTABLE_EXPORT/INDEX_STATISTICS
Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
Job "SYS"."SYS_IMPORT_TRANSPORTABLE_01" successfully completed at Fri Apr 20 14:23:57 2018 elapsed 0 00:00:04

SQL> select tablespace_name,status from dba_tablespaces;


TABLESPACE_NAME                STATUS
------------------------------ ---------
SYSTEM                         ONLINE
SYSAUX                         ONLINE
UNDOTBS1                       ONLINE
TEMP                           ONLINE
USERS                          ONLINE
CUBE_INDX                      READ ONLY
CUBE_DATA                      READ ONLY


7 rows selected.


SQL> alter tablespace CUBE_INDX read write;


Tablespace altered.


SQL> alter tablespace CUBE_DATA  read write;


Tablespace altered.


SQL> select tablespace_name,status from dba_tablespaces;


TABLESPACE_NAME                STATUS
------------------------------ ---------
SYSTEM                         ONLINE
SYSAUX                         ONLINE
UNDOTBS1                       ONLINE
TEMP                           ONLINE
USERS                          ONLINE
CUBE_INDX                      ONLINE
CUBE_DATA                      ONLINE


7 rows selected.


SQL> alter user cube default tablespace cube_data;


User altered.



SQL> select * from cube.cube where id>100;


        ID NAME
---------- ----------
      1000 cube1

总结:至此xtts跨平台传输表空间技术完成测试;此测试是linux 6.4+10G迁移至linux 6.4+11G ,其实在实际应用中是能够使用aix或者hp unix等平台进行迁移的本人也实践过,各位自己测试吧。mos参考文档地址:https://support.oracle.com/epmos/faces/DocumentDisplay?_afrLoop=517786952395212&parent=DOCUMENT&sourceId=2102859.1&id=1389592.1&_afrWindowMode=0&_adf.ctrl-state=18xwstk5ta_165

12C的xtts有所改动应该也不大参考文档:https://support.oracle.com/epmos/faces/SearchDocDisplay?_adf.ctrl-state=18xwstk5ta_9&_afrLoop=517777608164341#REF_PURPOSE

你可能感兴趣的:(migrate)