1. 程式人生 > >oracle 遠端匯入匯出dmp檔案

oracle 遠端匯入匯出dmp檔案

--進入sqlplus,先建立一個目錄用來dump資料庫
create directory dump_test as 'F:\xuyi\dump'  ;

--檢視一下是否存在該目錄
select * from dba_directories;

--授權給操作使用者這個dump目錄的許可權
grant read, write on directory dump_test to xuyi;

--PS:下面是在命令列執行而不是在sqlplus,而且注意如果版本不一致請註明對方版本,如不註明schemas的話則預設匯出登陸使用者的資料

--匯出:不能帶分號結尾(Linux中需要切換到Oracle使用者才能執行:su - oracle)
expdp xuyi/
[email protected]
schemas=db_user directory=dump_test dumpfile=data.dmp version=11.1.0.6.0 --匯入:不能帶分號結尾 impdp xuyi/[email protected] directory=dump_test dumpfile=data.dmp --想遠端匯入請使用NETWORK_LINK引數指定DB LINK,關於如何設定請參照如下文件: --http://wenku.baidu.com/view/b67bfa06e87101f69e31953a.html --xuyi是遠端服務名 create database link link5 connect to scott identified by tiger using 'xuyi'; --檢視是否生效 select * from
[email protected]
; --xuyi/password為本地賬號密碼,而link5中包含遠端伺服器賬號密碼 expdp xuyi/password network_link=link5 schemas=scott directory=dump_test dumpfile=data.dmp

PS:如果expdp需要從高版本匯出到低版本 必須在高版本上加上version=低版本號 這樣低版本才能識別高版本的dmp檔案

也有可能許可權會有問題,如下:

在利用NETWORK_LINK方式匯出的時候,出現了這個錯誤。
詳細錯誤資訊如下:
bash-3.00$ expdp yangtk/yangtk directory=d_temp dumpfile=jiangsu.dp network_link=test113 logfile=jiangsu.log tables=cat_org
Export: Release11.1.0.6.0 - 64bit Production on星期二, 16 9月, 2008 17:08:22
Copyright (c) 2003, 2007, Oracle.  All rights reserved.
連線到: Oracle Database11gEnterprise Edition Release11.1.0.6.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
ORA-31631:需要許可權
ORA-39149:無法將授權使用者連結到非授權使用者
檢查Oracle的錯誤手冊:
ORA-39149: cannot link privileged user to non-privileged user
Cause: A Data Pump job initiated be a user with EXPORT_FULL_DATABASE/IMPORT_FULL_DATABASE roles specified a network link that did not correspond to a user with equivalent roles on the remote database.
Action: Specify a network link that maps users to identically privileged users in the remote database.
錯誤描述的比較清楚,不過這個錯誤很難理解,難道一個許可權大的使用者不能通過資料庫鏈匯出一個許可權小的使用者。
當然,瞭解了這個錯誤的原因,其實問題很容易解決。在本地建立一個新使用者,不要授權EXP_FULL_DATABASE/IMP_FULL_DATABASE角色,就可以匯出:
bash-3.00$ sqlplus "/ as sysdba"
SQL*Plus: Release11.1.0.6.0 - Production on星期二9月16 16:53:48 2008
Copyright (c) 1982, 2007, Oracle.  All rights reserved.

連線到:
Oracle Database11gEnterprise Edition Release11.1.0.6.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> col grantee format a15
SQL> col granted_role format a15
SQL> select grantee, granted_role from dba_role_privs
  2  where grantee = 'YANGTK';
GRANTEE         GRANTED_ROLE
--------------- ---------------
YANGTK          CONNECT
YANGTK          RESOURCE
YANGTK          DBA
SQL> drop user test cascade;
使用者已刪除。
SQL> create user test identified by test
  2  default tablespace users
  3  quota unlimited on users;
使用者已建立。
SQL> grant connect to test;
授權成功。
SQL> grant create table, create database link to test;
授權成功。
SQL> grant read, write on directory d_temp to test;
授權成功。
SQL> conn test/test
已連線。
SQL> create database link test113 connect tojiangsuidentified byjiangsu
  2  using '172.0.2.113/test';
資料庫連結已建立。
SQL> select * from 
[email protected]
; GLOBAL_NAME -------------------------------------------------------------------------------- TEST SQL> exit