RMAN詳細教程(四):備份腳本實戰操做

RMAN詳細教程(一):基本命令代碼 RMAN詳細教程(二):備份、檢查、維護、恢復 RMAN詳細教程(三):備份腳本的組件和註釋 RMAN詳細教程(四):備份腳本實戰操做   html

一、爲了安全起見,先將數據庫徹底導出:

exp 用戶名/密碼@ORACLE file=/backup/ecology_$(date '+%Y%m%d').dmp full=y;  數據庫

二、由於是數據庫操做,因此應切換成Oracle用戶:

su - oracle  安全

三、檢查數據庫是否打開歸檔模式,如否,則打開SQLPLUS執行如下命令:

archive log list;
alter system set log_archive_dest_n='location=/u01/backupws ';
shutdown immediate;
startup mount;
alter database archivelog;
alter database open;

 

四、將rman腳本文件放置到backup_sh目錄下:

(1)全庫備份(一週三次) rman_ecology_all.shoracle

run {
    allocate channel a1 device type disk format '/backup/ecology_all_%T_%u';
    allocate channel a2 device type disk format '/backup/ecology_all_%T_%u';
    backup database skip offline plus archivelog delete all input;
    backup current controlfile;
    release channel a1;
    release channel a2;
}
    allocate channel for maintenance device type disk;
    delete obsolete;
    crosscheck backupset;

  (2)歸檔日誌備份(一週四次) rman_ecology_arc.shapp

run {
    allocate channel b1 device type disk format '/backup/ecology_arc_%T_%u';
    allocate channel b2 device type disk format '/backup/ecology_arc_%T_%u';
    backup archivelog all;
    backup current controlfile;
    release channel b1;
    release channel b2;
}
    allocate channel for maintenance device type disk;
    crosscheck backupset;

 

五、編寫RMAN腳本的運行腳本:

mkdir -p /backup/ # 建立目錄(-p表示不存在則新建,若存在則忽略) touch run_rman_ecology_all.sh # 建立all運行腳本 touch run_rman_ecology_arc.sh # 建立arc運行腳本測試

vi run_rman_ecology_all.sh

export ORACLE_HOME=/u01/app/oracle/product/10.2/db_1
export ORACLE_SID=ecology
/u01/app/oracle/product/10.2/db_1/bin/rman target / log=/backup/all_ecology_$(date +%F).log cmdfile=/backup_sh/rman_ecology_all.sh
vi run_rman_ecology_arc.sh

export ORACLE_HOME=/u01/app/oracle/product/10.2/db_1
export ORACLE_SID=ecology
/u01/app/oracle/product/10.2/db_1/bin/rman target / log=/backup/arc_ecology_$(date +%F).log cmdfile=/backup_sh/rman_ecology_arc.sh

 

六、添加執行權限:

chmod +x /backup_sh/run_rman_ecology_all.sh chmod +x /backup_sh/run_rman_ecology_arc.sh PS: <font color='red'>需使用root用戶。</font>  spa

七、手動測試腳本,成功以後再下一步。

若報錯,則直接打開/var/spool/mail/登錄用戶名,查看日誌並改正。  rest

八、添加定時任務:

週三五七晚20:00全庫,週一二四六晚20:00歸檔日誌日誌

crontab -e

00 20 * * 0,3,5 sh /backup_sh/run_rman_ecology_all.sh >> /backup/rman_crontab_all.log 2>&1
00 20 * * 1,2,4,6 sh /backup_sh/run_rman_ecology_arc.sh >> /backup/rman_crontab_arc.log 2>&1

<font color='red'>格式是「分 時 日 月 周 要執行的命令或腳本」。</font>  code

九、重啓計劃任務:

service cron restart     啊!總算完成了~~~ 原本只是由於網上Rman的教程不繫統化,想本身寫一篇造福人類而已。 寫着寫着發現一篇寫不下,太雜亂了ψ(*`ー´)ψ 因而就變成了兩篇...而後是三篇....最後擴展成了四篇...... 歷時一個月,也算完成一個系列筆記了吧(^_−)☆

相關文章
相關標籤/搜索