Linux ORCLE資料庫增量備份指令碼

來源:互聯網
上載者:User

ORCLEDatabase Backup策略
1.通過使用exp和imp命令實現資料庫匯出和匯入。
有三種模式:
a. 使用者模式: 匯出(匯入)使用者所有對象以及對象中的資料;
b. 表模式: 匯出(匯入)使用者所有表或者指定的表;
c. 整個資料庫: 匯出(匯入)資料庫中所有對象。
如:
普通匯出
a.匯出一個完整資料庫
exp system/manager file=f.dmp full=y
b.匯出資料庫定義而不匯出資料
exp system/manager file=f.dmp full=y rows=n
普通匯入:
a.完全匯入
imp system/manager file=f.dmp full=y
b.資料庫結構存在時,只匯入資料
imp system/manager file=f.dmp full=y ignore=y
2.每周進行Database Backup,以防資料庫被意外破壞後恢複資料
安排如下:
周一: 完全備份(f1) exp xxx/xxx inctype=complete file=f1.dmp
周二: 增量備份(f2) exp xxx/xxx inctype=incremental file=f2.dmp
周三: 增量備份(f3) exp xxx/xxx inctype=incremental file=f3.dmp
周四: 增量備份(f4) exp xxx/xxx inctype=incremental file=f4.dmp
周五: 累積備份(f5) exp xxx/xxx inctype=cumulative file=f5.dmp
周六: 增量備份(f6) exp xxx/xxx inctype=incremental file=f6.dmp
周日: 增量備份(f7) exp xxx/xxx inctype=incremental file=f7.dmp
比如資料庫在周日被破壞,則可用以下方式恢複:
1.建立空的資料庫,同之前的結構。
2.imp xxx/xxx inctype=RESTORE FULL=y FILE=f1.dmp
3.imp xxx/xxx inctype=RESTORE FULL=y FILE=f5.dmp
4.imp xxx/xxx inctype=RESTORE FULL=y FILE=f6.dmp
說明:
完全匯出:對整個資料庫的備份
增量匯出:是備份上一次完全匯出後改變的資料。
累積匯出:是備份自上次完全匯出後改變的資料。
EXAMPLE:LINUX下備份資料庫
BACKUP_DIR=/home/oracle/backups
if [ ! -d $BACKUP_DIR ]; then
mkdir -p $BACKUP_DIR
fi
DAYS=(Sun Mon Tue Wed Thu Fri Sat) #建立數組
TYPES=(incremental complete incremental incremental incremental cumulative incremental)
day=`date +%w` #取得本周天數,0代表周日,1代表周一
DAY_NAME=${DAYS[$day]} #取得數組的值
TYPE=${TYPES[$day]}
DATE_NAME=`date +%F`
FILE_NAME=${DATE_NAME}-${DAY_NAME}-${TYPE}.dmp #2008-12-8-Mon-complete.dmp
exp xxx/xxx inctype=$TYPE file=${BACKUP_DIR}/${FILE_NAME} > /dev/null
gzip ${BACKUP_DIR}/${FILE_NAME}
find $BACKUP_DIR -mtime +7 -delete #刪除七天前更改過的檔案
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.