码迷,mamicode.com
首页 > 其他好文 > 详细

RMAN 配置、监控与管理

时间:2016-08-02 13:17:33      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:

=========================

-- RMAN 配置、监控与管理

--=========================

 

 

一、通道及通道分配

    1.通道的概念

        一个通道代表一个到设备(磁盘或磁带)的数据流并且在目标数据库或辅助数据库实例上产生一个相应的服务器会话(server session)

        多个通道则产生多个服务器会话,这些服务器会话(或进程)将完成备份、还原与恢复操作等

        通道分为备份或还原到磁盘的磁盘通道(disk channel)、备份还原到磁带的磁带通道(SBT)

        在对数据库执行备份和恢复前必须先分配通道

        ALLOCATE CHANNEL命令在目标数据库启动一个服务器进程,同时必须定义服务器进程执行备份或者恢复操作使用的I/O类型

        实际上是通过channel来控制备份及恢复时的行为

           

        通道控制命令的作用:

            控制RMAN使用的OS资源

            影响并行度

            指定I/O 带宽的限制值(设置limit read rate参数)

            定义备份片大小的限制(设置limit kbytes)

            指定当前打开文件的限制值(设置limit maxopenfiles)

           

    2.自动分配通道

        可以使用下列命令来自动分配通道,一旦RMAN设定了下列参数,则RMAN根据这些配置来自动分配通道

            CONFIGURE DEVICE TYPE ...PARALLELISM

            CONFIGURE DEFAULT DEVICE TYPE

            CONFIGURE CHANNEL

                假定在RMAN提示符下执行backup datafile 1,则RMAN会使用预先配置的通道参数为之分配通道

                这些命令backup、restore、delete在非run块中运行时会根据configure命令设定的值自动分配通道

                但上述命令在run块中则需要手动分配通道

                   

        改变缺省的设备类型

            RMAN> CONFIGURE DEFAULT DEVICE TYEP TO sbt;

        为自动分配通道配置并行度

            RMAN> CONFIGURE DEVICE TYPE DISK PARALLELISM 3;

        配置自动通道选项

            RMAN> CONFIGURE CHANNEL DEVICE TYPE DISK

               2> FORMAT = ‘/BACKUP/RMAN/%U‘;

         

            RMAN> CONFIGURE CHANNEL DEVICE TYPE DISK

               2> MAXPIECESIZE 3G;

       

        --演示,将device type 改为sbt后再改回到缺省值

            RMAN> show default device type;   --显示default device type 的值

 

            RMAN configuration parameters are:

            CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default

 

            RMAN> configure default device type to sbt;  --将default device type值置为sbt

 

            new RMAN configuration parameters:

            CONFIGURE DEFAULT DEVICE TYPE TO ‘SBT_TAPE‘;

            new RMAN configuration parameters are successfully stored

 

            RMAN> show default device type ;   --显示更改后的default device type 的值

 

            RMAN configuration parameters are:

            CONFIGURE DEFAULT DEVICE TYPE TO ‘SBT_TAPE‘;

 

            RMAN> configure default device type clear;  --将default device type置为缺省值

 

            old RMAN configuration parameters:

            CONFIGURE DEFAULT DEVICE TYPE TO ‘SBT_TAPE‘;

            RMAN configuration parameters are successfully reset to default value

 

            RMAN> show default device type;

 

            RMAN configuration parameters are:

            CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default

           

    3.手动分配通道

        BACKUP,COPY,RESTORE,RECOVER等命令至少需要分配一个通道

        分配一个通道将在目标数据库所在服务器启动一个服务进程,分配的通道实际上是指定了并发度

        可以指定备份到不同的介质,并且可以在手工通道时指定读写速度

        RMAN> RUN {

           2> ALLOCATE CHANNEL ch1 TYPE disk

           3> BACKUP DATAFILE 1,2,4

           4> FORMAT  ‘/u01/app/oralce/rmanbak/users_%U.bak‘;}

                  

        下面的示例分配了个通道,且对不同的数据文件使用不同的通道来完成备份工作

        RMAN> RUN {

            2> allocate channel ch1 device type disk;

            3> allocate channel ch2 device type disk;

            4> allocate channel ch3 device type disk;

            5> backup

            6>    incremental level 0

            7>    (datafile 1,4 channel ch1)

            8>    (datafile 2,3 channel ch2)

            9>    (datafile 5,6 channel ch3);

            10> alter system archive log current;}

          

    4.通道配置选项

        connect :是一个Oracle Net连接串。一般不适用于单实例环境

        format : 为通道创建的备份片或映像副本确定路径与文件名

        duration: 控制作业的时间总量,以小时和分钟进行指定

        maxopenfiles:该选项限制RMAN一次能够打开的输入文件数,默认为

        maxpiecesize:限制一个备份集分割的备份片的大小,以字节(默认)、k、m、g为单位

        parms:能够被用于设置sbt_type通道所需的任何变量

        filesperset:备份集中可容纳的文件数

 

二、configure命令的使用

    configure命令可以完成下列任务

            配置通道的自动分配

            指定备份的保留策略

            指定备份副本的副本数

            限制备份集的大小

            设置缺省的备份类型为备份集或镜像备份

            启用或关闭备份优化

            配置是否自动备份控制文件

        配置备份到磁带 

            RMAN> CONFIGURE DEFAULT DEVICE TYPE TO SBT;

           

        如配置自动通道

            RMAN> CONFIGURE CHANNEL DEVICE TYPE DISK

                2> FORMAT = ‘/BACKUP/RMAN/%U‘;

               

        配置保留策略恢复窗口

            RMAN> CONFIGURE RETENTION POLICY TO RECOVERY

               2> WINDOW OF 7 DAYS;

              

        配置保留策略的冗余数

            RMAN> CONFIGURE RETENTION POLICY TO REDUNDANCY 2;

       

        配置多个备份镜像

            RMAN> CONFIGURE DATAFILE BACKUP COPIES FOR

               2> DEVICE TYPE disk TO 2;

              

        配置自动优化备份

            RMAN> CONFIGURE BACKUP OPTIMIZATION ON;

           

        使用清除命令恢复到缺省值

            RMAN> CONFIGURE RETENTION POLICY CLEAR;

            RMAN> CONFIGURE CHANNEL DEVICE TYPE sbt CLEAR;

           

        配置备份的并行度

            RMAN> CONFIGURE DEVICE TYPE DISK PARALLELISM 2

           

        配置备份片的大小

            RMAN> configure channel device type disk maxpiecesize=1G;

           

        配置I/O读速率(使用allocate channel 或configure channel的rate选项)

            RMAN> configure channel device type disk rate 1M;

           

        演示:

            RMAN> show controlfile autobackup;   

 

            RMAN configuration parameters are:

            CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default

 

            RMAN> configure controlfile autobackup on;   --配置控制文件的自动备份

 

            new RMAN configuration parameters:

            CONFIGURE CONTROLFILE AUTOBACKUP ON;

            new RMAN configuration parameters are successfully stored

 

            RMAN> show controlfile autobackup;

 

            RMAN configuration parameters are:

            CONFIGURE CONTROLFILE AUTOBACKUP ON;

 

            RMAN> configure controlfile autobackup clear;

 

            old RMAN configuration parameters:

            CONFIGURE CONTROLFILE AUTOBACKUP ON;

            RMAN configuration parameters are successfully reset to default value  

 

三、Show命令的使用

    show命令用于显示永久配置设置的相关信息

    使用show命令显示的主要内容有

        自动通道配置设置

        备份保留策略设置

        备份镜像副本数量

        备份集大小设置

        从备份中排除的表空间

        备份优化状态

    最常用的是show all命令

    也可以显示单个设置的信息,如

        RMAN> show backup optimization;

 

        RMAN configuration parameters are:

        CONFIGURE BACKUP OPTIMIZATION OFF; # default   

       

        RMAN> show exclude;

 

        RMAN configuration parameters are:

        RMAN configuration has no stored or default parameters     

       

四、List命令的使用

    列出备份集、数据文件镜像等

    列出指定表空间任意数据文件的备份集或镜像副本

    列出指定范围内包含归档日志的备份集或镜像副本

   

    RMAN> list backup;

    RMAN> list copy;

    RMAN> list backup of database;

    RMAN> list backup of tablespace uers;

    RMAN> list backup of archivelog all;

    RMAN> list backup verbose;

    RMAN> list backup summary;

    RMAN> list backup of datafile { n | <dir>}

    RMAN> list copy of archive from time = ‘sysdate - 7‘;

    RMAN> list backup of archivelog from sequence 1000 until sequence 1020;

    RMAN> list backupset tag=TAG20101014T155753;

 

    RMAN> list backup;   --列出备份信息

 

    List of Backup Sets

    ===================

 

    BS Key  Type LV Size       Device Type Elapsed Time Completion Time

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

    1       Full    25.47M     DISK        00:00:04     13-OCT-10      

            BP Key: 1   Status: AVAILABLE  Compressed: NO  Tag: TAG20101013T170706

            Piece Name: /u01/app/oracle/rmanbak/user_02lqc29q_1_1.bak

      List of Datafiles in backup set 1

      File LV Type Ckp SCN    Ckp Time  Name

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

      4       Full 1610281    13-OCT-10 /u01/app/oracle/oradata/orcl/users01.dbf   

     

    RMAN> list backup of datafile 4;  --列出datafile文件编号为的备份信息

 

    List of Backup Sets

    ===================

 

    BS Key  Type LV Size       Device Type Elapsed Time Completion Time

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

    1       Full    25.47M     DISK        00:00:04     13-OCT-10     

            BP Key: 1   Status: AVAILABLE  Compressed: NO  Tag: TAG20101013T170706

            Piece Name: /u01/app/oracle/rmanbak/user_02lqc29q_1_1.bak

      List of Datafiles in backup set 1

      File LV Type Ckp SCN    Ckp Time  Name

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

      4       Full 1610281    13-OCT-10 /u01/app/oracle/oradata/orcl/users01.dbf

 

    BS Key  Type LV Size       Device Type Elapsed Time Completion Time

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

    2       Full    435.04M    DISK        00:01:37     13-OCT-10     

            BP Key: 2   Status: AVAILABLE  Compressed: NO  Tag: TAG20101013T171906

            Piece Name: /u01/app/oracle/rmanbak/dfile_ORCL_04lqc30a_1_1.bak

      List of Datafiles in backup set 2

      File LV Type Ckp SCN    Ckp Time  Name

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

      4       Full 1610888    13-OCT-10 /u01/app/oracle/oradata/orcl/users01.dbf     

 

    RMAN> list backup summary;

 

 

    List of Backups

    ===============

    Key     TY LV S Device Type Completion Time #Pieces #Copies Compressed Tag

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

    1       B  F  A DISK        13-OCT-10       1       1       NO         TAG20101013T170706

    2       B  F  A DISK        13-OCT-10       1       1       NO         TAG20101013T171906

    3       B  F  A DISK        13-OCT-10       1       1       NO         TAG20101013T171906    

   

五、Report命令的使用

    Report命令显示存储仓库中详细的分析信息

    比如,哪些文件需要备份

          哪些备份可以被删除

          哪些文件不可恢复等

    RMAN> report schema;

    RMAN> report need backup;

    RMAN> report need backup days 3;

    RMAN> report need backup redundancy 3; 

    RMAN> report need backup recovery window of 3 days;

    RMAN> report obsolete;

    RMAN> report unrecoverable;

    RMAN> report schema at time ‘sysdate-7‘;

    RMAN> report need backup days 2 tablespace system;

   

    RMAN> report need backup;

 

    RMAN retention policy will be applied to the command

    RMAN retention policy is set to redundancy 1

    Report of files with less than 1 redundant backups

    File #bkps Name

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

    3    0     /u01/app/oracle/oradata/orcl/sysaux01.dbf

    5    0     /u01/app/oracle/oradata/orcl/example01.dbf

    6    0     /u01/app/oracle/oradata/orcl/tbs1.dbf

 

六、Delete命令的使用

    删除相关的备份集或镜像副本的物理文件,同时将删除标记delete更新到控制文件.如果使用恢复目录,则是清除恢复目录内的该备份集。

    RMAN> delete backupset;

    RMAN> delete backupset n;

    RMAN> delete obsolete ;

    RMAN> delete obsolete redundancy 2;

    RMAN> delete noprompt copy;

    RMAN> delete noprompt backupset tag TAG20101016T143521;

    RMAN> delete obsolete recovery window of 7 days;

    RMAN> delete expired backupset;

    RMAN> delete expired copy;

    RMAN> delete expired archivelog all;

   

七、crosscheck命令的使用

    用于校验存储仓库中的备份集或镜像副本,执行该命令后,将更新存储仓库中的刚刚校验的对象状态,便于后续操作处理。

    RMAN备份校验时的几种状态

        expired: 对象不存在于磁盘或磁带。当一个备份集处于expired状态,则该备份集中所有的备份片同样处于expired状态

        available: 对象处于可用状态。当一个备份集可用,则该备份集内的所有备份片同样可用

        unavailabe: 对象处于不可用状态。当一个备份集不可用,则该备份集内的所有备份片同样不可用

        注:expired不等同于obsolette。两者的差异请参考:RMAN 备份详解

       

    校验时的限制

        目标数据库必须被启动

        对于磁盘上的备份集,校验时不需要使用通道。而磁带上的备份集则必须使用通道,如果未为磁带配置自动通道,则必须手动分配

        可以校验执行resetlogs之前的备份,即可以校验不同的incarnation

        RMAN> crosscheck backupset;                --校验备份集

        RMAN> crosscheck copy;                   --校验镜像副本

        RMAN> crosscheck backup of controlfile;    --校验备份的控制文件

        RMAN> crosscheck backup of archivelog all; --校验所有备份的归档日志

        RMAN> crosscheck backup of datafile 1,2;   --校验datafile 1,2

        RMAN> crosscheck backup of tablespace sysaux,system;                      --校验表空间sysaux,system

        RMAN> crosscheck backup completed between ‘13-OCT-10‘ and ‘23-OCT-10‘; --校验时间段,时间段格式由NLS_DATE_FORMAT设置

        RMAN> crosscheck backupset 1067,1068;                                     --校验指定的备份集

 

八、validate命令的使用

    验证一个备份集内的数据的完整性。RMAN扫描备份集的所有备份片,并检查校验和,验证其内容是否可以成功还原

    validate是较crosscheck更高一级的验证操作.crosscheck仅仅是检查备份集的头部信息,校验文件的存在性,validate验证数据的有效性

       

        RMAN> validate backupset <primary key> [check logical]

        check logical测试数据和索引块,将验证得到的逻辑错误填充到V$DATABASE_BLOCK_CORRUPTION  视图

        也可以使用restore ... validate 子句来测试可还原性,而非真实的还原数据

       

        RMAN> list backupset summary;

        List of Backups

        ===============

        Key     TY LV S Device Type Completion Time #Pieces #Copies Compressed Tag

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

        1138    B  0  A DISK        13-OCT-10       1       1       YES        INC0

        1139    B  0  A DISK        13-OCT-10       1       1       YES        INC0

        1168    B  A  A DISK        13-OCT-10       1       1       YES        ARCHBK

        1181    B  F  A DISK        13-OCT-10       1       1       YES        CTLSPFILE_BK

 

 

        RMAN> validate backupset 1138,1139,1168,1181;  --验证备份集是否是有效的备份用于进行恢复

        using channel ORA_DISK_1

        channel ORA_DISK_1: starting validation of datafile backupset

        channel ORA_DISK_1: reading from backup piece /u01/oracle/bk/rmbk/inc0_ORCL_1gltn8te_1_1

        channel ORA_DISK_1: validation complete, elapsed time: 00:00:01

 

        RMAN> validate backupset 1138,1139,1168,1181 check logical;

 

        using channel ORA_DISK_1

        channel ORA_DISK_1: starting validation of datafile backupset

        channel ORA_DISK_1: reading from backup piece /u01/oracle/bk/rmbk/inc0_ORCL_1gltn8te_1_1

        channel ORA_DISK_1: validation complete, elapsed time: 00:00:01

 

九、影响RMAN的相关参数

    数据库初始化参数

        control_file_record_keep_time  --指定控制文件内RMAN信息被覆盖前保留的最小天数

        db_recovery_file_dest          --如果将RMAN备份到此处,需要设置该参数

        db_recovery_file_dest_size     --如果将RMAN备份到此处,需要设置该参数

    环境变量参数

        nls_date_format                --设定日期

        nls_lang                       --设定环境变量影响restore,recover,report等命令

       

十、保留策略

        有关保留策略请参考:RMAN 备份详解

转:http://blog.csdn.net/leshami/article/details/6032597

RMAN 配置、监控与管理

标签:

原文地址:http://www.cnblogs.com/andy6/p/5728770.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!