基于Linux下 Oracle 备份策略(RMAN)

基于Linux下 Oracle 备份策略(RMAN)


--**********************************

-- 基于Linux Oracle 备份策略(RMAN)

--**********************************

 

     Oracle 备份与管存在热备,冷以及逻辑备份之外,使用最多的莫于使用RMAN备份与。而制定RMAN备份是基于库丢失的容忍程度,即恢策略制定。在下面的备份策略中,出的是一通用的备份策略。在该备份策略中,使用了nocatalog保持备份本以及备份信息。在实际环境中根据具体的情况对行相。因为我现在目前接手的是一台单实例,一台RAC,所以么有必要做catalog方式。

 

 

一、步

1.认备份可用空以及备份,根据需要建相文件

 

    2.建通用的脚本用于过旧备份备份控制文件以及备份归档日志

        global_del_obso      --过旧备份

        global_bkctl         --备份控制文件

        global_arch          --备份归档日志

    3.0,1级差异增量备份

        脚本中均包含第2步的3脚本,先global_del,然后做增量备份,最后备份归档日志global_arch和控制文件global_bkctl

 

    4.inc0.rcv,inc1.rcv

        文件容包含 @@/<dir>/connect.rcv以及run{execute globalscript scriptname;}exit;

       

    5.编辑4步的三文件分别为inc0.sh,inc1.sh

        nohup $ORACLE_HOME/bin/rman cmdfile=/u03/bk/scripts/inc1.rcv log=/u03/bk/scripts/inc0.logappend &

   

    6.使用crontab制定备份计划   

 

二、具体实现

    演示境:

                    RHEL release 5.4 (Final) +Oracle 11.2.3

        标数      qbjmes

        录数:  

        备份        /u03/bk

        接脚本所在路

        注:听需要配置好且已启动

   

 1.接脚本

        connect.rcv文件

        connect nocatalog rman target /

 

2.建立通用脚本

        --除不必要的备份

run

{

allocatechannel ch1 device type disk;

crosscheck archivelog all;

                delete noprompt expired archivelog all;

                delete noprompt obsolete recovery window of 7days; 

                releasechannel ch1;

            }

 

       --备份控制文件脚本

run

{

                allocate channel ch1 device type disk;

                backup as compressed backupset

                current controlfile reuse

                format='/u03/bk/backupctl.ctl'

                tag='bkctl';

            release channel ch1;

            }

     

--备份归档日志脚本

            run

{

           allocate channel ch1 device type disk;

            allocate channelch2 device type disk;

            sql"alter system archive log current";   --归档当前的机日志

            set limit channelch1 readrate=10240;        --(取速率10M)             

            set limit channel ch1 kbytes=4096000;        --(备份片的大   

            backup ascompressed backupset

            format='/u03/bk/arch_%d_%U'

            tag='bkarch'

            archivelog all deleteinput;

            release channel ch1;

            release channel ch2;

            }

 

 

    3.01级差异增量备份脚本(注:每脚本备份会执过旧备份,脚本尾部会调用另外两个脚本来备份归档日志及控制文件)

        --0增量备份

           run

{

            allocate channelch1 device type disk;

            allocate channelch2 device type disk;

            set limit channel ch1 readrate=10240;

            set limit channelch1 kbytes=4096000;

            set limit channelch2 readrate=10240;

            set limit channelch2 kbytes=4096000;

            backup ascompressed backupset

            incremental level 0 database

            format='/u03/bk/inc0_%d_%U'

            tag='inc0';

            release channel ch1;

            release channel ch2;

        

            }

           

        --1增量备份        

            run

{

                allocate channel ch1 device type disk;

                allocate channel ch2 device type disk;

           set limit channel ch1 readrate=10240;

                set limit channel ch1 kbytes=4096000;

                set limit channel ch2 readrate=10240;

                set limit channel ch2 kbytes=4096000;

                backup as compressed backupset

                incrementallevel 1 database

                format='/u03/bk/inc1_%d_%U'

                tag='inc1';

                releasechannel ch1;

                releasechannel ch2;

            }

 

--备份成情

            listbackupset summary;

 

    4.建立shell脚本,linux动执行脚本

        a. vi inc0.rcvinc1.rcv               --注意不同的文件行不同的备份脚本

        @@/u03/bk/scripts/connect.rcv       --(rman下的脚本去用其他脚本用@@)(用脚本不需要分)

            run{

            execute globalscript gloal_inc0;

            }

            exit;

    

        b. 编辑shell文件   

            vi inc0.sh

                nohup  $ORACLE_HOME/bin/rman  cmdfile=/u03/bk/scripts/inc0.rcvlog=/u03/bk/scripts/inc0.logappend &

            vi inc1.sh

                nohup  $ORACLE_HOME/bin/rman  cmdfile=/u03/bk/scripts/inc1.rcvlog=/u03/bk/scripts/inc0.logappend &

        

       

            --注意:nohup&表示脚本放入后台

    

        c.使用crontab建立一个备份计划

        crontab -e  

            #min    hour    date  mon  day(星期)   command

            10        3      *     *   0          /u03/bk/scripts/inc0.sh

            10        3      *     *   1          /u03/bk/scripts/inc1.sh

            10        3      *     *   2          /u03/bk/scripts/inc1.sh

            10        3      *     *   3          /u03/bk/scripts/inc1.sh

            10        3      *     *   4          /u03/bk/scripts/inc1.sh

            10        3      *     *   5          /u03/bk/scripts/inc1.sh

            10        3      *     *   6          /u03/bk/scripts/inc1.sh

       

        d.crontab(如果启动)

            # /sbin/service crond status  --用于检查crontab 务状态

            # /sbin/service crond stop //关闭

            # /sbin/service crond restart //

            # /sbin/service crond reload //重新入配置

           

            使crontab在系统启动候自动启动

                /etc/rc.d/rc.local这个脚本的末尾加上:

                /sbin/service crond start

 

        e.上面的备份策略看,即

            周日0增量备份,相于全

            周一,周二,周三,周四,周五,周六1增量备份

        

   

        f.编辑好的shell 脚本测试

            chmod 755*.sh         --shell脚本加

            测试脚本  例如./inc0.sh

       

三、总结

    1.backup controlfile in each scripts tail (在脚本的尾部备份控制文件)

    2.Delete obsolete backupset in each scripts threshold(备份)

    3.Switch logfile before backup database; (库备份以前切志,备份联机重做日志)

    4.Chmod u+x*.sh

 

后续:

 

1、配置RMAN

CONFIGURE CONTROLFILE AUTOBACKUP ON;

CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FORDEVICE TYPE DISK TO '/u02/backup/%F';

CONFIGURE CHANNEL 1 DEVICE TYPE DISKFORMAT   '/u02/rman/dt1/dt1_%U_%T';

CONFIGURE CHANNEL 2 DEVICE TYPE DISKFORMAT   '/u02/rman/dt2/dt2_%U_%T';

CONFIGURE COMPRESSION ALGORITHM 'LOW'

 

2、计划任务:

[oracle@qbjmes ~]$ crontab -l

10 3 * * 0 /u03/bk/scripts/lv0.sh

10 3 * * 1 /u03/bk/scripts/lv1.sh

10 3 * * 2 /u03/bk/scripts/lv1.sh

10 3 * * 3 /u03/bk/scripts/lv1.sh

10 3 * * 4 /u03/bk/scripts/lv1.sh

10 3 * * 5 /u03/bk/scripts/lv1.sh

10 3 * * 6 /u03/bk/scripts/lv1.sh

[oracle@qbjmes ~]$

3、新建目录

mkdir /u03/bk/scripts/

chown -R /u03

 

4、shell脚本

lv0.sh

 

#!/bin/bash

 

source /home/oracle/.bash_profile

rman target / log=/u02/backup/db_lv0_`date+%Y%m%d`.log <<EOF

configure retention policy to recoverywindow of 7 days;

run{

allocate channel disk1 type disk;

allocate channel disk2 type disk;

backup incremental level 0 database includecurrent controlfile format '/u02/backup/db_level0_data_%d_%T_%s'

plus archivelog format'/u02/backup/db_level0_arch_%d_%T_%s'delete all input;

delete noprompt obsolete;

crosscheck backup;

delete noprompt expired backup;

release channel disk1;

release channel disk2;

}

exit;

EOF

 

lv1

 

#!/bin/bash

 

source /home/oracle/.bash_profile

rman target / log=/u02/backup/db_lv1_`date+%Y%m%d`.log <<EOF

configure retention policy to recoverywindow of 7 days;

run{

allocate channel disk1 type disk;

allocate channel disk2 type disk;

backup incremental level 1 database includecurrent controlfile format '/u02/backup/db_level1_data_%d_%T_%s'

plus archivelog format'/u02/backup/db_level1_arch_%d_%T_%s'delete all input;

delete noprompt obsolete;

crosscheck backup;

delete noprompt expired backup;

release channel disk1;

release channel disk2;

}

exit;

EOF

 

 

 

6、新建一个拷贝scpuser

 useradd -m -u 2201 -g oinstall -Gdba,oper,asmdba -d /home/scpuser -s /bin/bash scpuser

7、交换钥匙

ssh-keygen ssh-copy-id

8、拷贝

crontab -e 自动任务

10 4 * * 0 scp /u02/backup/*[email protected]:/data/meslog/0

10 4 * * 1 scp /u02/backup/*[email protected]:/data/meslog/1

10 4 * * 2 scp /u02/backup/*[email protected]:/data/meslog/2

10 4 * * 3 scp /u02/backup/*[email protected]:/data/meslog/3

10 4 * * 4 scp /u02/backup/*[email protected]:/data/meslog/4

10 4 * * 5 scp /u02/backup/*[email protected]:/data/meslog/5

10 4 * * 6 scp /u02/backup/* [email protected]:/data/meslog/6

 

7、新建一个删除rmuser

 useradd -m -u 3301 -g oinstall -Gdba,oper,asmdba -d /home/scpuser -s /bin/bash rmuser

8、交换钥匙

ssh-keygen ssh-copy-id

9、授权

 chmod -R 777 /u02/backup

10、删除

crontab -e 自动任务

[rmuser@qbjmes ~]$ crontab -l

10 5 * * 0 rm /u02/backup/*

10 5 * * 1 rm /u02/backup/*

10 5 * * 2 rm /u02/backup/*

10 5 * * 3 rm /u02/backup/*

10 5 * * 4 rm /u02/backup/*

10 5 * * 5 rm /u02/backup/*

10 5 * * 6 rm /u02/backup/*

 

5、重启cron自动任务

/etc/init.d/cronttabrestart

 

通过收集网络资源整理获得,结合公司实际的情况改成这样,比较基础,还请赐教。

 

你可能感兴趣的:(rman备份)