exp.exe/imp.exe 位於 $ORACLE_HOME/bin,為 Oracle 官方邏輯備份工具。exp 將資料庫物件與資料序列化為二進位 .dmp 檔;imp 讀取 .dmp 重建物件並載入資料。支援三種模式:
EXP_FULL_DATABASE/IMP_FULL_DATABASE 角色)$ exp scott/tiger@ORCL
Enter array fetch buffer size: 4096 > [Enter]
Export file: expdat.dmp > scott_backup.dmp
(1)E(ntire database), (2)U(sers), or (3)T(ables): (2)U > 3
Export table data (yes/no): yes > [Enter]
Compress extents (yes/no): yes > [Enter]
Table(T) or Partition(T:P) to be exported: (RETURN to quit) > emp
. . exporting table EMP 14 rows exported
Table(T) or Partition(T:P) to be exported: (RETURN to quit) > dept
. . exporting table DEPT 4 rows exported
Table(T) or Partition(T:P) to be exported: (RETURN to quit) > [Enter]
Export terminated successfully without warnings.
$ imp scott/tiger@ORCL
Import file: expdat.dmp > scott_backup.dmp
Import table data (yes/no): yes > [Enter]
Ignore create errors (yes/no): no > yes
Import grants (yes/no): yes > [Enter]
Import full export file (yes/no): no > yes
. . importing table EMP 14 rows imported
. . importing table DEPT 4 rows imported
Import terminated successfully with warnings.
# 1. 全庫導出
exp system/manager@ORCL file=/backup/full.dmp full=y log=/backup/full.log
# 2. 多 Schema 導出
exp system/manager@ORCL file=/backup/multi.dmp owner=(scott,hr,oe) log=/backup/multi.log
# 3. 指定表導出
exp scott/tiger@ORCL file=/backup/tables.dmp tables=(emp,dept,bonus) log=/backup/tables.log
# 4. 條件導出(WHERE 子句)
exp system/manager@ORCL file=/backup/emp_recent.dmp \
tables=(emp) query="WHERE hiredate > SYSDATE-30" log=/backup/emp_recent.log
# 1. 全庫導入(忽略物件存在錯誤)
imp system/manager@ORCL file=/backup/full.dmp full=y ignore=y log=/backup/imp_full.log
# 2. 指定表導入
imp scott/tiger@ORCL file=/backup/tables.dmp tables=(emp,dept) log=/backup/imp_tables.log
# 3. 換 Schema 導入(需參數檔)
# import.par 內容見上文 96015
ora_full_backup.bat@echo off
set ORACLE_SID=ORCL
set BACKUP_DIR=D:\oracle_backup
set DATE_STR=%date:~-4,4%%date:~-10,2%%date:~-7,2%
exp system/manager@ORCL file=%BACKUP_DIR%\full_%DATE_STR%.dmp full=y log=%BACKUP_DIR%\full_%DATE_STR%.log
rem 可選:壓縮
"C:\Program Files\7-Zip\7z.exe" a -tzip %BACKUP_DIR%\full_%DATE_STR%.zip %BACKUP_DIR%\full_%DATE_STR%.dmp
del %BACKUP_DIR%\full_%DATE_STR%.dmp
Oracle_Full_Backup → 觸發:每日 02:00cmd.exe → 參數:/c D:\scripts\ora_full_backup.bat.dmp/.zip 至備援資料中心/雲端儲存。imp 進行自動還原,資料覆蓋風險極高,人工確認不可省略。