1前期准备
1.1. 检查数据库时区,保持两边一致
select dbtimezone from dual;
DBTIME
------
+08:00
1.2. 检查数据库字符集,保持两边一致
select * from nls_database_parameters where parameter like '%CHARACTERSET%';
PARAMETER VALUE
------------------------------------------------------------------
NLS_CHARACTERSET AL32UTF8
NLS_NCHAR_CHARACTERSET UTF8
1.3. 检查目标端补丁情况
目标端 PSU无特殊需求,可以随情况安装最新即可。
select 'opatch',comments from dba_registry_history;
'OPATC COMMENTS
--------------------------------------------------------
opatch PSU 11.2.0.4.4
如果准备阶段使用 DBMS_FILE_TRANSFER方法,目标端建议安装的补丁如下:
Patch 19023822,修复目标端使用 DBMS_FILE_TRANSFER.GET_FILE包获取源端数据文件出现 ORA-03106 的情况。
Patch 22171097: MERGE REQUEST ON TOP OF DATABASE PSU11.2.0.4.6 FOR BUGS 17534365 19023822
如果准备阶段使用 RMAN 方法,目标端没有小补丁安装需求。
1.4. 检查组件安装情况,对于不一样的组件,需要有所标记
Select comp_name from dba_registry;
源端组件情况
COMP_NAME
--------------------------------------------------------------------------------
OracleApplication Express
OracleMultimedia
OracleXML Database
OracleExpression Filter
OracleRules Manager
OracleWorkspace Manager
OracleDatabase Catalog Views
OracleDatabase Packages and Types
JServerJAVA Virtual Machine
OracleXDK
OracleDatabase Java Packages
目标段组件情况
COMP_NAME
--------------------------------------------------------------------------------
OracleEnterprise Manager
OracleWorkspace Manager
OracleDatabase Catalog Views
OracleDatabase Packages and Types
备注:组件不同,可能导致源端的部分对象无法导入到目标端。
1.5. 检查是否使用了 Key Compression 的索引组织表
Key compression
select index_name,table_name from dba_indexes where compression='ENABLED';
索引组织表
select owner,table_name from dba_tables where iot_type is not null;
如果存在,目标端需要安装 Patch 14835322,否则索引组织表的对象无法导入到目标端。
目前该补丁只在 11.2.0.3 版本下提供,针对其他版本,如果 IOT表或者键值压缩索引无法导入时,建议在元数据导入完成后,将该类对象传输过去。
1.6. 检查源端是否有 Cluster 对象
If the sourcecontains cluster objects, then run "analyze cluster &cluster_namevalidate structure cascade" after XTTS has been completed in the targetdatabase and if it reports an ORA-1499 open the trace file and review if it hasentries like:
kdcchk: indexpoints to block 0x01c034f2 slot 0x1 chain length is 256
kdcchk: chain count wrong 0x01c034f2.1 chain is 1 index says 256
last entry 0x01c034f2.1 blockcount = 1
kdavls: kdcchk returns 3 when checking cluster dba 0x01c034a1 objn 90376
Then to repairthis inconsistency either:
1. rebuild thecluster index.
or
2. Install fix bug 17866999 and run dbms_repair.repair_cluster_index_keycount
If afterrepairing the inconsistency the "analyze cluster &cluster_namevalidate structure cascade" still reports issues then recreate theaffected cluster which involves recreating its tables.
1.7. 检查 RMAN DEVICE TYPE DISK 是否配置 COMPRESSED
ORA-19837:invalid blocksize 0 in backup piece header
ORA-06512: at "SYS.X$DBMS_BACKUP_RESTORE", line 2338
ORA-06512: at line 40
配置压缩会导致以上报错,通过rman > show all; 检查
1.8. SYS、SYSTEM 用户是否有对象存在于业务表空间
如数据库用户 SYS、SYSTEM 在业务表空间上创建有对象,则这些对象不能通过 XTTS 迁移,需要在目标库手工创建。
select table_name, owner, tablespace_name from dba_tables where tablespace_name not in('SYSTEM','SYSAUX') and owner in ('SYS','SYSTEM');
1.9. 检查表空间自包含
在传输阶段可能因为目标端数据文件目录所限制,需要将各个表空间拆分进行传送,在导入元数据阶段,考虑到字包含特性,需要将所有的表空间汇总进行传送。
检查表空间时,只检查业务表空间的自包含情况;系统表空间,临时表空间,undo 表空间不在检查列。
exec dbms_tts.transport_set_check('将所有需要传输的表空间名写在这里用逗号隔开' ,TRUE,True);
select * fromtransport_set_violations;
1.10. 检查源端 Compatible 参数
source 端不可以是 windows P7,source 端的 COMPATIBLE.RDBMS 必须大于 10.2.0,且不大于目标端 COMPATIBLE.RDBMS
show parameter compatible
如果目标端数据库版本是 11.2.0.3 或更低。那么需要在目标端装 11.2.0.4 并创建实例,然后用来进行备份集转换。如果 11.2.0.4 中转实例使用 ASM。那么 ASM 版本也必须是 11.2.0.4,否则报错 ORA-15295。
1.11. 如果启用 Block Change Tracking 功能
该功能在源端数据量较大或者数据改变较大时启用,需要在源端安装补丁 Bug 16850197。
该补丁在以下版本 PSU中提供
2.0.3.9
2.0.4
如果源库是在上述版本前,需要安装个别补丁。
1.12. 检查目标端的 DB_FILES 参数
在元数据导入阶段,如果目标端的 DB_FILES 参数小于源端的 DB_FILES 参数,会导致元数据导入出错,所以要确保目标端参数比源端大于或者等于。
Show parameter db_files
1.13. 确认生产库的 recycle in 功能是关闭,并手工清空回收站
Show parameter recyclebin;
NAME TYPE VALUE
--------------------------------- --------
recyclebin string on (这里应该为 off)
关闭回收站
alter system set recyclebin='off' scope=both;
alter system set recyclebin=off scope=spfile;
Shutdown immediate;
Startup;
关闭回收站功能后,不能回闪表。
1.scope=memory修改后当前就起作用,重启数据库不起作用 2.scope=spfile修改后当前不起作用,下次重启数据库才起作用 3.scope=both修改后当前起作用,下次重启数据库也起作用 |
1.14. 数据文件状态检查
Select distinct status from v$datafile;
正常返回应为:ONLINE、SYSTEM。
2 XTTS 操作步骤
a. 迁移步骤大致如下:
b. 初始化阶段,配置参数文件
c. 开启块追踪特性
d. 准备阶段,进行数据全量同步
e. 增量阶段,进行数据文件的增量同步
f. 在停机同步前,在目标端新建 Owner 用户,临时表
g. 传输阶段,最后一次增量同步,并导入元数据
h. 将原库中的其余用户导入到目标端中
i. 校验数据文件,检查有无坏块
3 RMAN 方式
注意:
使用 RMAN方式有一个严重的限制:同一批次的表空间传输到目标端后,都在同一个目录下,即目标端的最终存放数据文件的目录大小要足够存放一个批次中所有的表空间数据文件。
源端和目标端需要挂载存储用于存放所有数据文件的镜像文件,建议使用 NFS 的方式将存储远程从源端挂载到目标端,减少备份传送时间。
3.1. 初始化阶段,配置参数文件
3.1.1. 创建 Dest 端到 Source 端的 DBLINK
该步骤创立的 DBLINK用于在传输阶段的元数据导入时使用
源端:
create tablespace test1 datafile '/oracle/oradata/orcl/test1.dbf' size 10m autoextend on;
create user test1 identified by test1 default tablespace test1;
grant dba to test1;
目标端:
create tablespace test2 datafile '/oracle/oradata/orcl/test2.dbf' size 10m autoextend on;
create user test2 identified by test2 default tablespace test2;
grant dba to test2;
Service1 to service2
create public database link XTTSLINK
connect to TEST2 identified by test2
using '(DESCRIPTION=(CONNECT_DATA=(SERVICE_NAME=orcl))(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.228)(PORT=1521)))';
Service2 to service1
create public database link XTTSLINK
connect to TEST1 identified by test1
using '(DESCRIPTION=(CONNECT_DATA=(SERVICE_NAME=orcl))(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.117)(PORT=1521)))';
测试DBLINK的连通性
select * from v$version@XTTSLINK;
3.1.2. Source 端和 Dest 端创建目录用于存放 XTTS脚本
[oracle@source]$ pwd
/home/oracle/xtt2
[oracle@source]$ unzip rman_xttconvert_v3.zip
unzip rman-xttconvert_2.0.zip----self
Archive: rman_xttconvert_v3.zip
inflating: xtt.properties
inflating: xttcnvrtbkupdest.sql
inflating: xttdbopen.sql
inflating: xttdriver.pl
inflating: xttprep.tmpl
extracting: xttstartupnomount.sql
解压和创建目录后,一定要创建权限(所有),否则无法执行。
3.2. 开启块追踪特性(暂时没用,数据量少)
SQL> alter database enable block change tracking using file '+datadg';
Database altered.
按照文档所示,开启这个特性后,使用 XTTS会触发 BUG16850197,需要安装个别补丁,但是目前该补丁只在 11.2.0.3.8 上有提供。
经过测试,其余版本没有触发 bug。
注意:
RAC 环境下,需要将块追踪文件存放在共享存储上,否则会导致 DFS LOCKHANDLE,导致实例异常。
3.3. 准备阶段,进行数据全量同步
3.3.1. 修改参数
源端平台 ID 查询
select * from v$transportable_platform
/home/oracle/xtt2/ xtt.properties
vi /home/oracle/xtt2/xtt.properties----self
tablespaces=TEST1 需要大写
platformid=13
dfcopydir=/home/oracle/xtt2/dfcopydir
backupformat=/home/oracle/xtt2/backup
stageondest=/home/oracle/xtt2/stageondest
storageondest=/oggtest/oggtest
backupondest=/home/oracle/xtt2/backupondest
parallel=2
rollparallel=2
mkdir /home/oracle/xtt2/dfcopydir
mkdir /home/oracle/xtt2/backup
mkdir /home/oracle/xtt2/stageondest
mkdir /home/oracle/xtt2/backupondest
mkdir /oracle/oradata/orcl--------不用建,本来就有
mkdir /oggtest/oggtest------------这个赋予777,很麻烦
解压和创建目录后,一定要创建权限(所有),否则无法执行。20180702做到次
附录解释:
tablespaces= ----需要迁移的表空间
platformid= ----源 OS 平台 ID
dfcopydir= ----源数据库备份文件存放目录
backupformat= ---源数据库增备文件存放目录
stageondest= ----目标据库备份文件存放目录
storageondest= ----目标据库正式文件存放目录
backupondest= ----目标据库增备文件存放目录
parallel= ----备份,转化的并行度
rollparallel= ----增备的并行度
getfileparallel= ---- 使用 dbms_file_transfer 方式的并行度
我的:
tablespaces=TEST1
platformid=13
dfcopydir=/home/oracle/xtt2/dfcopydir
backupformat=/home/oracle/xtt2/backup
stageondest=/home/oracle/xtt2/stageondest
storageondest=/oggtest/oggtest
backupondest=/home/oracle/xtt2/backupondest
parallel=2
rollparallel=2
3.3.2. 将 XTTS目录 Copy 传送到目标端
scp -rp /home/oracle/xtt2/ 192.168.1.228:/home/oracle/
-p是带权限复制
3.3.3. 设置 TMPDIR
If TMPDIR is not set, output files are created in and input files are expected to be in /tmp.
[oracle@service1 ]$ export TMPDIR=/home/oracle/xtt2
[oracle@service2 ]$ export TMPDIR=/home/oracle/xtt2
源端开启归档:
Shutdown immediate
Startup mount
Alter database archivelog;
3.3.4. 源端 Prepare(以下所有命令,建议在xtt2目录中,否则容易出现报错)
初始化之后产生 xttplan.txt rmanconvert.cmd
xttplan.txt 记录了当前 SCN,也就是下次需要增量的开始 SCN
rmanconvert.cmd 记录了文件转换的名字
[oracle@service1 xtt2]$ $ORACLE_HOME/perl/bin/perl /home/oracle/xtt2/xttdriver.pl -p开启归档20180707
--------------------------------------------------------------------
Parsing properties
--------------------------------------------------------------------
--------------------------------------------------------------------
Done parsing properties
--------------------------------------------------------------------
--------------------------------------------------------------------
Checking properties
--------------------------------------------------------------------
--------------------------------------------------------------------
Done checking properties
--------------------------------------------------------------------
--------------------------------------------------------------------
Starting prepare phase
--------------------------------------------------------------------
Prepare source for Tablespaces:
'TEST1' /home/oracle/xtt2/stageondest
xttpreparesrc.sql for 'TEST1' started at Sat Jul 7 11:27:43 2018
xttpreparesrc.sql for ended at Sat Jul 7 11:27:44 2018
Prepare source for Tablespaces:
'' /home/oracle/xtt2/stageondest
xttpreparesrc.sql for '' started at Sat Jul 7 11:27:47 2018
xttpreparesrc.sql for ended at Sat Jul 7 11:27:47 2018
--------------------------------------------------------------------
Done with prepare phase
--------------------------------------------------------------------
[oracle@service1 xtt2]$
报错:
[oracle@service1 xtt2]$ $ORACLE_HOME/perl/bin/perl /home/oracle/xtt2/xttdriver.pl -p
--------------------------------------------------------------------
Parsing properties
--------------------------------------------------------------------
--------------------------------------------------------------------
Done parsing properties
--------------------------------------------------------------------
--------------------------------------------------------------------
Checking properties
--------------------------------------------------------------------
--------------------------------------------------------------------
Done checking properties
--------------------------------------------------------------------
--------------------------------------------------------------------
Starting prepare phase
--------------------------------------------------------------------
Prepare source for Tablespaces:
'TEST1' /home/oracle/xtt2/stageondest
xttpreparesrc.sql for 'TEST1' started at Sat Jul 7 18:12:05 2018
xttpreparesrc.sql for ended at Sat Jul 7 18:12:06 2018
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Error:
------
Error in executing xttpreparesrc.sql
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
查看报错:xttprepare.cmd1530958325
DECLARE
*
ERROR at line 1:
ORA-20001: TABLESPACE(S) IS READONLY OR,
OFFLINE JUST CONVERT, COPY
ORA-06512: at line 282
也就是说表空间现在是只读;更改表空间属性:
[oracle@service1 ~]$ sqlplus sys/WXHWXH AS SYSDBA
SQL*Plus: Release 11.2.0.4.0 Production on Sat Jul 7 18:13:00 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> ALTER TABLESPACE test1 read write
2 ;
Tablespace altered.
3.3.5. 源端生成的数据文件 Copy 到目标端
[oracle@service1 xtt2]$ scp -p dfcopydir/TEST1_6.tf 192.168.1.228:/home/oracle/xtt2/stageondest
oracle@192.168.1.228's password:
TEST1_6.tf
-p意思是复制权限
3.3.6. 转换数据文件 Copy 的 Endian 模式
export TMPDIR=/home/oracle/xtt2---------------------源端
[oracle@service1 xtt2]$ scp -p rmanconvert.cmd 192.168.1.228:/home/oracle/xtt2
oracle@192.168.1.228's password:
rmanconvert.cmd -------------------源端
-----------------目标端:
[oracle@service2 xtt2]$ $ORACLE_HOME/perl/bin/perl /home/oracle/xtt2/xttdriver.pl -c
--------------------------------------------------------------------
Parsing properties
--------------------------------------------------------------------
--------------------------------------------------------------------
Done parsing properties
--------------------------------------------------------------------
--------------------------------------------------------------------
Checking properties
--------------------------------------------------------------------
--------------------------------------------------------------------
Done checking properties
--------------------------------------------------------------------
--------------------------------------------------------------------
Performing convert
--------------------------------------------------------------------
--------------------------------------------------------------------
Converted datafiles listed in: /home/oracle/xtt2/xttnewdatafiles.txt
--------------------------------------------------------------------
转换成功之后会生成 xttnewdatafiles.txt
整个过程,存放在 stageondest 的 copy,将会转换写入到 storageondest 参数设置的最终存放点(/oggtest/oggtest)。转换完成后,copy 就可以删除了。
3.4. 增量阶段,进行数据文件的增量同步
3.4.1. 源端创建增量备份
[oracle@service1 xtt2]$ $ORACLE_HOME/perl/bin/perl /home/oracle/xtt2/xttdriver.pl -i ------------20180707
--------------------------------------------------------------------
Parsing properties
--------------------------------------------------------------------
--------------------------------------------------------------------
Done parsing properties
--------------------------------------------------------------------
--------------------------------------------------------------------
Checking properties
--------------------------------------------------------------------
--------------------------------------------------------------------
Done checking properties
--------------------------------------------------------------------
--------------------------------------------------------------------
Backup incremental
--------------------------------------------------------------------
Prepare newscn for Tablespaces: 'TEST1'
Prepare newscn for Tablespaces: ''
rman target / cmdfile /home/oracle/xtt2/rmanincr.cmd
Recovery Manager: Release 11.2.0.4.0 - Production on Sat Jul 7 11:57:12 2018
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL (DBID=1499662243)
RMAN> set nocfau;
2> host 'echo ts::TEST1';
3> backup incremental from scn 1149584
4> tag tts_incr_update tablespace 'TEST1' format
5> '/home/oracle/xtt2/backup/%U';
6>
executing command: SET NOCFAU
using target database control file instead of recovery catalog
ts::TEST1
host command complete
Starting backup at 07-JUL-18
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=197 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00006 name=/oracle/oradata/orcl/test1.dbf
channel ORA_DISK_1: starting piece 1 at 07-JUL-18
channel ORA_DISK_1: finished piece 1 at 07-JUL-18
piece handle=/home/oracle/xtt2/backup/03t7db0q_1_1 tag=TTS_INCR_UPDATE comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 07-JUL-18
Recovery Manager complete.
--------------------------------------------------------------------
Done backing up incrementals
--------------------------------------------------------------------
[oracle@service1 xtt2]$
第一次增量备份之后产生的配置文件为 tsbkupmap.txt incrbackups.txt,这两个为增量与数据文件对应关系配置,在做增量恢复时候需要用到。增量备份文件放在了backupformat 指定位置。
3.4.2. 传输增量备份到目标端
[oracle@sprac1 xtt2]$ scp -p /home/oracle/xtt2/backup/03t7db0q_1_1 192.168.1.228:/home/oracle/xtt2/stageondest
3.4.3. 目标端应用增量备份
[oracle@service1 xtt2]$ scp -p xttplan.txt tsbkupmap.txt 192.168.1.228:/home/oracle/xtt2
OR (scp -p /home/oracle/xtt2/xttplan.txt 192.168.1.228:/home/oracle/xtt2/
scp -p /home/oracle/xtt2/tsbkupmap.txt 192.168.1.228:/home/oracle/xtt2/)
[oracle@service2 xtt2]$ perl xttdriver.pl -r 目标端执行
[oracle@service2 xtt2]$ $ORACLE_HOME/perl/bin/perl /home/oracle/xtt2/xttdriver.pl -r
--------------------------------------------------------------------
Parsing properties
--------------------------------------------------------------------
--------------------------------------------------------------------
Done parsing properties
--------------------------------------------------------------------
--------------------------------------------------------------------
Checking properties
--------------------------------------------------------------------
--------------------------------------------------------------------
Done checking properties
--------------------------------------------------------------------
--------------------------------------------------------------------
Start rollforward
--------------------------------------------------------------------
--------------------------------------------------------------------
End of rollforward phase
--------------------------------------------------------------------
[oracle@service2 xtt2]$
3.4.4. 源端为之后的增量备份确定新的 SCN
[oracle@service1 xtt2]$ $ORACLE_HOME/perl/bin/perl /home/oracle/xtt2/xttdriver.pl -s
--------------------------------------------------------------------
Parsing properties
--------------------------------------------------------------------
--------------------------------------------------------------------
Done parsing properties
--------------------------------------------------------------------
--------------------------------------------------------------------
Checking properties
--------------------------------------------------------------------
--------------------------------------------------------------------
Done checking properties
--------------------------------------------------------------------
Prepare newscn for Tablespaces: 'TEST1'
Prepare newscn for Tablespaces: ''
New /home/oracle/xtt2/xttplan.txt with FROM SCN's generated
[oracle@service1 xtt2]$
该步骤会将 -i 时生成的 xttplan.txt.new 改名为 xttplan.txt,并将原来的 xttplan.txt 备份。
3.4.5. 重复前滚操作
重复操作步骤 3.4.1 - 3.4.4,恢复增量数据。
3.5. 停机同步前,在目标端新建 Owner 用户(已经在上面建立)
3.6. 传输阶段,最后一次增量同步,并导入元数据
3.6.1. 将原库表空间置为只读状态
SQL> alter tablespace test1 read only;
3.6.2. 开始最后做增量备份
重复步骤 3.4.1 - 3.4.3,做最后的增量恢复。( 3.4.4!!!)
3.4.1. 源端创建增量备份
[oracle@service1 xtt2]$ $ORACLE_HOME/perl/bin/perl /home/oracle/xtt2/xttdriver.pl -i
--------------------------------------------------------------------
Parsing properties
--------------------------------------------------------------------
--------------------------------------------------------------------
Done parsing properties
--------------------------------------------------------------------
--------------------------------------------------------------------
Checking properties
--------------------------------------------------------------------
--------------------------------------------------------------------
Done checking properties
--------------------------------------------------------------------
--------------------------------------------------------------------
Backup incremental
--------------------------------------------------------------------
Prepare newscn for Tablespaces: 'TEST1'
Prepare newscn for Tablespaces: ''
rman target / cmdfile /home/oracle/xtt2/rmanincr.cmd
Recovery Manager: Release 11.2.0.4.0 - Production on Sat Jul 7 14:36:41 2018
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL (DBID=1499662243)
RMAN> set nocfau;
2> host 'echo ts::TEST1';
3> backup incremental from scn 1206414
4> tag tts_incr_update tablespace 'TEST1' format
5> '/home/oracle/xtt2/backup/%U';
6>
executing command: SET NOCFAU
using target database control file instead of recovery catalog
ts::TEST1
host command complete
Starting backup at 07-JUL-18
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=69 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00006 name=/oracle/oradata/orcl/test1.dbf
channel ORA_DISK_1: starting piece 1 at 07-JUL-18
channel ORA_DISK_1: finished piece 1 at 07-JUL-18
piece handle=/home/oracle/xtt2/backup/08t7dkbq_1_1 tag=TTS_INCR_UPDATE comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 07-JUL-18
Recovery Manager complete.
--------------------------------------------------------------------
Done backing up incrementals
3.4.2. 传输增量备份到目标端
[oracle@service1 xtt2]$ scp -p /home/oracle/xtt2/backup/08t7dkbq_1_1 192.168.1.228:/home/oracle/xtt2/stageondest
oracle@192.168.1.228's password:
08t7dkbq_1_1 100% 48KB 48.0KB/s 00:00
3.4.3. 目标端应用增量备份
[oracle@service1 xtt2]$ scp -p xttplan.txt tsbkupmap.txt 192.168.1.228:/home/oracle/xtt2
oracle@192.168.1.228's password:
xttplan.txt tsbkupmap.txt
应用增量备份:
[oracle@service2 xtt2]$ $ORACLE_HOME/perl/bin/perl /home/oracle/xtt2/xttdriver.pl -r
--------------------------------------------------------------------
Parsing properties
--------------------------------------------------------------------
--------------------------------------------------------------------
Done parsing properties
--------------------------------------------------------------------
--------------------------------------------------------------------
Checking properties
--------------------------------------------------------------------
--------------------------------------------------------------------
Done checking properties
--------------------------------------------------------------------
--------------------------------------------------------------------
Start rollforward
--------------------------------------------------------------------
--------------------------------------------------------------------
End of rollforward phase
--------------------------------------------------------------------
源端导出元数据:
[oracle@service1 xtt2]$ expdp test3/test3 directory=sourcedir dumpfile=test1.dmp transport_tablespaces=TEST1 transport_full_check=y
Export: Release 11.2.0.4.0 - Production on Sat Jul 7 14:42:47 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
Starting "TEST3"."SYS_EXPORT_TRANSPORTABLE_01": test3/******** directory=sourcedir dumpfile=test1.dmp transport_tablespaces=TEST1 transport_full_check=y
Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
Processing object type TRANSPORTABLE_EXPORT/TABLE
Processing object type TRANSPORTABLE_EXPORT/TABLE_STATISTICS
Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
Master table "TEST3"."SYS_EXPORT_TRANSPORTABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for TEST3.SYS_EXPORT_TRANSPORTABLE_01 is:
/oracle/oradata/orcl/test1.dmp
******************************************************************************
Datafiles required for transportable tablespace TEST1:
/oracle/oradata/orcl/test1.dbf
Job "TEST3"."SYS_EXPORT_TRANSPORTABLE_01" successfully completed at Sat Jul 7 14:43:37 2018 elapsed 0 00:00:50
复制到目标库:
scp -p /oracle/oradata/orcl/test1.dmp 192.168.1.228:/oracle/oradata/orcl/
目标库导入元数据和数据:
在目标端创建用户,但是不能创建test1表空间,否则无法导入(ORA-29349: tablespace 'TEST1' already exists
):
create user test1 identified by test1 ;
grant dba to test1;
[oracle@service2 xtt2]$ impdp test2/test2 DUMPFILE=test1.dmp DIRECTORY=destdir TRANSPORT_DATAFILES='/oggtest/oggtest/TEST1_6.xtf'
Import: Release 11.2.0.4.0 - Production on Sat Jul 7 18:50:59 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 "TEST2"."SYS_IMPORT_TRANSPORTABLE_01" successfully loaded/unloaded
Starting "TEST2"."SYS_IMPORT_TRANSPORTABLE_01": test2/******** DUMPFILE=test1.dmp DIRECTORY=destdir TRANSPORT_DATAFILES=/oggtest/oggtest/TEST1_6.xtf
Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
Processing object type TRANSPORTABLE_EXPORT/TABLE
Processing object type TRANSPORTABLE_EXPORT/TABLE_STATISTICS
Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
Job "TEST2"."SYS_IMPORT_TRANSPORTABLE_01" successfully completed at Sat Jul 7 18:51:17 2018 elapsed 0 00:00:13
更改默认表空间:
alter user test1 default tablespace TEST1;
更改表空间为读写:
ALTER TABLESPACE test1 read write;
当然也可以:impdp test2/test2 DUMPFILE=test1.dmp DIRECTORY=destdir TRANSPORT_DATAFILES='/oggtest/oggtest/TEST1_6.xtf' REMAP_SCHEMA=test1:test2
REMAP_SCHEMA
Default: none
Purpose
Loadsall objects from the source schema into a target schema.
Syntax and Description
REMAP_SCHEMA=source_schema:target_schema
特别注意:(1)源端表空间最后一次增量必须是只读;导出元数据也是在只读情况下;(2)经测验:TEST1_6.xtf(数据文件)不能删除,元数据文件可以删除。否则报错如下:
SQL> startup
ORACLE instance started.
Total System Global Area 830930944 bytes
Fixed Size 2257800 bytes
Variable Size 541068408 bytes
Database Buffers 281018368 bytes
Redo Buffers 6586368 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 7 - see DBWR trace file
ORA-01110: data file 7: '/oggtest/oggtest/TEST1_6.xtf'
SQL> shutdown immediate
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Total System Global Area 830930944 bytes
Fixed Size 2257800 bytes
Variable Size 541068408 bytes
Database Buffers 281018368 bytes
Redo Buffers 6586368 bytes
Database mounted.
Database opened.
SQL>
以下是一些引用:
3.6.3. 自定义 Role 处理
---自定义角色,Role(R_INIT_USER)
select GRANTED_ROLE from dba_role_privs whereGRANTEE='XTTS';
create role R_INIT_USER;
select 'grant '||PRIVILEGE||' to '||GRANTEE||';' from dba_sys_privs where grantee='TEST1';
3.6.4. 自定义 Profile 处理
---执行源端保留的 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;
3.6.5. 临时表处理
---创建临时表
@temp_table.sql
源端生产库采集脚本,目标端执行
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 ();
3.6.6. 目标端导入元数据
3.6.6.1. 一次元数据导入
[oracle@sprac2 xtt2]$ perl xttdriver.pl -e
$ORACLE_HOME/perl/bin/perl /home/oracle/xtt2/xttdriver.pl -e
[oracle@service2 xtt2]$ $ORACLE_HOME/perl/bin/perl /home/oracle/xtt2/xttdriver.pl -e
--------------------------------------------------------------------
Parsing properties
--------------------------------------------------------------------
--------------------------------------------------------------------
Done parsing properties
--------------------------------------------------------------------
--------------------------------------------------------------------
Checking properties
--------------------------------------------------------------------
--------------------------------------------------------------------
Done checking properties
--------------------------------------------------------------------
--------------------------------------------------------------------
Generating plugin
--------------------------------------------------------------------
--------------------------------------------------------------------
Done generating plugin file /home/oracle/xtt2/xttplugin.txt
--------------------------------------------------------------------
[oracle@service2 xtt2]$
这个步骤会产生一个导入样本脚本 xttplugin.txt,需要修改如下:
在一次元数据导入阶段,不能开启并行,统计信息导入阶段,可以将会话杀除终止
cat xttplugin.txt
impdp directory=DATA_PUMP_DIRlogfile=tts_imp.log \
network_link=xttlinktransport_full_check=no \
transport_tablespaces=XTTS \
transport_datafiles='/oggtest/oggtest/XTTS_10.xtf' exclude=statistics
[oracle@service2 xtt2]$ vi xttplugin.txt
impdp directory=<DATA_PUMP_DIR> logfile=<tts_imp.log> \
impdp directory=<DATA_PUMP_DIR> logfile=<tts_imp.log> \
network_link=<ttslink> transport_full_check=no \
transport_tablespaces=TEST1 \
transport_datafiles='/oggtest/oggtest/TEST1_6.xtf' exclude=statistics
将统计信息排除,后面开启并行收集统计信息。
3.6.6.2. 二次元数据导入
将第一次没有导入的过程,视图,包,触发器导入。
impdp directory=DATA_PUMP_DIR logfile=tts_imp_2.log network_link=xttlink schemas= 'XTTS' content=metadata_only exclude=index,table,constraint,statistics
3.6.6.3. 重新在目标端搜集统计信息
execDBMS_STATS.GATHER_SCHEMA_STATS(ownname=>'XTTS',ESTIMATE_PERCENT=>5,method_opt=>'forall columns size 1',cascade=>true,force=>true,degree=>12);
3.7. 将原库中的其余用户导入到目标端中,权限处理
使用如下脚本重新赋权
SET SERVEROUTPUT ON
SET LINESIZE 1000
SET FEEDBACK OFF
SET TRIMSPOOL ON
set long 999999
SET PAGESIZE 1000
spool grant_role_priv.sql
select 'grant '||GRANTED_ROLE||' to '||grantee||';'from dba_role_privs where grantee in() and admin_option='NO'
union
select 'grant '||GRANTED_ROLE||' to '||grantee||' withadmin option;' from dba_role_privs where grantee in() and admin_option='YES';
spool off
SET SERVEROUTPUT ON
SET LINESIZE 1000
SET FEEDBACK OFF
set long 999999
SET TRIMSPOOL ON
SET PAGESIZE 1000
spool grant_sys_priv.sql
select 'grant '||privilege||' to '||grantee||';' fromdba_sys_privs where grantee in() and admin_option='NO'
union
select 'grant '||privilege||' to '||grantee||' withadmin option;' from dba_sys_privs where grantee in()and admin_option='YES';
spool off
SET SERVEROUTPUT ON
SET LINESIZE 1000
SET FEEDBACK OFF
SET TRIMSPOOL ON
set long 999999
SET PAGESIZE 1000
spool grant_tab_privs.sql
select 'grant ' || privilege || ' on ' || owner || '.'|| table_name || ' to ' || grantee || ';' from dba_tab_privs where grantee in()grantable='NO'
union
select 'grant ' || privilege || ' on ' || owner || '.'|| table_name || ' to ' || grantee || ' with grant option;' from dba_tab_privswhere grantee in() and grantable='YES';
spool off
3.8. 校验数据文件,检查有无坏块
RMAN> validate tablespace xtts check logical;
3.9. 编译无效对象,进行数据对比。
@$ORACLE_HOME/rdbms/admin/utlrp.sq