linux下oracle备份策略(rman)

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

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

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

 

    Oracle 备份与管存在热备,冷以及逻辑备份之外,使用最多的莫于使用RMAN备份与。而制定RMAN备份

是基于库丢失的容忍程度,即恢策略制定。在下面的备份策略中,出的是一通用的备份策略。在该备份策略中,使用了catalog

保持备份本以及备份信息。在实际环境中根据具体的情况对行相整。

 

一、步

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

   

    1.账户建一connect.rcv文件包含接到target catalog信息

   

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

        global_del_obso      --过旧备份

        global_bkctl         --备份控制文件

        global_arch          --备份归档日志

   

    3.0,1,2增量备份

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

       

    4.inc0.rcv,inc1.rcv,inc2.rcv

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

       

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

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

   

    6.使用crontab制定备份计划   

 

二、具体实现

    演示境:

                    CentOS release 4.6 (Final) + Oracle 10g

        标数      austin

        录数:   david

        备份        /u03/bk

        接脚本所在路/u03/bk/scripts

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

   

    1.接脚本

        connect.rcv文件

            connect catalog rman/rman@david;

            connect target sys/oracle@austin;

        catalog的通用脚本

            rman cmdfile=/u03/bk/scripts/connect.rcv --(rman中使用外部脚本)

            rman catalog rman/rman@david target sys/oracle@austin   --使用脚本接后建通用脚本

 

    2.建立通用脚本

        --除不必要的备份

            RMAN> create global script global_del_obso  comment 'A script for obsolete backup and delete it' {

            2> crosscheck archivelog all;

            3> delete noprompt expired archivelog all;

            4> allocate channel ch1 device type disk;

            5> delete noprompt obsolete recovery window of 7 days; 

            6> release channel ch1;

            7> }

       

        --备份控制文件脚本

            RMAN> create global script global_bkctl comment 'A script for backup control file'{

            2> allocate channel ch1 device type disk;

            3> backup as compressed backupset

            4> current controlfile reuse

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

            6> tag='bkctl';

            7> release channel ch1;

            8> }

       

        --备份归档日志脚本

            RMAN> create global script global_arch comment "backup archivelog and then delete it" {

            2> allocate channel ch1 device type disk;

            3> allocate channel ch2 device type disk;

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

            5> set limit channel ch1 readrate=10240;        --(取速率10M)            

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

            7> backup as compressed backupset

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

            9> tag='bkarch'

            10> archivelog all delete input;

            11> release channel ch1;

            12> release channel ch2;

            13> }

       

        --使用list看所有的已建立的全局脚本

            list global script names;               --(列出所有的脚本)

            delete globals script script_name;      --(除脚本)

           

            RMAN> list global script names;

 

            List of Stored Scripts in Recovery Catalog

                        

                Global Scripts

                        

                   Script Name

                   Description

                   -----------------------------------------------------------------------

                   global_arch

                   backup archivelog and then delete it

           

                   global_bkctl

                   A script for backup control file

            

                   global_del_obso

                   A script for obsolete backup and delete it

   

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

        --0增量备份

            RMAN> create global script global_inc0 comment "backup database as incrmental level 0"{

            2> execute global script global_del_obso;

            3> allocate channel ch1 device type disk;

            4> allocate channel ch2 device type disk;

            5> set limit channel ch1 readrate=10240;

            6> set limit channel ch1 kbytes=4096000;

            7> set limit channel ch2 readrate=10240;

            8> set limit channel ch2 kbytes=4096000;

            9> backup as compressed backupset

            10> incremental level 0 database

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

            12> tag='inc0';

            13> release channel ch1;

            14> release channel ch2;

            15> execute global script global_arch;

            16> execute global script global_bkctl;

            17> }

           

        --1增量备份       

            RMAN> create global script global_inc1 comment "backup database as incrmental level 1"{

            2> execute global script global_del_obso;

            3> allocate channel ch1 device type disk;

            4> allocate channel ch2 device type disk;

            5> set limit channel ch1 readrate=10240;

            6> set limit channel ch1 kbytes=4096000;

            7> set limit channel ch2 readrate=10240;

            8> set limit channel ch2 kbytes=4096000;

            9> backup as compressed backupset

            10> incremental level 1 database

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

            12> tag='inc1';

            13> release channel ch1;

            14> release channel ch2;

            15> execute global script global_arch;

            16> execute global script global_bkctl;

            17> }

 

        --2增量备份       

            RMAN> create global script global_inc2 comment "backup database as incrmental level 2"{

            2> execute global script global_del_obso;

            3> allocate channel ch1 device type disk;

            4> allocate channel ch2 device type disk;

            5> set limit channel ch1 readrate=10240;

            6> set limit channel ch1 kbytes=4096000;

            7> set limit channel ch2 readrate=10240;

            8> set limit channel ch2 kbytes=4096000;

            9> backup as compressed backupset

            10> incremental level 2 database

            11> format='/u03/bk/inc2_%d_%U'

            12> tag='inc2';

            13> release channel ch1;

            14> release channel ch2;

            15> execute global script global_arch;

            16> execute global script global_bkctl;

            17> }

       

        --rman检验rman的脚本global_inc0global_inc1global_inc2,RMAN动检查,下面的句用来执行脚本(检验)

            RMAN> run{

            2> execute global script global_inc0;

            3> execute global script global_inc1;

            4> execute global script global_inc2;

            5> }

       

        --备份成情

            list backupset summary;

 

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

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

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

            run{

            execute global script gloal_inc0;

            }

            exit;

    

        b. 编辑shell文件   

            vi inc0.sh

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

            vi inc1.sh

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

            vi inc2.sh

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

       

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

    

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

        crontab -e  

            #min    hour    date  mon  day(星期)    command

            30        1      *     *    0           /u03/bk/scripts/inc0.sh

            30        1      *     *    1           /u03/bk/scripts/inc2.sh

            30        1      *     *    2           /u03/bk/scripts/inc2.sh

            30        1      *     *    3           /u03/bk/scripts/inc2.sh

            30        1      *     *    4           /u03/bk/scripts/inc1.sh

            30        1      *     *    5           /u03/bk/scripts/inc2.sh

            30        1      *     *    6           /u03/bk/scripts/inc2.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增量备份,相于全

            周一,周二,周三2增量备份

            周四1增量备份

            周五,周六2增量备份

   

        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

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页