天天看點

oracle10g的EXPDP與IMPDP的導出與導入測試

實驗環境:

伺服器A:172.21.1.30 伺服器B:172.21.1.40 兩台伺服器上分别運作兩套oracle資料庫,本實驗以scott使用者為例進行測試。

實驗目的:

通過DB_LINK的複制功能,利用expdp,impdp進行資料的遠端備份及恢複。 進行測試前,将伺服器B上scott使用者的dept,emp進行删除,本測試隻是使用 impdp将伺服器A資料庫下scott使用者的dept,emp表導入到伺服器B資料庫 scott使用者下。

操作步驟:

1.在伺服器A,B上分别以sys身份登入資料庫,并建立directory,db_link,指令如下: session A: > create directory dp01 as '/bk/dp01'; Directory created. session A: >create public database link ln_db40 connect to scott identified by tiger using 'ip40'; Database link created. session A: >grant connect,resource,exp_full_database,imp_full_database to scott identified by tiger; Grant succeeded. session B: > create directory dp02 as '/bk/dp02'; session B: >create public database link ln_db30 connect to scott identified by tiger using 'ip30'; session B: >grant connect,resource,exp_full_database,imp_full_database to scott identified by tiger; 2.在确認以上步驟中的db_link沒問題後,做以下操作: a. 伺服器A:(将本地資料庫中scott使用者下的dept,emp兩張表導出備份檔案為exp01.dmp)
[oracle@session A: dp01]$ expdp scott/tiger directory=dp01 dumpfile=exp01.dmp network_link=ln_db30 tables=emp,dept Export: Release 10.2.0.1.0 - Production on Wednesday, 03 August, 2011 14:39:05 Copyright (c) 2003, 2005, Oracle. All rights reserved. Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production  With the Partitioning, OLAP and Data Mining options  Starting "SCOTT"."SYS_EXPORT_SCHEMA_01": scott/********@ip30 directory=dp01 dumpfile=exp01.dmp network_link=ln_db30 tables=emp,dept  Estimate in progress using BLOCKS method...  Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA  Total estimation using BLOCKS method: 320 KB  Processing object type SCHEMA_EXPORT/USER  Processing object type SCHEMA_EXPORT/SYSTEM_GRANT  Processing object type SCHEMA_EXPORT/ROLE_GRANT  Processing object type SCHEMA_EXPORT/DEFAULT_ROLE  Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA  Processing object type SCHEMA_EXPORT/TABLE/TABLE  Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX  Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT  Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS  Processing object type SCHEMA_EXPORT/TABLE/COMMENT  Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT  . . exported "SCOTT"."SYS_EXPORT_SCHEMA_01" 172.8 KB 1073 rows  . . exported "SCOTT"."DEPT" 5.656 KB 4 rows  . . exported "SCOTT"."EMP" 7.820 KB 14 rows  Master table "SCOTT"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded  ******************************************************************************  Dump file set for SCOTT.SYS_EXPORT_SCHEMA_01 is:  /bk/dp01/exp01.dmp  Job "SCOTT"."SYS_EXPORT_SCHEMA_01" successfully completed at 14:39:37 [oracle@session A: dp01]$ ls exp01.dmp export.log import.log b. 将備份檔案exp01.dmp從伺服器A拷貝到伺服器B: [oracle@session A: dp01]$ scp –r exp01.dmp 172.21.1.40:/bk/dp02/ c.在伺服器A上,執行以下指令,将dept,emp表導入到伺服器B的scott使用者下: [oracle@session A: dp01]$ impdp scott/tiger@ip40 directory=dp02 dumpfile=exp01.dmp tables=emp,dept Import: Release 10.2.0.1.0 - Production on Wednesday, 03 August, 2011 14:34:57 Master table "SCOTT"."SYS_IMPORT_TABLE_01" successfully loaded/unloaded  Starting "SCOTT"."SYS_IMPORT_TABLE_01": scott/********@ip40 directory=dp02 dumpfile=exp01.dmp tables=emp,dept  Processing object type TABLE_EXPORT/TABLE/TABLE  Processing object type TABLE_EXPORT/TABLE/TABLE_DATA  . . imported "SCOTT"."DEPT" 5.656 KB 4 rows  . . imported "SCOTT"."EMP" 7.820 KB 14 rows  Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX  Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT  Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT  Job "SCOTT"."SYS_IMPORT_TABLE_01" successfully completed at 14:34:55
3.使用sys使用者登入伺服器A的資料庫,進行測試,檢視B的scott使用者下的dept,emp表是否存在: $ sqlplus / as sysdba session A: > conn scott/tiger Connected. session A: > select * from tab; TNAME TABTYPE CLUSTERID  ------------------------------ ------- ----------  DEPT TABLE  EMP TABLE session A: > select * from tab@ln_db40;

由以上實驗不難看出,表dept,emp已成功導入B的scott使用者。

EXPDP 可以導出所有資料庫的資料,隻要它能連接配接到這個資料庫,或者它登入的資料庫 

上能讀取到被導出的庫的資料,因為此時可以通過資料庫鍊來讀取被導出的庫的資料。

如下測試:

可以分為三個伺服器:A,B,C,以下指令在A在執行:

說明:

expdp 在伺服器A上;

network_link=ln_db30 是伺服器B的資料庫中scott使用者的資料庫鍊,其指向伺服器C的使用者scott, 

SCOTT10使用者中隻有兩個表dept,emp.

從上面的操作可以看出:expdp 可以是用戶端的程式,但它導出的資料(DMP)必須存放在它登入

的資料庫的目錄下(本例中,存放在機器B的資料庫directory=dp02下),而被導出的資料是通過

資料庫鍊(network_link)到機器C的資料庫裡讀取的。

另外注意:在這過程中,A資料庫使用者scott和C資料庫使用者scott(或者資料庫鍊中的使用者)都必須被

授予EXP_FULL_DATABASE 權限。

nelwork_link意思是從本地資料庫導入datafile直接到remote database,中間省略了exp的操作,

nelwork_link=source_database_link,确認nelwork_link參數是一個存在的目标資料庫名稱,同時

存在database link.

補充一下兩個限制條件:

<b>nelwork_link parameter Restrictions</b>

Network imports do not support the use of evolved types. 

<b>a:</b> When the NETWORK_LINK parameter is used in conjunction with the TABLES parameter,

only whole tables can be imported (not partitions of tables).

是以,當使用impdp導入時多張表時,如果添加network_link參數,就會報錯如下:

UDI-00011: parameter dumpfile is incompatible with parameter network_link

<b>b:</b> If the USERID that is executing the import job has the IMP_FULL_DATABASE role on the

target database, then that user must also have the EXP_FULL_DATABASE role on the source

database.The only types of database links supported by Data Pump Import are: public,

fixed-user, and connected-user. Current-user database links are not supported.

    本文轉自vcdog 51CTO部落格,原文連結:http://blog.51cto.com/255361/837646,如需轉載請自行聯系原作者

上一篇: gluster