首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 數據庫知識 >  >> Oracle 資料庫 >> Oracle 資料庫基礎

Oracle 邏輯備份與恢復完整指南:exp/imp 參數詳解與實戰範例

     編輯:Oracle 資料庫基礎

邏輯備份(Logical Backup)使用 exp 將物件結構與資料導出為 .dmp 檔案,恢復時用 imp 導入。適用於資料庫開啟狀態、跨版本/平台遷移、單一物件備份等場景。本文系統整理 exp/imp 三種模式(表、方案、完整資料庫)的常用參數與實戰指令。

一、導出 - exp 常用參數

參數說明
userid執行導出的帳號/密碼[@連線字串]
tables指定導出的表(支援多表、跨方案)
owner指定導出的方案(Schema)
full=y導出整個資料庫(需 DBA/EXP_FULL_DATABASE 權限)
inctype增量備份類型:COMPLETE / INCREMENTAL / CUMULATIVE
rows=y|n是否導出資料列(n 僅導結構)
file導出檔案路徑與檔名
direct=y直接路徑導出(Direct Path),大量資料時較快,但要求字符集一致

導出模式實戰範例

1. 導出表

-- 導出自己的表
exp userid=scott/tiger@orcl tables=(emp,dept) file=d:\e1.dmp

-- 導出其他方案的表(需 DBA 權限)
exp userid=system/manager@orcl tables=(scott.emp) file=d:\e2.dmp

-- 僅導出表結構
exp userid=scott/tiger@orcl tables=(emp) file=d:\e3.dmp rows=n

-- 直接路徑導出(大量資料加速)
exp userid=scott/tiger@orcl tables=(emp) file=d:\e4.dmp direct=y

2. 導出方案(Schema)

-- 導出自己的方案
exp userid=scott/tiger@orcl owner=scott file=d:\scott.dmp

-- 導出多個方案
exp userid=system/manager@orcl owner=(system,scott) file=d:\system.dmp

3. 導出完整資料庫與增量備份

-- 完全增量導出(基準備份)
exp userid=system/manager@orcl full=y inctype=complete file=d:\all.dmp

-- 增量導出(僅備份上次備份後變更)
exp userid=system/manager@orcl full=y inctype=incremental file=d:\inc.dmp

-- 累積導出(備份上次完全導出後所有變更)
exp userid=system/manager@orcl full=y inctype=cumulative file=d:\cum.dmp

二、導入 - imp 常用參數

參數說明
userid執行導入的帳號/密碼[@連線字串]
tables指定導入的表
fromuser來源方案(導出時的擁有者)
touser目標方案(導入後的擁有者)
file導入檔案路徑
full=y導入整個導出檔案內容
inctype增量導入類型(RESTORE)
rows=y|n是否導入資料列
ignore=y物件已存在時忽略錯誤,僅導入資料

導入模式實戰範例

1. 導入表

-- 導入自己的表
imp userid=scott/tiger@orcl tables=(emp) file=d:\xx.dmp

-- 導入表到其他使用者(需 DBA/IMP_FULL_DATABASE)
imp userid=system/pwd@orcl tables=(emp) file=d:\xx.dmp touser=scott

-- 僅導入結構
imp userid=scott/tiger@orcl tables=(emp) file=d:\xx.dmp rows=n

-- 物件存在時僅導入資料
imp userid=scott/tiger@orcl tables=(emp) file=d:\xx.dmp ignore=y

2. 導入方案

-- 導入自己的方案
imp userid=scott/tiger file=d:\xxx.dmp

-- 導入其他方案(跨 Schema)
imp userid=system/pwd file=d:\xxx.dmp fromuser=導出用戶 touser=導入用戶 ignore=y
注意:若 fromuser 指定的用戶在目標資料庫不存在,需先建立該用戶與表空間,否則導入會失敗。

3. 導入完整資料庫

imp userid=system/pwd full=y file=d:\xxx.dmp

增量備份/恢復實戰流程

假設備份排程:週一完全(A)、週二~四增量(B/C/D)、週五累積(E)、週六~日增量(F/G)。週日災難發生時恢復步驟:

  1. CREATE DATABASE 重建資料庫結構
  2. 建立足夠大的 Rollback Segment
  3. 完全導入 A:imp system/pwd inctype=RESTORE full=y file=A
  4. 累積導入 E:imp system/pwd inctype=RESTORE full=y file=E
  5. 最近增量導入 F:imp system/pwd inctype=RESTORE full=y file=F

操作提醒

  • 執行 exp/imp 時需在 $ORACLE_HOME/bin 目錄下,或已將該路徑加入 PATH。
  • 字符集不一致時,direct=y 會報錯;一般模式會自動轉換但可能影響效能。
  • 大型資料庫建議搭配 PARFILE 參數檔管理冗長參數,避免命令列過長。
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved