Oracle資料庫中rman備份指令碼非常實用

來源:互聯網
上載者:User

Oracle資料庫中rman備份指令碼非常實用

Oracle資料庫中rman備份指令碼非常實用

查詢字元集

SQL> select * from nls_database_parameters; 

NLS_CHARACTERSET
AL32UTF8 

備份時字元集很重要,不然會出亂碼

一、0級備份(全備)紅色是要修改的,根據個人的存放位置。

[oracle@oracle122 script]$ cat db_bak0.rman
run
{
    configure retention policy to recovery window of 8 days;
    configure controlfile autobackup on;
    configure controlfile autobackup format for device type disk to '/home/oracle/rmanbak/%F';
    allocate channel ch1 device type disk format '/home/oracle/rmanbak/inc0_%d_%s_%p_%u_%T';
    backup incremental level 0 tag='level 0' database skip inaccessible filesperset 10 plus archivelog filesperset 20;
    release channel ch1;
}
allocate channel for maintenance device type disk;
crosscheck backup;
delete noprompt expired backup;
delete noprompt obsolete;
delete noprompt archivelog until time 'sysdate-30';

0級運行指令碼

[oracle@oracle122 script]$ cat exec_0_level.sh
ORACLE_HOSTNAME=oracle122; export ORACLE_HOSTNAME
ORACLE_BASE=/u01/app; export ORACLE_BASE
ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1; export ORACLE_HOME
ORACLE_SID=orcl; export ORACLE_SID
ORACLE_TERM=xterm; export ORACLE_TERM
PATH=/usr/sbin:$PATH; export PATH
PATH=$ORACLE_HOME/bin:$PATH; export PATH
export DATE=$(date +%Y_%m_%d)
export NLS_LANG="Simplified Chinese_china".AL32UTF8

/u01/app/oracle/product/11.2.0/dbhome_1/bin/rman target sys/sys_admin cmdfile /home/oracle/rmanbak/script/db_bak0.rman log /home/oracle/rmanbak/script/log/rman_$DATE.log append

二、1級備份(增量)

[oracle@oracle122 script]$ cat db_bak1.rman
run
{
    configure retention policy to recovery window of 8 days;
    configure controlfile autobackup on;
    configure controlfile autobackup format for device type disk to '/home/oracle/rmanbak/%F';
    allocate channel ch1 device type disk format '/home/oracle/rmanbak/inc1_%d_%s_%p_%u_%T';
    backup incremental level 1 tag='level 1' database skip inaccessible filesperset 10 plus archivelog filesperset 20;
    release channel ch1;
}
allocate channel for maintenance device type disk;
crosscheck backup;
delete noprompt expired backup;
delete noprompt obsolete;
delete noprompt archivelog until time 'sysdate-30';

1級運行指令碼

[oracle@oracle122 script]$ cat exec_1_level.sh
ORACLE_HOSTNAME=oracle122; export ORACLE_HOSTNAME
ORACLE_BASE=/u01/app; export ORACLE_BASE
ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1; export ORACLE_HOME
ORACLE_SID=orcl; export ORACLE_SID
ORACLE_TERM=xterm; export ORACLE_TERM
PATH=/usr/sbin:$PATH; export PATH
PATH=$ORACLE_HOME/bin:$PATH; export PATH
export DATE=$(date +%Y_%m_%d)
export NLS_LANG="Simplified Chinese_china".AL32UTF8

/u01/app/oracle/product/11.2.0/dbhome_1/bin/rman target sys/sys_admin cmdfile /home/oracle/rmanbak/script/db_bak1.rman log /home/oracle/rmanbak/script/log/rman_$DATE.log append

 

三、2級備份(從0級追加到現在的備份)

[oracle@oracle122 script]$ cat db_bak2.rman
run
{
    configure retention policy to recovery window of 8 days;
    configure controlfile autobackup on;
    configure controlfile autobackup format for device type disk to '/home/oracle/rmanbak/%F';
    allocate channel ch1 device type disk format '/home/oracle/rmanbak/inc2_%d_%s_%p_%u_%T';
    backup incremental level 2 tag='level 2' database skip inaccessible filesperset 10 plus archivelog filesperset 20 delete all input;
    release channel ch1;
}
allocate channel for maintenance device type disk;
crosscheck backup;
delete noprompt expired backup;
delete noprompt obsolete;

2級運行指令碼

[oracle@oracle122 script]$ cat exec_2_level.sh
ORACLE_HOSTNAME=oracle122; export ORACLE_HOSTNAME
ORACLE_BASE=/u01/app; export ORACLE_BASE
ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1; export ORACLE_HOME
ORACLE_SID=orcl; export ORACLE_SID
ORACLE_TERM=xterm; export ORACLE_TERM
PATH=/usr/sbin:$PATH; export PATH
PATH=$ORACLE_HOME/bin:$PATH; export PATH
export DATE=$(date +%Y_%m_%d)
export NLS_LANG="Simplified Chinese_china".AL32UTF8

/u01/app/oracle/product/11.2.0/dbhome_1/bin/rman target sys/sys_admin cmdfile /home/oracle/rmanbak/script/db_bak2.rman log /home/oracle/rmanbak/script/log/rman_$DATE.log append 

定時備份星期天為0級全備,星期三為2級備份,星期一,星期二,星期四,星期五,星期六為1級增量備份晚上11點開始備份

[oracle@oracle122 script]$ crontab -l
* 23 * *  0 /home/oracle/rmanbak/script/exec_0_level.sh
* 23 * *  1 /home/oracle/rmanbak/script/exec_1_level.sh
* 23 * *  2 /home/oracle/rmanbak/script/exec_1_level.sh
* 23 * *  3 /home/oracle/rmanbak/script/exec_2_level.sh
* 23 * *  4 /home/oracle/rmanbak/script/exec_1_level.sh
* 23 * *  5 /home/oracle/rmanbak/script/exec_1_level.sh
* 23 * *  6 /home/oracle/rmanbak/script/exec_1_level.sh

--------------------------------------推薦閱讀 --------------------------------------

RMAN 配置歸檔日誌刪除策略

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

RMAN備份策略制定參考內容

RMAN備份學習筆記

OracleDatabase Backup加密 RMAN加密

--------------------------------------分割線 --------------------------------------

相關文章

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.