RMAN备份的特性

 1.并发:主要用于提高备份的速度,可以分为手动并发或自动并发

        手动并发:通过分配多个通道并将文件指定到特定的通道

       

            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 incremental level=0

            6>  format '/u01/app/oracle/rmanbak/df_%d_%U'

            7>  (datafile 1 channel ch1 tag='sys')

            8>  (datafile 3 channel ch2 tag='aux')

            9>  (datafile 2,4,5,6 channel ch3 tag='other');

            10> sql 'alter system archive log current';

            11> release channel ch1;

            12> release channel ch2;

            13> release channel ch3;

            14> }  

 

        自动并发:使用configure配置并发度即可

            RMAN> configure device type disk parallelism 3 backup type to backupset;

           

            --下面的备份将自动启用个通道执行并发

            RMAN>  backup database format '/u01/app/oralce/rmanbak/p3_%U';

 

    2.复用备份

        即将一个备份集复制多份,同一备份集,Oracle最多可复用个

        手工指定:

            RMAN> backup copies 2 datafile 4

            2> format '/u01/app/oracle/rmanbak/d1/df_%U',

            3>        '/u01/app/oracle/rmanbak/d2/df_%U';  

           

        自动指定:配置下列参数

            RMAN> configure datafile backup copies for device type disk to 2;  --指定备份数据文件副本数

            RMAN> configure archivelog backup copies for device type disk to 2;--指定备份日志文件副本数

           

    3.备份备份集

        bacup backupset

       

    4.镜像备份

        镜像备份时会检查数据文件中是否存在坏块,可以使用nochecksum来跳过坏块的检测

        也可以指定maxcorrupt判断有多少个坏块时,Oracle将停止该镜像备份

       

        RMAN> backup as copy

        2> datafile 4 format '/u01/app/oracle/rmanbak/users.dbf' tag='users'

 

        --以下命令等同于上一条

        RMAN> copy datafile 4 to '/u01/app/oracle/rmanbak/user01.dbf';

 

        RMAN> backup as copy

        2> archivelog like 'o1_mf_1_118_6chl1byd_.arc'

        3> format '/u01/app/oracle/rmanbak/arch_1015.bak';

 

        --使用下面的configure命令将backup type设置为copy之后,则缺省的备份为镜像副本

        RMAN> configure device type disk parallelism 1 backup type to copy;

 

        RMAN> backup datafile 4  --由于上面的设置,则此命令备份的将是镜像副本

        2> format '/u01/app/oracle/rmanbak/users.dbf.bak' tag=users;   

 

        --使用并行度来执行镜像拷贝

        RMAN> configure device type disk parallelism 4;

 

        RMAN> backup as copy #3 files copied in parallel

        2> (datafile 1 format '/u01/app/oracle/rmanbak/df1.bak')

        3> (datafile 2 format '/u01/app/oracle/rmanbak/df2.bak')

        4> (datafile 3  format '/u01/app/oracle/rmanbak/df3.bak');

       

        镜像备份时指定子句DB_FILE_NAME_CONVERT来实现镜像路径转移,该子句也是一个初始化参数,用于primary db 到standby db

            的数据文件的转换

           

            DB_FILE_NAME_CONVERT = ('string1' , 'string2' , 'string3' , 'string4' ...)

            用string2替换string1,string4替换string3

           

            RMAN> backup as copy device type disk

            2> db_file_name_convert('oradata/orcl','bk/rmbk')

            3> tablespace users;       

           

    5.压缩备份集   

        RMAN> configure channel device type disk format '/u01/app/oracle/rmanbak/%d_%U.bak';

       

        --下面的命令使用了参数as compressed来实现手动压缩

        RMAN> backup as compressed backupset database;

        RMAN> backup as compressed backupset datafile 4,5,6;

       

        --下面使用configure命令配置自动压缩备份集功能,则后续的备份会自动使用压缩功能

        RMAN> configure device type disk parallelism 4 backup type to compressed backupset;

       

        --由于设置了自动压缩,则下面的命令将压缩备份的system表空间及控制文件、参数文件

        RMAN> backup tablespace system tag=system;

       

    6.使用tag标记

        tag标记可以为备份集或映像副本指定一个有意义的名字,以备后续使用,其优点如下

            为备份集或映像副本提供描述信息

            能够在list 命令中使用更好的定位备份文件

            能够在restore和switch命令中使用

            同一个tag在多个备份集或多个映像副本中使用

            当未指定tag标记时,则系统产生缺省的tag标记,其格式为:TAGYYYYMMDDTHHMMSS

       

        RMAN> backup as compressed backupset datafile 1,2,3 tag='Monthly_full_bak';

       

        RMAN> backup as compressed backupset tablespace users tag='Weekly_full_bak';

               

        RMAN> list backupset tag=monthly_full_bak; 

 

    7.增量备份

        差异增量备份将备份自上次增量备份以来所有发生改变的数据块

        累计增量备份将备份自上次级增量备份以来所有改变过的数据块

       

        --下面启用级增量备份

        RMAN> run{

        2> allocate channel ch1 type disk;

        3> backup incremental level 0 database

        4> format '/u01/app/oracle/rmanbak/db_%d_%U'

        5> tag=db_inc_0;

        6> release channel ch1;

        7> }

 

        SQL> select sid,sofar,totalwork from v$session_longops;  --查询备份情况

 

        --下面启用级差异增量备份

        RMAN> run{

        2> allocate channel ch1 type disk;

        3> backup incremental level 1 database

        4> format '/u01/app/oracle/rmanbak/db1_%d_%U'

        5> tag=db_inc_1;

        6> release channel ch1;

        7> }

 

        --下面启用级累计增量备份

        RMAN> run{

        2> allocate channel ch1 type disk;

        3> backup incremental level 1 cumulative database

        4> format '/u01/app/oracle/rmanbak/dbc_%d_%U'

        5> tag=db_inc_c_1;

        6> release channel ch1;

        7> }

 

    8.启用块变化跟踪

        启用块变化跟踪即是指定一个文件用于记录数据文件中哪些块发生了变化,在RAMN进行增量备份时,仅仅需读取该文件来备份这些

        发生变化的块,从而减少了备份时间和I/O资源。

        使用下面的命令来启用块变化跟踪

            ALTER DATABASE ENABLE BLOCK CHANGE TRACKING USING FILE '<dir>'

 

        SQL> alter database enable block change tracking

          2  using file '/u01/app/oracle/oradata/orcl/blk_ch_trc.trc';

 

        SQL> ho ls -lht /u01/app/oracle/oradata/orcl/blk_ch_trc.trc

        -rw-r----- 1 oracle oinstall 12M Oct 15 19:41 /u01/app/oracle/oradata/orcl/blk_ch_trc.trc

 

        SQL> select * from v$block_change_tracking;

 

        STATUS     FILENAME                                           BYTES

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

        ENABLED    /u01/app/oracle/oradata/orcl/blk_ch_trc.trc     11599872

 

        SQL> alter database disable block change tracking; --disable后块变化跟踪文件被自动删除

 

        SQL>  select * from v$block_change_tracking;

 

        STATUS     FILENAME                                           BYTES

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

        DISABLED       

       

    9.备份保留策略

        保留策略主要是保留备份副本的一些规则,通常用于满足恢复或其他的需要(比如磁盘空间或磁带空间大小限制)

        备份保留策略分为冗余和恢复窗口,这两种保留策略互不兼容,要么使用前者,要么使用后者

        备份冗余

            默认为,可以通过RMAN> configure retention policy to redundancy 2;来修改

            当为时,RMAN会为每个数据文件、归档日志、控制文件生成一个备份。可以使用report obsolete命令查看备份数多于的备份

            并使用delete obsolete来删除过时的备份

           

        恢复窗口       

            恢复窗口允许完成恢复到过去某个时间点的时点恢复,通常设定为多少天

            使用命令RMAN> configure retetion policy to recovery window of 7 days

            该命令将确保具有足够的数据文件和归档日志来执行能够返回一个星期中任意时间点的不完全恢复,且允许删除随着时间推移

                而变为废弃的备份,即应当满足该条件:SYSDATE - BACKUP CHECKPOINT TIME >= 7

            对于大于天但是是恢复所需要的备份依然会被保留

           

        清除备份保留策略

            RMAN> configure retention policy clear;

           

        注意obsolete 与expired

            obsolete:是指根据保留策略来确定该备份是否在恢复的时候需要,如不在需要或有更新的备份来替代,则该备份集被置为

                obsolete,即废弃的备份集或镜像副本。

            expired: 是指执行crosscheck时,根据存储仓库中记录的备份信息来定位备份集或镜像副本,而找不到对应的备份集或镜像副

                本,则这些备份集或镜像副本被置为expired。

 

    10.使用BACKUP ... VALIDATE验证数据文件逻辑坏块,损坏的坏块将被记录到v$database_block_corruption视图

            BACKUP VALIDATE CHECK LOGICAL DATABASE ARCHIVELOG ALL;

你可能感兴趣的:(rman)