expdp和impdp的应用-高版本通过dblink导入到低版本

今天接到要进行数据库用户的部分数据迁移需求,需求如下

IMP、WO、INSA开头的表只要结构,不要数据

B、TEMP、TMP开头的表不用导

其他表需要导出数据和表结构,同时要求导出此用户下的所有其他对象,如:procedure,sequence等

源数据库在远程主机内,我想到的方法是先通过dblink导入到本地 再将dmp文件传输到目标数据库本机下的directory目录下

1、本地数据库和目标数据库的版本和字符集

查看版本:select * from v$version;  

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

目标:Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod

2 、在本地数据库创建database link

create database link dblink73 connect to inas30 identified by inas30 using ‘’orcl01‘’;

3、创建directory--我这里用本地的system用户导出

--我这里用本地的system用户导出

sqlplus / as sysdba

create directory dir as 'F:';

grant all on directory dir to system;

创建目标数据库用户--已有的话就不用创建

create user inas_30 identified by inas_30 default tablespace inas temporary tablespace temp;

grant connect,resource,unlimited tablespace to inas_30;

create directory dir as 'F:';

grant all on directory DUMP_INAS30_73 to inas30_73;

4、筛选需要导出数据的表

---筛选表
select a.TABLE_NAME,a.TABLESPACE_NAME from user_tables a
minus
select b.TABLE_NAME,b.TABLESPACE_NAME from user_tables b where b.TABLE_NAME like 'IMP%'
minus
select c.TABLE_NAME,c.TABLESPACE_NAME from user_tables c where c.TABLE_NAME like 'WO%'
minus
select d.TABLE_NAME,d.TABLESPACE_NAME from user_tables d where d.TABLE_NAME like 'INSA%'
minus
select e.TABLE_NAME,e.TABLESPACE_NAME from user_tables e where e.TABLE_NAME like 'B%'
minus
select f.TABLE_NAME,f.TABLESPACE_NAME from user_tables f where f.TABLE_NAME like 'TEMP%'
minus
select g.TABLE_NAME,g.TABLESPACE_NAME from user_tables g where g.TABLE_NAME like 'TMP%'
minus
select h.TABLE_NAME,h.TABLESPACE_NAME from user_tables h where regexp_like (h.TABLE_NAME,'[[:digit:]]+$')
minus
select h.TABLE_NAME,h.TABLESPACE_NAME from user_tables h where regexp_like (h.TABLE_NAME,'[_][J]{0,2}$')

---导入对象的数据结构
expdp system/123@orcl dumpfile=inas30_1112.dmp logfile=inas30_1112.log directory=dir schemas=inas30 network_link=dblink73 content=metadata_only version=10.2.0.1.0
impdp inas30_73/inas30_73 dumpfile=inas30_1112.dmp logfile=inas30_1112.log directory=DUMP_INAS30_73 remap_schema=inas30:inas30_73 table_exists_action=replace

----删除不用的数据表
declare
cursor cur_ddl is select e.TABLE_NAME,e.TABLESPACE_NAME from user_tables e where e.TABLE_NAME like 'B%'
union
select f.TABLE_NAME,f.TABLESPACE_NAME from user_tables f where f.TABLE_NAME like 'TEMP%'
union
select g.TABLE_NAME,g.TABLESPACE_NAME from user_tables g where g.TABLE_NAME like 'TMP%';

begin
for cur_d in cur_ddl loop
execute immediate 'drop table '||cur_d.TABLE_NAME||'';
end loop;
end;

---导出导入数据表数据

expdp system/123@orcl dumpfile=inas30_1112_tab1.dmp logfile=inas30_1112_tab1.log directory=dir network_link=dblink73 tables=(inas30.ABI_ABIAPPLY_RULE_DIMENSION,inas30.ABI_ABILITY,inas30.ABI_ABILITYGROUP_APPLY_RULE,inas30.ABI_ABILITY_APPLY_RULE,inas30.ABI_ABILITY_CLASSIFICATION,inas30.ABI_ABILITY_EXEC_ABNORMITY,inas30.ABI_ABILITY_EXEC_ABNO_RULE,inas30.ABI_ABILITY_EXEC_ABNO_SYN_RULE,inas30.ABI_ABILITY_NEBSSERVICE_RELA,inas30.ABI_ABILITY_PARAM_RELA,inas30.ABI_ABILITY_PARAM_RELA_BAK,inas30.ABI_ABILITY_RELA,inas30.ABI_ABILITY_RELA_GROUP,inas30.ABI_ABILITY_RELA_GROUPDEF,inas30.ABI_NEBS_PLATFORM,inas30.ABI_NEBS_PROTOCOL,inas30.ABI_NEBS_SERVICE,inas30.ABI_NEBS_SERVICE_CATALOG,inas30.ABI_NEBS_SERVICE_PLATFORM_MAP,inas30.ABI_PROTOCOL_PARAM,inas30.ABI_WO_INFO_COMPONENTS) version=10.2.0.1.0

将inas30_1112_tab1.dmp文件传输到目标数据库directory目录下

impdp inas30_73/inas30_73 dumpfile=inas30_1112_tab1.dmp logfile=inas30_1112_tab1.log directory=DUMP_INAS30_73 tables=(inas30.ABI_ABIAPPLY_RULE_DIMENSION,inas30.ABI_ABILITY,inas30.ABI_ABILITYGROUP_APPLY_RULE,inas30.ABI_ABILITY_APPLY_RULE,inas30.ABI_ABILITY_CLASSIFICATION,inas30.ABI_ABILITY_EXEC_ABNORMITY,inas30.ABI_ABILITY_EXEC_ABNO_RULE,inas30.ABI_ABILITY_EXEC_ABNO_SYN_RULE,inas30.ABI_ABILITY_NEBSSERVICE_RELA,inas30.ABI_ABILITY_PARAM_RELA,inas30.ABI_ABILITY_PARAM_RELA_BAK,inas30.ABI_ABILITY_RELA,inas30.ABI_ABILITY_RELA_GROUP,inas30.ABI_ABILITY_RELA_GROUPDEF,inas30.ABI_NEBS_PLATFORM,inas30.ABI_NEBS_PROTOCOL,inas30.ABI_NEBS_SERVICE,inas30.ABI_NEBS_SERVICE_CATALOG,inas30.ABI_NEBS_SERVICE_PLATFORM_MAP,inas30.ABI_PROTOCOL_PARAM,inas30.ABI_WO_INFO_COMPONENTS) remap_schema=inas30:inas30_73 table_exists_action=replace
---
expdp system/123@orcl dumpfile=inas30_1112_tab2.dmp logfile=inas30_1112_tab2.log directory=dir network_link=dblink73 tables=(inas30.CHK_COMMAND_EQUALS,inas30.CHK_CWON_AUTOFINISH_FAILURE,inas30.CHK_PARAM_NVALEQU_IGNORE,inas30.CHK_WORKORDER,inas30.INAS_FIX_PARAM,inas30.INAS_FIX_TEMPLATE,inas30.INAS_PROTOCOL_PARAM,inas30.INAS_SC_PARAM,inas30.INAS_SERVICE_COMMAND,inas30.INAS_SERVICE_PLATFORM,inas30.INAS_WO_MACRO,inas30.INAS_WO_MACRO_ANALYSIS,inas30.INAS_WO_MACRO_ANALYSIS_F,inas30.INAS_WO_MACRO_CARD_RES,inas30.INAS_WO_MACRO_KZXKFIX,inas30.INAS_WO_PARAM,inas30.INAS_WO_XPATH,inas30.INS_ACTION,inas30.INS_CRM_EVENT) version=10.2.0.1.0

将inas30_1112_tab2.dmp文件传输到目标数据库directory目录下

impdp inas30_73/inas30_73 dumpfile=inas30_1112_tab2.dmp logfile=inas30_1112_tab2.log directory=DUMP_INAS30_73 tables=(inas30.CHK_COMMAND_EQUALS,inas30.CHK_CWON_AUTOFINISH_FAILURE,inas30.CHK_PARAM_NVALEQU_IGNORE,inas30.CHK_WORKORDER,inas30.INAS_FIX_PARAM,inas30.INAS_FIX_TEMPLATE,inas30.INAS_PROTOCOL_PARAM,inas30.INAS_SC_PARAM,inas30.INAS_SERVICE_COMMAND,inas30.INAS_SERVICE_PLATFORM,inas30.INAS_WO_MACRO,inas30.INAS_WO_MACRO_ANALYSIS,inas30.INAS_WO_MACRO_ANALYSIS_F,inas30.INAS_WO_MACRO_CARD_RES,inas30.INAS_WO_MACRO_KZXKFIX,inas30.INAS_WO_PARAM,inas30.INAS_WO_XPATH,inas30.INS_ACTION,inas30.INS_CRM_EVENT) remap_schema=inas30:inas30_73 table_exists_action=replace
----

expdp system/123@orcl dumpfile=inas30_1112_tab3.dmp logfile=inas30_1112_tab3.log directory=dir network_link=dblink73 tables=(inas30.INS_EVENT,inas30.INS_EVENT_MAP,inas30.INS_OFFERS,inas30.INS_PRODUCT,inas30.INS_PRODUCT_MAP,inas30.INS_PROD_CLASSIFICATION,inas30.INS_PROD_PROPERTY,inas30.INS_PROD_PROP_VALUE,inas30.INS_PROD_PROP_VALUE_REL,inas30.INS_PROD_RESOURCE,inas30.INS_PROD_RES_REL,inas30.INS_PROPERTY_MAP,inas30.INS_SERVICE,inas30.INS_SERVICE_MAP,inas30.INT_INTERFACE,inas30.INT_ITM_RECORD,inas30.LTE_VC_ABILITY_MAP,inas30.SCV_ABI_PRIORITY_BASE,inas30.SCV_WO_PRIORITY_BASE,inas30.SC_ABILITY_ABTY_SOLVE_MODE,inas30.SC_ABILITY_ACTGROUP_RULE,inas30.SC_ABILITY_RELA_STATE,inas30.SC_ABILITY_RELA_TYPE,inas30.SC_ABILITY_TYPE,inas30.SC_BUSI_AREA,inas30.SC_CATALOG,inas30.SC_CWO_NEBSVR_STATE,inas30.SC_DISPATCH_ABNORMITY_STATE,inas30.SC_EXEC_TYPE) version=10.2.0.1.0

将inas30_1112_tab3.dmp文件传输到目标数据库directory目录下

impdp inas30_73/inas30_73 dumpfile=inas30_1112_tab3.dmp logfile=inas30_1112_tab3.log directory=DUMP_INAS30_73 tables=(inas30.INS_EVENT,inas30.INS_EVENT_MAP,inas30.INS_OFFERS,inas30.INS_PRODUCT,inas30.INS_PRODUCT_MAP,inas30.INS_PROD_CLASSIFICATION,inas30.INS_PROD_PROPERTY,inas30.INS_PROD_PROP_VALUE,inas30.INS_PROD_PROP_VALUE_REL,inas30.INS_PROD_RESOURCE,inas30.INS_PROD_RES_REL,inas30.INS_PROPERTY_MAP,inas30.INS_SERVICE,inas30.INS_SERVICE_MAP,inas30.INT_INTERFACE,inas30.INT_ITM_RECORD,inas30.LTE_VC_ABILITY_MAP,inas30.SCV_ABI_PRIORITY_BASE,inas30.SCV_WO_PRIORITY_BASE,inas30.SC_ABILITY_ABTY_SOLVE_MODE,inas30.SC_ABILITY_ACTGROUP_RULE,inas30.SC_ABILITY_RELA_STATE,inas30.SC_ABILITY_RELA_TYPE,inas30.SC_ABILITY_TYPE,inas30.SC_BUSI_AREA,inas30.SC_CATALOG,inas30.SC_CWO_NEBSVR_STATE,inas30.SC_DISPATCH_ABNORMITY_STATE,inas30.SC_EXEC_TYPE) remap_schema=inas30:inas30_73 table_exists_action=replace

-----

expdp system/123@orcl dumpfile=inas30_1112_tab4.dmp logfile=inas30_1112_tab4.log directory=dir network_link=dblink73 tables=(inas30.SC_FOREIGN_WO_INFO,inas30.SC_FOREIGN_WO_STATE,inas30.SC_IWO_BIL_ACT_TYPE,inas30.SC_LOCAL_NETWORK,inas30.SC_PROD_INST_GROUP_TYPE,inas30.SC_PROD_INST_STAT,inas30.SC_PROD_RES_SPECIALTY,inas30.SC_PROD_TYPE,inas30.SC_PROPERTY_DATA_TYPE,inas30.SC_PROPERTY_INPUT_TYPE,inas30.SC_STANDARD_CODE,inas30.SC_STANDARD_TYPE,inas30.SC_THREAD_FINISH_MODE,inas30.SC_THREAD_RUN_STATE,inas30.SC_WOI_COMP_IMPL_PARAM,inas30.SC_WOP_DATA_ORIGIN,inas30.SC_WO_ARCH_STATE,inas30.SC_WO_BUICOMP_STATE,inas30.SC_WO_MAN_ACT_OBJ_TYPE,inas30.SC_WO_MAN_ACT_TPYE,inas30.SC_WO_ORIGIN,inas30.SC_WO_REPLY_STATE,inas30.SC_WO_STATE,inas30.SC_WO_TYPE,inas30.TOS_APP_DOMAIN,inas30.TOS_APP_SERVER,inas30.TOS_AREA,inas30.TOS_BUSINESS_OBJ,inas30.TOS_BUTTON,inas30.TOS_CONFIG,inas30.TOS_CONFIG_CLOB,inas30.TOS_LOG,inas30.TOS_LOG_EXCEPTION,inas30.TOS_LOG_JOB,inas30.TOS_LOG_TYPE,inas30.TOS_MENU,inas30.TOS_MYDESKTOP,inas30.TOS_ORG,inas30.TOS_PRIV,inas30.TOS_PUBLIC_INFO,inas30.TOS_ROLE,inas30.TOS_ROLE_PRIV,inas30.TOS_STAFF,inas30.TOS_STAFF_ONLINE,inas30.TOS_STAFF_PRIV,inas30.TOS_VERSION_INFO) version=10.2.0.1.0

将inas30_1112_tab4.dmp文件传输到目标数据库directory目录下

impdp inas30_73/inas30_73 dumpfile=inas30_1112_tab4.dmp logfile=inas30_1112_tab4.log directory=DUMP_INAS30_73 tables=(inas30.SC_FOREIGN_WO_INFO,inas30.SC_FOREIGN_WO_STATE,inas30.SC_IWO_BIL_ACT_TYPE,inas30.SC_LOCAL_NETWORK,inas30.SC_PROD_INST_GROUP_TYPE,inas30.SC_PROD_INST_STAT,inas30.SC_PROD_RES_SPECIALTY,inas30.SC_PROD_TYPE,inas30.SC_PROPERTY_DATA_TYPE,inas30.SC_PROPERTY_INPUT_TYPE,inas30.SC_STANDARD_CODE,inas30.SC_STANDARD_TYPE,inas30.SC_THREAD_FINISH_MODE,inas30.SC_THREAD_RUN_STATE,inas30.SC_WOI_COMP_IMPL_PARAM,inas30.SC_WOP_DATA_ORIGIN,inas30.SC_WO_ARCH_STATE,inas30.SC_WO_BUICOMP_STATE,inas30.SC_WO_MAN_ACT_OBJ_TYPE,inas30.SC_WO_MAN_ACT_TPYE,inas30.SC_WO_ORIGIN,inas30.SC_WO_REPLY_STATE,inas30.SC_WO_STATE,inas30.SC_WO_TYPE,inas30.TOS_APP_DOMAIN,inas30.TOS_APP_SERVER,inas30.TOS_AREA,inas30.TOS_BUSINESS_OBJ,inas30.TOS_BUTTON,inas30.TOS_CONFIG,inas30.TOS_CONFIG_CLOB,inas30.TOS_LOG,inas30.TOS_LOG_EXCEPTION,inas30.TOS_LOG_JOB,inas30.TOS_LOG_TYPE,inas30.TOS_MENU,inas30.TOS_MYDESKTOP,inas30.TOS_ORG,inas30.TOS_PRIV,inas30.TOS_PUBLIC_INFO,inas30.TOS_ROLE,inas30.TOS_ROLE_PRIV,inas30.TOS_STAFF,inas30.TOS_STAFF_ONLINE,inas30.TOS_STAFF_PRIV,inas30.TOS_VERSION_INFO) remap_schema=inas30:inas30_73 table_exists_action=replace

--查看四个导入导出日志,发现第一个导入日志出错,出错为约束错误,如下:

ORA-39083: 对象类型 REF_CONSTRAINT 创建失败, 出现错误:
ORA-02298: 无法验证 (INAS30_73.FK_NLZSPGZ_R_CP) - 未找到父项关键字
失败的 sql 为:
ALTER TABLE "INAS30_73"."ABI_ABILITYGROUP_APPLY_RULE" ADD CONSTRAINT "FK_NLZSPGZ_R_CP" FOREIGN KEY ("INDEP_PROD_ID") REFERENCES "INAS30_73"."INS_PRODUCT" ("PROD_ID") ENABLE
ORA-39083: 对象类型 REF_CONSTRAINT 创建失败, 出现错误:
ORA-02298: 无法验证 (INAS30_73.FK_NLSYGZ_R_CP_PROD_ID) - 未找到父项关键字
失败的 sql 为:
ALTER TABLE "INAS30_73"."ABI_ABILITY_APPLY_RULE" ADD CONSTRAINT "FK_NLSYGZ_R_CP_PROD_ID" FOREIGN KEY ("DPROD_ID") REFERENCES "INAS30_73"."INS_PRODUCT" ("PROD_ID") ENABLE
处理对象类型 TABLE_EXPORT/TABLE/TRIGGER
处理对象类型 TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
作业 "INAS30_73"."SYS_IMPORT_TABLE_01" 已经完成, 但是有 2 个错误 (于 20:30:20 完成)

将两个失败的sql语句取出:

ALTER TABLE "INAS30_73"."ABI_ABILITYGROUP_APPLY_RULE" ADD CONSTRAINT "FK_NLZSPGZ_R_CP" FOREIGN KEY ("INDEP_PROD_ID") REFERENCES "INAS30_73"."INS_PRODUCT" ("PROD_ID") ENABLE

ALTER TABLE "INAS30_73"."ABI_ABILITY_APPLY_RULE" ADD CONSTRAINT "FK_NLSYGZ_R_CP_PROD_ID" FOREIGN KEY ("DPROD_ID") REFERENCES "INAS30_73"."INS_PRODUCT" ("PROD_ID") ENABLE

在新的目标库当前用户下运行即可

上一篇:thinkphp 官方文件执行引入流程


下一篇:Spring 4 官方文档学习(十一)Web MVC 框架之异常处理