Linux平台下的Oracle自動備份案例(使用RMAN)

來源:互聯網
上載者:User

有個童鞋問rman的自動備份指令碼程式,我之前有寫過exp備份指定方案自動備份案例(Linux平台下的Oracle自動備份案例(使用exp工具)   ),現在補充下rman的案例。
為此寫出下文,僅以記錄並分享這個過程。

環境:
作業系統:RHEL5.4
資料庫:Oracle 10.2.0
相關變數值:
ORACLE_BASE=/u01/app/oracle
ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1
備份的資料庫執行個體名:test
備份的目標目錄:/backup_rman

實現過程如下:
第一步:準備目錄
mkdir /backup_rman
chown oracle:oinstall /backup_rman
chmod 755 /backup_rman

第二步:備份指令碼程式的編寫
1、建立備份指令碼
切換到oracle使用者,在oracle家目錄下面建立bin目錄,建立檔案rman_backup.sh
mkdir bin
cd bin
touch rman_backup.sh
chmod 755 rman_backup.sh
編輯rman_backup.sh檔案,添加如下內容:
#!/bin/bash
source /home/oracle/.bash_profile
/u01/app/oracle/product/10.2.0/db_1/bin/rman target / nocatalog cmdfile=/home/oracle/bin/rman_cmd  log=/backup_rman/rman_full_`date +%Y%m%d%H%M`.log
2、建立rman的備份指令檔
cd ~/bin
touch rman_cmd
編輯rman_cmd檔案添加如下內容(根據需要,可以進行適當的修改):
crosscheck archivelog all;
delete noprompt expired archivelog all;
run {
        configure retention policy to recovery window of 4 days;
        configure controlfile autobackup off;
        allocate channel c1 device type disk  format '/backup_rman/rman_full_%T_%U'  maxpiecesize=3G;
        allocate channel c2 device type disk  format '/backup_rman/rman_full_%T_%U'  maxpiecesize=3G;
        allocate channel c3 device type disk  format '/backup_rman/rman_full_%T_%U'  maxpiecesize=3G;
        backup database plus archivelog delete all input;
        backup current controlfile format '/backup_rman/rman_%T_CTL_%U';
        backup spfile format '/backup_rman/rman_%T_SPFILE_%U';
        release channel c1;
        release channel c2;
        release channel c3;
}
crosscheck backupset;
delete noprompt expired backup;
delete noprompt obsolete;
crosscheck archivelog all;
delete noprompt expired archivelog all;


第三步:添加crontab計劃任務
使用oracle使用者添加例行任務:
crontab -e
新開啟的視窗中添加一下內容:
0 24 * * * /home/oracle/bin/rman_backup.sh
(*/3 * * * * /home/oracle/bin/rman_backup.sh)
注,括弧內的可以是做測試的時候用的,每三分鐘執行一次備份,例為每天淩晨24點執行備份

第四步:執行驗證:
1、crontab成功執行驗證:
在root下執行tail -f /var/log/cron,監控cron日誌來確保crontab的成功執行:
Aug 31 00:20:06 model crontab[6380]: (oracle) BEGIN EDIT (oracle)
Aug 31 00:20:48 model crontab[6380]: (oracle) REPLACE (oracle)
Aug 31 00:20:48 model crontab[6380]: (oracle) END EDIT (oracle)
Aug 31 00:21:01 model crond[26958]: (oracle) RELOAD (cron/oracle)
Aug 31 00:21:01 model crond[6412]: (oracle) CMD (/home/oracle/bin/rman_backup.sh)
Aug 31 00:24:01 model crond[6621]: (oracle) CMD (/home/oracle/bin/rman_backup.sh)

2、查看rman是否執行,並且執行成功
a.可在rman執行的時候執行ps -ef | grep rman | grep -v grep來查看rman進程是否成功啟動
b.查看/backup_rman目錄中是否有備份產生的檔案:
$ oracle@model /backup_rman> ls
rman_20120831_CTL_0mnjvu15_1_1    rman_full_20120831_0injvtrq_1_1
rman_20120831_CTL_0vnjvu57_1_1    rman_full_20120831_0jnjvtvs_1_1
rman_20120831_SPFILE_0nnjvu18_1_1  rman_full_20120831_0knjvu0c_1_1
rman_20120831_SPFILE_10njvu5a_1_1  rman_full_20120831_0lnjvu13_1_1
rman_full_201208310021.log        rman_full_20120831_0onjvu1a_1_1
rman_full_201208310024.log        rman_full_20120831_0pnjvu1e_1_1
rman_full_20120831_0dnjvtrg_1_1    rman_full_20120831_0qnjvu1e_1_1
rman_full_20120831_0enjvtrg_1_1    rman_full_20120831_0rnjvu1i_1_1
rman_full_20120831_0fnjvtrg_1_1    rman_full_20120831_0snjvu4s_1_1
rman_full_20120831_0gnjvtrp_1_1    rman_full_20120831_0tnjvu52_1_1
rman_full_20120831_0hnjvtrp_1_1    rman_full_20120831_0unjvu55_1_1

驗證結果:rman自動備份任務執行成功!

推薦閱讀:

Oracle基礎教程之通過RMAN複製資料庫

RMAN備份策略制定參考內容

RMAN備份學習筆記

OracleDatabase Backup加密 RMAN加密

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.