mysql跨平台迁移复制_手工 XTTS CPT 迁移-跨平台迁移数据库-阿里云开发者社区

-- xtts 跨平台迁移数据库

-- 步骤:

1、初始化参数设置;

2、将源端数据文件传输到目标系统;

3、转换数据文件为目标系统的字节序;

4、在源端创建增量备份,并传输到目标端;

5、在目标端恢复增量备份;

6、重复多次操作4和5步骤;

7、将源端数据库表空间设置为 READ ONLY 模式;

8、最后一次执行4和5步骤;

9、在源端导出元数据,并在目标端导入;

10、将目标端的数据库表空间设置为 READ WRITE;

11、数据验证。

-- 建议xtts目录和/rman 备份的路径目录都使用nfs共享

alter system set deferred_segment_creation=false sid='*' scope=spfile;

-- ###########################增量临时文件在asm######### xtt.properties ##########################

tablespaces=SPROD_TBS,IDX_TBS

platformid=13

dfcopydir=/xttrman/full -- 本地全量备份数据的路径

backupformat=/xttrman/incr -- 本地增量备份数据的路径

stageondest=/xttrman/full -- 目标端所需要恢复数据的路径,后续生成的增量也要拷贝到这里

storageondest=+DATA/prod/datafile -- 目标端数据文件路径 -c 的时候放的位置

backupondest=+DATA/prod/datafile -- 目标端增量文件的临时路径,做完增量后会自动删除,如果放asm需要设置asm_home和asm_sid

asm_home=/oracle/app/grid/product/11.2.0/grid

asm_sid=+ASM

parallel=2

rollparallel=2

getfileparallel=2

-- #############################建议使用这种方式,增量临时文件在文件系统###### xtt.properties #######################

tablespaces=SPROD_TBS,IDX_TBS

platformid=13

dfcopydir=/xttrman/full

backupformat=/xttrman/incr

stageondest=/xttrman/full

storageondest=+DATA/prod/datafile

backupondest=/xttrman/rec

#asm_home=/oracle/app/grid/product/11.2.0/grid

#asm_sid=+ASM

parallel=2

rollparallel=2

getfileparallel=2

-- ###########################################################################################

-- 源端全量备份脚本

cat full_backup.sh

export TMPDIR=/oracle/soft/xttconvert

perl xttdriver.pl -p

-- 源端执行全量备份

sh full_backup.sh

-- 生成文件

$ cat xttplan.txt

SPROD_TBS::::967892

6

IDX_TBS::::967892

$ cat rmanconvert.cmd

host 'echo ts::SPROD_TBS';

convert from platform 'Linux x86 64-bit'

datafile

'/xttrman/full/SPROD_TBS_5.tf'

,'/xttrman/full/SPROD_TBS_6.tf'

format '+DATA/prod/datafile/%N_%f.dbf'

parallelism 2;

host 'echo ts::IDX_TBS';

convert from platform 'Linux x86 64-bit'

datafile

'/xttrman/full/IDX_TBS_7.tf'

format '+DATA/prod/datafile/%N_%f.dbf'

parallelism 2;

-- 目标端,执行恢复转换

vi convert.sh

export XTTDEBUG=1

export TMPDIR=/oracle/soft/xttconvert

perl xttdriver.pl -c

sh convert.sh

vi do_incr.sh

export TMPDIR=/oracle/soft/xttconvert

perl xttdriver.pl -i

-- 源端增量备份

sh do_incr.sh

$ cat xttplan.txt.new

SPROD_TBS::::968168

6

IDX_TBS::::968196

[oracle@localhost xttconvert]$ cat tsbkupmap.txt

IDX_TBS::7:::1=07u31cir_1_1

SPROD_TBS::5,6:::1=06u31ciq_1_1

-- 注意每次做完增量 需要将增量的数据文件拷贝到全量备份的目录下,恢复完删除/xttrman/incr/*

cp /xttrman/incr/-* /xttrman/full/

-- 目标端增量恢复

vi restore_incr.sh

export TMPDIR=/oracle/soft/xttconvert

perl xttdriver.pl -r

-- 注意如果增量恢复文件放在asm可能会出现以下错误,可以忽略,这个是xtts无法自动删除asm的临时文件

Can't locate strict.pm in @INC (@INC contains: /oracle/app/grid/product/11.2.0/grid/perl/lib/5.10.0/x86_64-linux-thread-multi /oracle/app/grid/product/11.2.0/grid/perl/lib/5.10.0 /oracle/app/grid/product/11.2.0/grid/perl/lib/site_perl/5.10.0/x86_64-linux-thread-multi /oracle/app/grid/product/11.2.0/grid/perl/lib/site_perl/5.10.0 /oracle/app/grid/product/11.2.0/grid/lib /oracle/app/grid/product/11.2.0/grid/lib/asmcmd /oracle/app/grid/product/11.2.0/grid/rdbms/lib/asmcmd /oracle/app/grid/product/11.2.0/grid/perl/lib/5.10.0/x86_64-linux-thread-multi /oracle/app/grid/product/11.2.0/grid/perl/lib/5.10.0 /oracle/app/grid/product/11.2.0/grid/perl/lib/site_perl/5.10.0/x86_64-linux-thread-multi /oracle/app/grid/product/11.2.0/grid/perl/lib/site_perl/5.10.0 /oracle/app/grid/product/11.2.0/grid/perl/lib/5.10.0/x86_64-linux-thread-multi /oracle/app/grid/product/11.2.0/grid/perl/lib/5.10.0/x86_64-linux-thread-multi /oracle/app/grid/product/11.2.0/grid/perl/lib/5.10.0 /oracle/app/grid/product/11.2.0/grid/perl/lib/site_perl/5.10.0/x86_64-linux-thread-multi /oracle/app/grid/product/11.2.0/grid/perl/lib/site_perl/5.10.0 /oracle/app/grid/product/11.2.0/grid/perl/lib/site_perl .) at /oracle/app/grid/product/11.2.0/grid/bin/asmcmdcore line 143.

BEGIN failed--compilation aborted at /oracle/app/grid/product/11.2.0/grid/bin/asmcmdcore line 143.

Can't locate strict.pm in @INC (@INC contains: /oracle/app/grid/product/11.2.0/grid/perl/lib/5.10.0/x86_64-linux-thread-multi /oracle/app/grid/product/11.2.0/grid/perl/lib/5.10.0 /oracle/app/grid/product/11.2.0/grid/perl/lib/site_perl/5.10.0/x86_64-linux-thread-multi /oracle/app/grid/product/11.2.0/grid/perl/lib/site_perl/5.10.0 /oracle/app/grid/product/11.2.0/grid/lib /oracle/app/grid/product/11.2.0/grid/lib/asmcmd /oracle/app/grid/product/11.2.0/grid/rdbms/lib/asmcmd /oracle/app/grid/product/11.2.0/grid/perl/lib/5.10.0/x86_64-linux-thread-multi /oracle/app/grid/product/11.2.0/grid/perl/lib/5.10.0 /oracle/app/grid/product/11.2.0/grid/perl/lib/site_perl/5.10.0/x86_64-linux-thread-multi /oracle/app/grid/product/11.2.0/grid/perl/lib/site_perl/5.10.0 /oracle/app/grid/product/11.2.0/grid/perl/lib/5.10.0/x86_64-linux-thread-multi /oracle/app/grid/product/11.2.0/grid/perl/lib/5.10.0/x86_64-linux-thread-multi /oracle/app/grid/product/11.2.0/grid/perl/lib/5.10.0 /oracle/app/grid/product/11.2.0/grid/perl/lib/site_perl/5.10.0/x86_64-linux-thread-multi /oracle/app/grid/product/11.2.0/grid/perl/lib/site_perl/5.10.0 /oracle/app/grid/product/11.2.0/grid/perl/lib/site_perl .) at /oracle/app/grid/product/11.2.0/grid/bin/asmcmdcore line 143.

BEGIN failed--compilation aborted at /oracle/app/grid/product/11.2.0/grid/bin/asmcmdcore line 143.

-- 下次增量要记录当前恢复的scn位置,产生最新 xttplan.txt 文件,要不然下次增量还会在全量进行备份

perl xttdriver.pl -s

-- 后续增量循环以下三步骤

sh do_incr.sh

sh restore_incr.sh

perl xttdriver.pl -s

-- 最后一次增量,表空间设置为只读模式

SQL> alter tablespace SPROD_TBS read only;

Tablespace altered.

SQL> alter tablespace IDX_TBS read only;

Tablespace altered.

-- 最后一次恢复

sh do_incr.sh

sh restore_incr.sh

----------------------------------------------------------------------------------------

-- 传输表空间

传输表空间的步骤可以和最后一次增量备份同时执行,可开并行

方法1:

-- 目标端执行,得到impdp脚本

$ORACLE_HOME/perl/bin/perl xttdriver.pl –e

impdp system/oracle directory=ddmp logfile=impdp_xtts_20180527.lognetwork_link=TEST \

transport_full_check=no \

transport_tablespaces=TEST,TEST_IND \

transport_datafiles='/data3/oradata/targetdb/TEST_5.dbf','/data3/oradata/targetdb/TEST_IND_6.dbf'

方法2:

-- 手工导出导入表空间

源端

expdp system/oracle directory=sdmp dumpfile=xtts.dmplogfile=expdp_xtts_20180527.log transport_tablespaces=TEST,TEST_INDtransport_full_check=no;

-- 复制导出的文件到目标端

目标端

impdp system/oracle directory=ddmp dumpfile=xtts.dmplogfile=impdp_xtts_20180527.logtransport_datafiles='/app/oradata/targetdb/TEST_5.dbf,/app/oradata/targetdb/TEST_IND_6.dbf'

-- 验证,传输完成后应该能够看到所有表空间,并且能够查询其中的数据

set pagesize 2000

set linesize 200

col file_name for a40

col OBJECT_NAME for a30

select TABLESPACE_NAME from dba_tablespaces;

----------------------------------------------------------------------------------------

-- 导入元数据

-- 源端检查表空间的自包含性

SQL> EXECUTE DBMS_TTS.TRANSPORT_SET_CHECK('TEST02', TRUE);

SQL> SELECT * FROM TRANSPORT_SET_VIOLATIONS;

no rows selected

/*

$ expdp system/oracle directory=source_dbdata dumpfile=test02.dmp transport_tablespaces=test02 transport_full_check=y

$ impdp test02/test02 DUMPFILE=test02.dmp DIRECTORY=source_dbdata TRANSPORT_DATAFILES=/home/oracle/xtts/target_data/TEST02_7.dbf

*/

-- 方式一

-- 建议不要导入统计信息,目标库直接收集

create or replace directory xtts_dir as '/oracle/soft/'

create database link ttslink connect to system identified by "oracle" USING 'sprod';

ASMCMD> ls -al

WARNING:option 'a' is deprecated for 'ls'

please use 'absolutepath'

Type Redund Striped Time Sys Name

DATAFILE UNPROT COARSE JUN 01 21:00:00 Y +DATA/PROD/DATAFILE/idx_tbs_7.dbf => IDX_TBS.274.1009834557

DATAFILE UNPROT COARSE JUN 01 21:00:00 Y +DATA/PROD/DATAFILE/sprod_tbs_5.dbf => SPROD_TBS.273.1009834553

DATAFILE UNPROT COARSE JUN 01 21:00:00 Y +DATA/PROD/DATAFILE/sprod_tbs_6.dbf => SPROD_TBS.275.1009834553

DATAFILE UNPROT COARSE JUN 01 21:00:00 Y none => SYSAUX.257.1009808403

DATAFILE UNPROT COARSE JUN 01 21:00:00 Y none => SYSTEM.256.1009808403

DATAFILE UNPROT COARSE JUN 01 21:00:00 Y none => UNDOTBS1.258.1009808403

DATAFILE UNPROT COARSE JUN 01 21:00:00 Y none => USERS.259.1009808403

N idx_tbs_7.dbf => +DATA/PROD/DATAFILE/IDX_TBS.274.1009834557

N sprod_tbs_5.dbf => +DATA/PROD/DATAFILE/SPROD_TBS.273.1009834553

N sprod_tbs_6.dbf => +DATA/PROD/DATAFILE/SPROD_TBS.275.1009834553

ASMCMD>

impdp \’/ as sysdba\‘ directory=xtts_dir logfile=tts_imp.log network_link=ttslink transport_full_check=no transport_tablespaces=SPROD_TBS,IDX_TBS exclude=STATISTICS transport_datafiles='+DATA/PROD/DATAFILE/IDX_TBS.275.1009832163','+DATA/PROD/DATAFILE/SPROD_TBS.274.1009832159','+DATA/PROD/DATAFILE/SPROD_TBS.273.1009832159'

ls -al|grep -v *.zip|grep -v .sh|awk -F' ' '{print $9}'|xargs rm -rf

-- 方式二

-- 源端导出,如果不对数据字典做任何修改操作,可提前导出

expdp system/oracle DIRECTORY=xtts_dir LOGFILE=dp_fullexp_meta.log DUMPFILE=dp_full.dmp FULL=y CONTENT=METADATA_ONLY

-- 复制导出的文件到目标端

-- 目标端导入

impdp system/oracle DIRECTORY=xtts_dir LOGFILE=dp_fullexp_meta.log DUMPFILE=dp_full.dmp FULL=y CONTENT=METADATA_ONLY

-- 自定义 Role 处理

select GRANTED_ROLE from dba_role_privs whereGRANTEE='XTTS';

create role R_INIT_USER;

select 'grant '||PRIVILEGE||' to '||GRANTEE||';' fromdba_sys_privs where grantee='R_INIT_USER';

-- 自定义 Profile 处理

set long 1000000

SET PAGESIZE 3000

set lines 200

SET HEADING OFF

SET VERIFY OFF

SET FEEDBACK OFF

set echo on

set timing off

set wrap On

SET LONGCHUNKSIZE 400

spool create_profile.sql

with profile as(

select distinct profile from dba_profiles)

select dbms_metadata.get_ddl('PROFILE',PROFILE) fromprofile;

-- 临时表处理

set long 1000000

SET PAGESIZE 3000

set lines 200

SET HEADING OFF

SET VERIFY OFF

SET FEEDBACK OFF

set echo on

set timing off

set wrap On

SET LONGCHUNKSIZE 400

select dbms_metadata.get_ddl('TABLE',TABLE_NAME,OWNER)

from DBA_TABLES

where TEMPORARY='Y' and owner in ();

-- 解释:

tablespaces=    -- 需要迁移的表空间

platformid=  -- 源 OS 平台 ID

dfcopydir=   -- 源数据库备份文件存放目录

backupformat=    -- 源数据库增备文件存放目录

stageondest=  -- 目标据库备份文件存放目录

storageondest=  -- 目标据库正式文件存放目录

backupondest=  -- 目标据库增备文件存放目录

parallel=  -- 备份,转化的并行度

rollparallel=  -- 增备的并行度

getfileparallel=  -- 使用 dbms_file_transfer 方式的并行度

-- xtts 跨平台迁移数据库 2

1、源和目标库创建数据库对应的目录,目标库创建公共DBLink使用 system 用户

# source db

create or replace directory ora10g_dbf_dir as '+DATA/ora10g/datafile';

create or replace directory xttsfiles as '/home/oracle/xttsfiles';

grant read,write on directory ... to public;

# target db

create or replace directory ora12c_dbf_dir as '+DATA/ora12c/datafile';

create or replace directory xttsfiles as '/home/oracle/xttsfiles';

grant read,write on directory ... to public;

create database link ORA10G_LINK connect to system identified by system using 'ORA10G';

2、解压 XTTS

unzip -d /home/oracle/xtts rman_xttconvert_1.4.zip

3、编辑 xtts.properties 配置文件

vi xtts.properties

tablespace=AP_DATA,AP_IDX

# source db param

platform=2

srcdir=ora10g_dbf_dir

srclink=ora10g_link

dfcopydir=/home/oracle/xttsfiles

backupformat=/home/oracle/xttsfiles

# target db param

dstdir=ora12c_dbf_dir

stageondest=/home/oracle/xttsfiles

storageondest=+DATA

backupondest=+FRA

asm_home=/u01/app/12.1.0/grid

asm_sid=+ASM

parallel=4

rollparallel=2

4、执行脚本

-- 初始提取

Generate initial datafile image copies:

$ ./xttdriver.pl -S

Copy scripts & files to destination platform:

$ scp ... ...

Pull initial datafile image copies to destination:

$ ./xttdriver.pl -G

Conversion handled implicitly!

-- 增量同步

Generate INCREMENTAL LEVEL 1 backup sets:

$ ./xttdriver.pl -i

Copy scripts & files to destination platform:

$ scp ... ...

Capture SCN of last synchronization:

$ ./xttdriver.pl -s

Use INCREMENTAL LEVEL 1 backup sets to recover datafile image copies to current SCN:

$ ./xttdriver.pl -r

-- 当源库与目标库期望接近时,DBA决定完成迁移,则将所有需要XTTS迁移的对象设置为只读模式,

alter tablespace ... read only;

-- 直到最后一个1级增量备份被捕获兵传输到目标库,然后应用于0级备份,在最后一次恢复。

-- 最终同步

Generate INCREMENTAL LEVEL 1 backup sets:

$ ./xttdriver.pl -i

Copy scripts & files to destination platform:

$ scp ... ...

Capture SCN of last synchronization:

$ ./xttdriver.pl -s

Use INCREMENTAL LEVEL 1 backup sets to recover datafile image copies to final SCN:

$ ./xttdriver.pl -r

Import metadata into destination database:

$ ./xttdriver.pl -e

-- CPT(Cross-Platform Transport) 跨平台迁移数据库

# source 12.1.0.1

Backup READ ONLY tablespace as backup sets:

rman target /

backup for transport format '+DATA' datapump format '/home/oracle/cpt/dp_file.dmp' tablespace tpch_data,tpch_idx;

Copy datafile backup sets to target database 12.1.0.2

Use DBMS_FILE_TRANSFER or other OS tools transport to destination OS.

# target 12.1.0.2 non-CDB

rman target /

restore foreign tablespace tpch_data,tpch_idx format '+DATA' from backupset '+RECO' dump file from backupset '/home/oracle/cpt/dp_file.dmp';

你可能感兴趣的:(mysql跨平台迁移复制)