使用 ExpDP 和 ImpDP 来转移数据

 

今天遇到一个需求,把一个Schema下的对象(Table, Sequence, Package, etc)分别转移到其他两个Schema下。如果用普通的Exp/Imp,需要在tables参数里面写很多东西。并且 wait4friend 还不确定能否对sequence等对象进行排除。所以决定使用10g之后提供的数据泵来处理。

 

背景是这样的,原始用户是Test,分别导入

1. TestDP_0,全量导入

2. TestDP_1,部分对象导入

 

准备工作

首先建立各种对象,其中比较重要的是Oracle目录对象。数据泵只能把数据存放在目录对象指定的位置。

PS: DB Link不是必须的,这里是为了测试本机数据不落地直接导入导出。

-----------------------------------------------------------------------------------
-------- 建立数据泵需要使用的目录对象
drop directory pump;
create directory pump as '/home/oracle/pump';

select * from dba_directories;

-----------------------------------------------------------------------------------
-------- 建立连接到自己的db link
-- as sysdba
drop public database link link_self;
create public database link link_self connect to system identified by *** using 'xxxx'; 

-----------------------------------------------------------------------------------
--------- 建立需要导入的用户
-- dest 0 and src 2
drop user testdp_0 cascade;
create user testdp_0 identified by test default tablespace hfzc;
grant resource, connect to testdp_0;

-- dest 1
drop user testdp_1 cascade;
create user testdp_1 identified by test default tablespace hfzc;
grant resource, connect to testdp_1;

-- dest 2
drop user testdp_2 cascade;
create user testdp_2 identified by test default tablespace hfzc;
grant resource, connect to testdp_2;

 

Step 1

全量导出用户下的所有对象,参数文件如下

userid=system/***
directory=pump                       -- Oracle目录对象 
parallel=2
schemas=test
dumpfile=test201.dmp
logfile=test201.log

 

Step 2

把所有对象和数据导入到新建立的TestDP_0用户中

userid=system/***
directory=pump
parallel=2
schemas=test
remap_schema=test:testdp_0     -- 重新映射用户
dumpfile=test201.dmp
logfile=testdp_0_imp_full.log
transform=OID:N                      -- 避免在同一个库导入object时发生OID重复的错误

 

Step 3

把指定的对象导入到TestDP_1用户下,使用了include参数

userid=system/***
directory=pump
parallel=2
schemas=test
remap_schema=test:testdp_1
dumpfile=test201.dmp
logfile=testdp_1_imp_part.log
transform=OID:N
include=table:"in ('EP_BILL','EP_CUSTOMER')",sequence:"in ('BILL_ID') ",package:"in ('EP_PKG')"  -- 只导入指定的对象

 

Step 4

通过exclude参数排除掉一部分对象,把其他的全部导入TestDP_2用户下,并且通过DB Link操作。注意这里没有使用刚才导出的dump文件。

userid=system/***
directory=pump
parallel=2
schemas=test
remap_schema=test:testdp_2
network_link=link_self              -- 不使用DUMP文件,而直接使用数据库链接
logfile=testdp_2_imp_dblink.log
transform=OID:N
exclude=table:"in ('EP_BILL','EP_CUSTOMER')",sequence:"in ('BILL_ID') ",package:"in ('EP_PKG')"  --  排除对象

 

执行ExpDP,ImpDP

因为把参数都写在了参数文件中,所以调用过程非常简单,仅仅是使用不同的参数文件名称填充parfile

[oracle@TESTDB pump]$ expdp parfile=test.par

posted on 2012-09-26 17:38  wait4friend  阅读(458)  评论(0编辑  收藏  举报