利用 exp 工具搭配 inctype 參數,可實現完全、累積、增量三級備份,再配合 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_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"
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"
# 每月 1 號 02:00 完全備份
0 2 1 * * /oracle/exp_comp.sh
# 週一至週六 02:30 增量備份
30 2 * * 1-6 /oracle/exp_incr.sh
# 週日 02:45 累積備份
45 2 * * 0 /oracle/exp_cumu.sh
inctype=complete:建立基準點,後續累積/增量以此為基準inctype=cumulative:備份自上次完全備份以來所有變更inctype=incremental:僅備份上次任意備份 (完全/累積/增量) 以來的變更rq 格式可依需求調整 (如 %Y%m%d 含年份)expdp (Data Pump) 取代舊版 exp,效能與平行度較佳# 還原順序:完全備份 → 最新累積備份 → 其後所有增量備份
imp system/manager file=db_comp0101.dmp full=y
imp system/manager file=db_cumu0107.dmp full=y
imp system/manager file=db_incr0108.dmp full=y
...
imp system/manager file=db_incr0110.dmp full=y
建立標準化備份腳本與排程,是資料庫可用性的基石。