利用 Oracle exp 工具實現三級備份策略,配合 crontab 自動化執行:
exp_comp.sh#!/bin/sh
rq=`date +"%m%d"`
su - oracle -c "exp system/manager full=y inctype=complete file=/oracle/export/db_comp${rq}.dmp"
exp_incr.sh#!/bin/sh
rq=`date +"%m%d"`
su - oracle -c "exp system/manager full=y inctype=incremental file=/oracle/export/db_incr${rq}.dmp"
exp_cumu.sh#!/bin/sh
rq=`date +"%m%d"`
su - oracle -c "exp system/manager full=y inctype=cumulative file=/oracle/export/db_cumu${rq}.dmp"
| 參數 | 說明 |
|---|---|
full=y | 完全導出模式,包含所有用戶對象 |
inctype | 備份類型:complete(完全)、cumulative(累積)、incremental(增量) |
file | 導出檔路徑,含日期後綴避免覆蓋 |
su - oracle -c | 切換到 oracle 用戶執行,確保環境變數正確 |
編輯 /var/spool/cron/crontabs/root 加入:
0 2 1 * * /oracle/exp_comp.sh # 每月1日 02:00 完全備份
30 2 * * 0-5 /oracle/exp_incr.sh # 週一至六 02:30 增量備份
45 2 * * 6 /oracle/exp_cumu.sh # 週日 02:45 累積備份
提示:時間表可根據業務恢復時間目標(RTO)與恢復點目標(RPO)調整。
/oracle/export 需預留足夠磁碟空間,建議掛載獨立磁碟陣列exp system/manager file=xxx.dmp show=y這套 Shell 腳本結合 exp 的三種導出模式與 crontab,構建了低成本、可維護的邏輯備份體系。實際部署時請根據數據量級調整頻率與保留策略,並納入災難恢復演練計畫。