xtts 迁移数据库

采用最新版本的 rman_xttconvert_VER4.3.zip 做迁移

1. 先把xtts的脚本放到源库

2. 然后给 xtt.properties 指定源库/目标库的备份放置的路径,以及datafile在目标端的路径

3. 把 xtts 脚本目录拷贝到目标端

4. 把源库/目标库的 TMPDIR 环境变量设置到脚本的所在目录

5. 源库上备份 xttdriver.pl --backup

6. 拷贝源库的 res.txt 和备份到目标库

7. 在目标库恢复 xttdriver.pl --restore

8. 然后不断做 incremental backup

a). 源库做 incremental backup: xttdriver.pl --backup

b). 源库拷贝incrbackups.txt中刚做的incremental backup到目标库

c). 拷贝 res.txt到目标库

d). 目标库应用 incremental backup (会重启目标库): xttdriver.pl --restore  重复操作

9. Final Incremental Backup 最后一次增量备份

a). 需要把源库的 tablespace 置为只读

b). 最后一次备份: xttdriver.pl --backup

c). 源库拷贝最后的incremental backup到目标库

d). 拷贝 res.txt到目标库

e). 目标库最后一次追平备份: xttdriver.pl --restore

10. Transport Phase:

把metadata从源库导出再导入到目标库 测试的准备阶段:

a). 先在原库创建测试用户和数据 创建两个tablespace 一个放数据一个放索引

create tablespace test datafile '+data' size 100m;

create tablespace test_ind datafile '+data' size 100m;

grant dba to test identified by test;

alter user test default tablespace test;

conn test/test

create table test1 as select * from dba_source;

create index test1_ind on test1(line) tablespace test_ind;

create or replace procedure copy_table_status(src_owner varchar2, src_tabname varchar2, trg_owner varchar2, trg_tabname varchar2) Authid Current_User is n_numrows all_tables.num_rows%TYPE; n_numblks all_tables.blocks%TYPE;

n_avgrlen all_tables.avg_row_len%TYPE;

n_invalidate boolean default false;

begin

dbms_stats.get_table_stats(ownname => upper(src_owner), tabname => upper(src_tabname), numrows => n_numrows, numblks => n_numblks, avgrlen => n_avgrlen);

dbms_stats.set_table_stats(ownname => upper(trg_owner), tabname => upper(trg_tabname), numrows => n_numrows, numblks => n_numblks, avgrlen => n_avgrlen, no_invalidate => n_invalidate);

end;

/

b). 在原库检查一些限制 比如

-- 原库需要启用 archive log mode

-- 原库的 COMPATIBLE 参数不能大于目标库

-- 原库的 rman 设置:

DEVICE TYPE DISK 不能设置为 COMPRESSED 

BACKUP TYPE 不能设置为 COPY (需要设置为 BACKUP TYPE TO BACKUPSET)

channel 不能设置为 SBT channel 不能有限制,比如 MAXSETSIZE,MAXPIECESIZE等

-- 要传输的 tablespace 不能有 offline 的 datafile,

tablespace状态应当是 READ WRITE

-- 如果目标端不是 Linux,则 DB 版本应大于 12.1.0.1

-- 原库的 DB 版本不应大于目标端 DB 版本

-- 原库/目标库 DB 版本应当大于 11.2.0.4

-- 临时的备份不应当放到 ASM 中 (ASM是能用来放置最后的 datafile)

- enable archived log

SQL> alter system set db_recovery_file_dest_size=10g scope=both sid='*';

SQL> alter system set db_recovery_file_dest='+data' scope=both sid='*';

SQL> shutdown immediate

SQL> startup mount

SQL> alter database archivelog;

SQL> alter database open;

--- check RMAN setting

RMAN> show all;

CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET;

# default

-- check COMPATIBLE parameter

SQL> show parameter COMPATIBLE

c). 另外,详细阅读 Note 2471245.1 的 Known Issues 中提到的注意事项 比如:原库和目标库都不应有自定义的 glogin.sql

开始实施XTTS

Step 1.1: 在目标端安装软件,创建数据库以及创建相关的用户

– 在目标端创建用户 test sqlplus / as sysdba 

grant dba to test identified by test;

Grant succeeded.

Step1.2: 确定要做 xtts 的表空间,并确定满足基本的 transportable tablespace 的条件

通读下面的文档来更详细的了解Transportable tablespace,

确保两边满足 Transportable tablespace 的条件 Master Note for Transportable Tablespaces (TTS)

-- Common Questions and Issues (Doc ID 1166564.1) Transportable Tablespace (TTS) Restrictions and Limitations: Details, Reference,

and Version Where Applicable (Doc ID 1454872.1) 比如

-- 在原库执行DBMS_TTS.TRANSPORT_SET_CHECK检查是否要 transport 的 tablespace 是自包含的

CONN / AS SYSDBA

SQL> EXEC SYS.DBMS_TTS.TRANSPORT_SET_CHECK(ts_list => 'TEST,TEST_IND', incl_constraints => TRUE);

PL/SQL procedure successfully completed.

SQL> SELECT * FROM transport_set_violations;

no rows selected

<== 确保执行 DBMS_TTS.TRANSPORT_SET_CHECK 之后,transport_set_violations没有返回任何行

Step 1.3 从 note 2471245.1下载 rman_xttconvert_VER4.zip到原库,解压

[oracle@frac1 xtts]$pwd

/home/oracle/xtts

[oracle@frac1 xtts]$ ls

rman_xttconvert_VER4.3.zip

xttcnvrtbkupdest.sql

xttdbopen.sql

xttdriver.pl xtt.newproperties

xttprep.tmpl xtt.properties x

ttstartupnomount.sql Step

 

1.4 在原库和目标库创建必须的目录

原库:创建一个目录存放备份 (对应的是 xtt.properties 中的 src_scratch_location 参数)

$ mkdir /home/oracle/xtts_backup

目标库:创建一个目录存放备份 (对应的是 xtt.properties 中的 dest_scratch_location 参数 )

$ mkdir /home/oracle/xtts_backup_dest

目标库:另外,还要确认目标库里datafile 最后要放置的路径 (对应的是 xtt.properties 中的 dest_datafile_location 参数 )

SQL > select file_name from dba_data_files; FILE_NAME

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

/u01/data/R11204/users01.dbf <==

所以在我们这次测试中,稍后目标库的 xtt.properties 中的 dest_datafile_location 参数应定义为 /u01/data/R11204

Step1.5 在原库配置 xtt.properties 文件 以下是强制需要设置的参数

tablespaces platformid src_scratch_location dest_scratch_location dest_datafile_location (if using 12c or higher)

-- usermantransport=1 tablespaces

在我们这个例子里是以逗号分隔的 TEST,TEST_IND;

platformid是指定原库的 platformid,

可以通过查询原库的 V$DATABASE.PLATFORM_ID 获知:

比如: SQL> select platform_id from v$database;

PLATFORM_ID

-----------

13

<=====

AIX 的 platform_id 并不是 13

注意:因为脚本会自动获取目标库的 platformid,所以这里的platformid是指定原库的 platformid src_scratch_location

在我们这个例子里是

/home/oracle/xtts_backup dest_scratch_location

在我们这个例子里是

/home/oracle/xtts_backup_dest dest_datafile_location

在我们这个例子里是 /u01/data/R11204

这个例子中的这几个参数最后是

$ cat xtt.properties |grep -v ^# |grep -v ^

$ tablespaces=TEST,TEST_IND platformid=13

src_scratch_location=/home/oracle/xtts_backup dest_datafile_location=/u01/data/R11204

dest_scratch_location=/home/oracle/xtts_backup_dest Step

1.6 把原库的 xttconvert 脚本以及修改过的 xtt.properties 拷贝到目标库

注释:下面的 192.168.56.160 是我的测试案例中目标库所在的主机的 IP 地址

$ scp -r /home/oracle/xtts oracle@192.168.56.160:/home/oracle/xtts oracle@192.168.56.160's password: xttdriver.pl

100% 176KB 176.2KB/s 00:00

xtt.newproperties 100% 5169 5.1KB/s 00:00

xttprep.tmpl 100% 11KB 11.4KB/s 00:00

xttstartupnomount.sql 100% 52 0.1KB/s 00:00

xttcnvrtbkupdest.sql 100% 1390 1.4KB/s 00:00

xtt.properties 100% 5203 5.1KB/s 00:00

xttdbopen.sql 100% 71 0.1KB/s 00:00

 

Step 1.7 在原库以及目标库要执行操作的 shell 里设置 TMPDIR 环境变量到 rman_xttconvert_VER4 脚本所在的目录

export TMPDIR=/home/oracle/xtts

Step 2.1 在原库设置正确的 ORACLE_HOME 和 ORACLE_SID 参数并执行备份

$ . oraenv ORACLE_SID = [R112041] 

The Oracle base remains unchanged with value /u01/app/oracle

[oracle@frac1 ~]$ echo $ORACLE_HOME /u01/app/oracle/product/11.2.0/dbhome_1

[oracle@frac1 ~]$ echo $ORACLE_SID R112041 并执行备份

$ cd /home/oracle/xtts

$ORACLE_HOME/perl/bin/perl xttdriver.pl --backup

Step 2.2 把原库生成的备份以及 res.txt 文件拷贝到目标库

– 拷贝备份从原库的 src_scratch_location 到目标库的 dest_scratch_location

--在原库执行 $ scp -r /home/oracle/xtts_backup/*oracle@192.168.56.160:/home/oracle/xtts_backup_dest

oracle@192.168.56.160's password: TEST_IND_7.tf 100% 100MB 100.0MB/s 00:01

TEST_6.tf 100% 100MB 100.0MB/s 00:01

-– 把 /home/oracle/xtts 目录下的res.txt 文件拷贝到目标库的/home/oracle/xtts 目录下

--在原库执行$ scp res.txt oracle@192.168.56.160:/home/oracle/xtts/ oracle@192.168.56.160's password:

res.txt 100% 118 0.1KB/s 00:00 S

tep 2.3 在目标库应用备份

-- 设置 ORACLE_HOME 和 ORACLE_SID 环境变量

[oracle@oslab ~]$ echo $ORACLE_HOME

/u01/app/oracle/product/11.2.0.4

[oracle@oslab ~]$ echo $ORACLE_SID R11204

-- 在目标库应用备份

[oracle@oslab ~]$

cd /home/oracle/xtts/

[oracle@oslab xtts]

 $ORACLE_HOME/perl/bin/perl xttdriver.pl --restore

Step 3.1 接下来是做增量备份并应用到目标端 (注意!!! 下面的步骤里会重启目标端的数据库)

– 在原库做增量备份 $ORACLE_HOME/perl/bin/perl xttdriver.pl --backup

Step 3.2 把增量备份以及 res.txt 拷贝到目标库 拷贝备份从原库的 src_scratch_location 到目标库的 dest_scratch_location

--在原库执行

cd /home/oracle/xtts/

$ scp `cat incrbackups.txt` oracle@192.168.56.160:/home/oracle/xtts_backup_dest oracle@192.168.56.160's password:

04vqapf3_1_1 100% 40KB 40.0KB/s 00:00 03

vqapf2_1_1 100% 40KB 40.0KB/s 00:00

$ scp res.txt oracle@192.168.56.160:/home/oracle/xtts/ oracle@192.168.56.160's password:

res.txt 100% 260 0.3KB/s 00:00 Step

 

3.3 在目标库应用增量备份 (这个步骤会重启目标端数据库)

-- 在目标库执行

cd /home/oracle/xtts/ $ORACLE_HOME/perl/bin/perl xttdriver.pl --restore

注意!!! Step 3.1 到 Step 3.3 可以反复操作来实现目标库追平原库的目的,直到最终做 transportable tablespace 的最后步骤

Step 4.1 这个步骤是原库的 tablespace 置为只读 (稍后会做最后一次增量备份并在目标端最后一次应用增量备份)

-- 在原库把 test, test_ind tablespace置为只读 (此时应用就不能修改数据了)

SQL> alter tablespace TEST read only; Tablespace altered. SQL> alter tablespace TEST_IND read only; Tablespace altered.

Step 4.2 在原库做最后一次增量备份 $ORACLE_HOME/perl/bin/perl xttdriver.pl --backup

这次会有下面的 warning, 但可以忽略

####################################################################

Warning: ------ Warnings found in executing /home/oracle/xtts/backup_Mar21_Sun_20_32_11_889//xttpreparenextiter.sql

####################################################################

Prepare newscn for Tablespaces: 'TEST_IND' DECLARE* ERROR at line 1: ORA-20001: TABLESPACE(S) IS READONLY OR, OFFLINE JUST CONVERT, COPY ORA-06512: at line 284 ####################################################################

Warning: ------ Warnings found in executing /home/oracle/xtts/backup_Mar21_Sun_20_32_11_889//xttpreparenextiter.sql

####################################################################

Step 4.3 把增量备份以及 res.txt 传输至目标端 --在原库执行

$ cd /home/oracle/xtts/

$ scp `cat incrbackups.txt` oracle@192.168.56.160:/home/oracle/xtts_backup_dest

$ scp res.txt oracle@192.168.56.160:/home/oracle/xtts/

Step 4.4 在目标端应用最后一次增量备份

--在目标库执行 $ORACLE_HOME/perl/bin/perl xttdriver.pl --restore

Step 5.1 从原库导出对应 tablespace 的 metadata --在原库执行下面的操作,注意替换 directory, transport_tablespaces 以及用户名密码信息

$ expdp system/oracle dumpfile=xttdump.dmp directory=DATA_PUMP_DIR statistics=NONE transport_tablespaces=TEST,TEST_IND transport_full_check=y logfile=tts_export.log

在我的案例中生成的 dump 文件如下 /u01/app/oracle/product/11.2.0/dbhome_1/rdbms/log/xttdump.dmp

Step 5.2 拷贝 dmp 文件到目标库

$ scp /u01/app/oracle/product/11.2.0/dbhome_1/rdbms/log/xttdump.dmp oracle@192.168.56.160:/home/oracle/xtts/

Step 5.3 导入到目标库

--导入目标库:需要修改 directory以及transport_datafiles指定的目录以及文件名字(datafile名可能会发生改变)

$ ls  /u01/data/R11204/TEST*

 /u01/data/R11204/TEST_6.dbf

/u01/data/R11204/TEST_IND_7.dbf

$ impdp system/oracle dumpfile=xttdump.dmp directory=xtts transport_datafiles='/u01/data/R11204/TEST_6.dbf','/u01/data/R11204/TEST_IND_7.dbf'

Step 6.1 在收尾的部分,我们会先验证迁移过来的 datafile 的一致性

--目标库 $ rman target / RMAN>

validate tablespace 'TEST','TEST_IND' check logical;

 

Step 6.2 最后把两个 tablespace 置为 READ WRITE模式

--目标库 sqlplus / as sysdba

alter tablespace TEST read write;

alter tablespace TEST_IND read write;

 

参考mos 提供方案写的。

posted on 2021-04-02 15:35  包子没馅  阅读(491)  评论(0编辑  收藏  举报

导航