oracle 數據庫備份還原 EXPDP IMPDP

一、expdp/impdp和exp/imp的區別
1、exp和imp是客戶端工具程序,它們既可以在客戶端使用,也可以在服務端使用。
2、expdp和impdp是服務端的工具程序,他們只能在oracle服務端使用,不能在客戶端使用。
3、imp只適用於exp導出的文件,不適用於expdp導出文件;impdp只適用於expdp導出的文件,而不適用於exp導出文件。
4、對於10g以上的服務器,使用exp通常不能導出0行數據的空表,而此時必須使用expdp導出。

二、expdp導出步驟
(1)創建邏輯目錄:
   第一步:在服務器上創建真實的目錄;(注意:第三步創建邏輯目錄的命令不會在OS上創建真正的目錄,所以要先在服務器上創建真實的目錄。如下圖:)
oracle 數據庫備份還原 EXPDP IMPDP
  第二步:用sys管理員登錄sqlplus;
oracle 數據庫備份還原 EXPDP IMPDP
  第三步:創建邏輯目錄;
SQL> create directory data_dir as '/home/oracle/dmp/user';
Directory created.
  第四步:查看管理員目錄,檢查是否存在;
SQL> select * from dba_directories;
OWNER DIRECTORY_NAME


DIRECTORY_PATH


SYS DATA_DIR
/home/oracle/dmp/user
  第五步:用sys管理員給你的指定用戶賦予在該目錄的操作權限。
SQL> grant read,write on directory data_dir to user;
Grant succeeded.
(2)用expdp導出dmp,有五種導出方式:
第一種:“full=y”,全量導出數據庫;
expdp user/passwd@orcl dumpfile=expdp.dmp directory=data_dir full=y logfile=expdp.log;
第二種:schemas按用戶導出;
expdp user/passwd@orcl schemas=user dumpfile=expdp.dmp directory=data_dir logfile=expdp.log;
第三種:按表空間導出;
expdp sys/passwd@orcl tablespace=tbs1,tbs2 dumpfile=expdp.dmp directory=data_dir logfile=expdp.log;
第四種:導出表;
expdp user/passwd@orcl tables=table1,table2 dumpfile=expdp.dmp directory=data_dir logfile=expdp.log;
第五種:按查詢條件導;
expdp user/passwd@orcl tables=table1='where number=1234' dumpfile=expdp.dmp directory=data_dir logfile=expdp.log;

三、impdp導入步驟
(1)如果不是同一臺服務器,需要先將上面的dmp文件下載到目標服務器上,具體命令參照:http://www.cnblogs.com/promise-x/p/7452972.html
(2)參照“expdp導出步驟”裏的前三步,建立邏輯目錄;
(3)用impdp命令導入,對應五種方式:
第一種:“full=y”,全量導入數據庫;
impdp user/passwd directory=data_dir dumpfile=expdp.dmp full=y;
第二種:同名用戶導入,從用戶A導入到用戶A;
impdp A/passwd schemas=A directory=data_dir dumpfile=expdp.dmp logfile=impdp.log;
第三種:①從A用戶中把表table1和table2導入到B用戶中;
impdp B/passwdtables=A.table1,A.table2 remap_schema=A:B directory=data_dir dumpfile=expdp.dmp logfile=impdp.log;
    ②將表空間TBS01、TBS02、TBS03導入到表空間A_TBS,將用戶B的數據導入到A,並生成新的oid防止衝突;

impdp A/passwd remap_tablespace=TBS01:A_TBS,TBS02:A_TBS,TBS03:A_TBS remap_schema=B:A FULL=Y transform=oid:n
directory=data_dir dumpfile=expdp.dmp logfile=impdp.log
第四種:導入表空間;
impdp sys/passwd tablespaces=tbs1 directory=data_dir dumpfile=expdp.dmp logfile=impdp.log;
第五種:追加數據;
impdp sys/passwd directory=data_dir dumpfile=expdp.dmp schemas=system table_exists_action=replace logfile=impdp.log;
--table_exists_action:導入對象已存在時執行的操作。有效關鍵字:SKIP,APPEND,REPLACE和TRUNCATE

原文:https://www.cnblogs.com/promise-x/p/7477360.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章