RMAN 备份详解

一、数据库备份与RMAN备份的概念

   

    1.数据库完全备份:按归档模式分为归档和非归档

        归档模式

            打开状态,属于非一致性备份

            关闭状态,可以分为一致性和非一致性

        非归档模式

            打开状态,非一致性备份无效

            关闭状态,一致性备份,非一致性备份不被推荐

    2.RMAN备份     

        RMAN使用服务器会话来完成备份操作,从RMAN客户端连接到服务器将产生一个服务器会话

        RMAN备份内容包括:整个数据库,表空间,数据文件,指定的数据文件,控制文件,归档日志文件,参数文件等

       3.RMAN备份的类型

        完整备份(full) 或增量备份(incremental)

        一致性备份(consistent)或不一致性备份(inconsistent)

        热备(open)或冷备(closed),冷备时数据库必须处于mount状态,冷备可以为一致性备份或非一致性备份

               

        完整备份

            一个或多个数据文件的一个完整副本,包含从备份开始处所有的数据块.完整备份不能作为增量的基础

           

        增量备份

            包含从最近一次备份以来被修改或添加的数据块.可以分为差异增量备份和累计增量备份

            差异增量备份仅仅包含n级或n级以下被修改过的数据块。备份数据量小,恢复时间长。

            累计增量备份仅仅包含n-1级或n-1级以下被修改过的数据块。备份数据量大,恢复时间短。

            0级增量备份相当于一个完整备份,该备份包含所有已用的数据块文件,与完整备份的差异是完整备份不能用作级增量备份的基础

                       

        一致性备份

            备份所包含的各个文件中的所有修改都具备相同的系统变化编号(system change numberSCN)

            也就是说,备份所包含的各个文件中的所有数据均来自同一时间点。

            一致性数据库完全备份(consis-tent whole database backup)进行还原(restore)后,不需要执行恢复操作(recovery)

       

        非一致性备份

            在数据库处于打开(open)状态时,或数据库异常关闭(shut down abnormally)后,对一个或多个数据

            库文件进行的备份。非一致性备份需要在还原之后进行恢复操作

   

    4.备份集与镜像副本

        备份集

            是包含一个或多个数据文件,归档日志文件的二进制文件的集合.备份集由备份片组成,一个备份集中可以包含一个或多个备份片

            可以通过filesperset参数来设置备份集中可包含的备份片数,

            也可以设定参数maxpiecesize来制定每个备份片的大小。

            备份集中空闲的数据块将不会被备份,因此备份集可以支持压缩。备份集支持增量备份,可以备份到磁盘或磁带。

           

        镜像副本

            是数据文件或归档日志文件等的完整拷贝,未经过任何压缩等处理,不能备份到磁带,也不支持增量备份

            恢复时可以立即使用实现快速恢复

            等同于操作系统的复制命令

            可以作为级增量备份

   

    5.备份路径

        可以备份到磁盘目录

        可以备份到磁带

        闪回区

   

    6.备份限制

        数据库必须处于mountopen状态

        不能备份联机日志

        在非归档模式下仅仅能作干净备份,即在干净关闭且启动到mount状态下备份

        在归档模式下,current状态下数据文件可以备份

       

     关于更多备份与恢复的概念请参考:Oracle 备份恢复概念

二、使用RMAN进行备份

 

    1.备份数据库

 

        RMAN> show all;

 

        RMAN configuration parameters are:

        CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default

        CONFIGURE BACKUP OPTIMIZATION OFF; # default

        CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default

        CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default

        CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default

        CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default

        CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default

        CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default

        CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT   '/u01/app/oracle/rmanbak/df_%d_%U';

        CONFIGURE MAXSETSIZE TO UNLIMITED; # default

        CONFIGURE ENCRYPTION FOR DATABASE OFF; # default

        CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default

        CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default

        CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/10g/dbs/snapcf_orcl.f'; # defaul       

 

        RMAN> backup database format '/u01/app/oracle/rmanbak/whole_%d_%U';  --备份整个数据库

 

        RMAN> backup as compressed backupset                       --备份整个数据库并压缩备份集

        2> database format '/u01/app/oracle/rmanbak/whole_%d_%U';

 

        RMAN> run{

        2> allocate channel ch1 type disk                          --手动分配一个通道

        3> maxpiecesize=2g;                                        --指定备份片的大小为2g

        4> backup as compressed backupset                          --压缩备份集

        5> format  '/u01/app/oracle/rmanbak/whole_%d_%U' filesperset=3--指定备份集中允许容纳的文件数为个

        6> database;

        7> release channel ch1;}                                   --释放通道

 

        RMAN> configure device type disk parallelism 3;   --将并行度改为

 

        old RMAN configuration parameters:

        CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET;

        new RMAN configuration parameters:

        CONFIGURE DEVICE TYPE DISK PARALLELISM 3 BACKUP TYPE TO BACKUPSET;

        new RMAN configuration parameters are successfully stored

 

        RMAN> backup as compressed backupset    --并行度改为之后,自动启用了个通道

        2> format '/u01/app/oracle/rmanbak/whole_%d_%U' filesperset=3

        3> database;

 

        Starting backup at 14-OCT-10

        allocated channel: ORA_DISK_1

        channel ORA_DISK_1: sid=148 devtype=DISK    --sid值对应v$session视图中的sid

        allocated channel: ORA_DISK_2

        channel ORA_DISK_2: sid=146 devtype=DISK

        allocated channel: ORA_DISK_3

        channel ORA_DISK_3: sid=144 devtype=DISK

 

        RMAN> run{

        2> allocate channel ch1 type disk

        3> maxpiecesize=100m;   --备份片大小设置为m,则一个备份集包含多个备份片,且每个备份片大小为100m

        4> backup

        5> format '/u01/app/oracle/rmanbak/whole_%d_%U'

        6> database;

        7> release channel ch1;}

 

        RMAN> list backupset tag=TAG20101014T171115;

 

        List of Backup Sets

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

 

        BS Key  Type LV Size       Device Type Elapsed Time Completion Time

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

        21      Full    690.30M    DISK        00:01:39     14-OCT-10

          List of Datafiles in backup set 21

          File LV Type Ckp SCN    Ckp Time   Name

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

          1       Full 1648791    14-OCT-10 /u01/app/oracle/oradata/orcl/system01.dbf

          2       Full 1648791    14-OCT-10 /u01/app/oracle/oradata/orcl/undotbs01.dbf

          3       Full 1648791    14-OCT-10 /u01/app/oracle/oradata/orcl/sysaux01.dbf

          4       Full 1648791    14-OCT-10 /u01/app/oracle/oradata/orcl/users01.dbf

          5       Full 1648791    14-OCT-10 /u01/app/oracle/oradata/orcl/example01.dbf

          6       Full 1648791    14-OCT-10 /u01/app/oracle/oradata/orcl/tbs1.dbf

 

          Backup Set Copy #1 of backup set 21

          Device Type Elapsed Time Completion Time Compressed Tag

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

          DISK        00:01:39     14-OCT-10      NO         TAG20101014T171115

 

            List of Backup Pieces for backup set 21 Copy #1

            BP Key  Pc# Status      Piece Name

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

            21      1   AVAILABLE   /u01/app/oracle/rmanbak/whole_ORCL_0nlqemtj_1_1

            22      2   AVAILABLE   /u01/app/oracle/rmanbak/whole_ORCL_0nlqemtj_2_1

            23      3   AVAILABLE   /u01/app/oracle/rmanbak/whole_ORCL_0nlqemtj_3_1

            24      4   AVAILABLE   /u01/app/oracle/rmanbak/whole_ORCL_0nlqemtj_4_1

            25      5   AVAILABLE   /u01/app/oracle/rmanbak/whole_ORCL_0nlqemtj_5_1

            26      6   AVAILABLE   /u01/app/oracle/rmanbak/whole_ORCL_0nlqemtj_6_1

            27      7   AVAILABLE   /u01/app/oracle/rmanbak/whole_ORCL_0nlqemtj_7_1

 

        BS Key  Type LV Size       Device Type Elapsed Time Completion Time

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

        22      Full    6.80M      DISK        00:00:01     14-OCT-10

                BP Key: 28   Status: AVAILABLE  Compressed: NO  Tag: TAG20101014T171115

                Piece Name: /u01/app/oracle/rmanbak/whole_ORCL_0olqen0s_1_1

          Control File Included: Ckp SCN: 1648817      Ckp time: 14-OCT-10

          SPFILE Included: Modification time: 14-OCT-10

 

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

2.备份数据文件

        Oracle数据文件及表空间的管理请参考:Oracle 表空间与数据文件

        RMAN> backup as copy datafile 4                                             --备份类型为镜像备份

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

 

        RMAN> list copy; 

 

        RMAN> backup datafile 4,5,6 format '/u01/app/oracle/rmanbak/df_%d_%U';      --备份类型为备份集

 

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

3.备份表空间

        Oracle数据文件及表空间的管理请参考:Oracle 表空间与数据文件

 

        RMAN>  backup tablespace users,example format '/u01/app/oracle/rmanbak/tb_%d_%U';

 

        RMAN> backup tablespace temp;  --临时表空间不需要备份

 

        Starting backup at 14-OCT-10

        using channel ORA_DISK_1

        using channel ORA_DISK_2

        RMAN-00571: ===========================================================

        RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============

        RMAN-00571: ===========================================================

        RMAN-03002: failure of backup command at 10/14/2010 18:56:12

        RMAN-20202: tablespace not found in the recovery catalog

        RMAN-06019: could not translate tablespace name "TEMP"

 

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

 4.备份控制文件

        Oracle 控制文件的详细介绍请参考:Oracle 控制文件(CONTROLFILE)

 

        RMAN> configure controlfile autobackup on;--自动备份控制文件置为on状态,将自动备份控制文件和参数文件

 

        old RMAN configuration parameters:

        CONFIGURE CONTROLFILE AUTOBACKUP OFF;

        new RMAN configuration parameters:

        CONFIGURE CONTROLFILE AUTOBACKUP ON;

        new RMAN configuration parameters are successfully stored

 

        注:在备份system01.dbfsystem表空间时将会自动备份控制文件和参数文件,即使自动备份控制文件参数为off

 

        --单独备份控制文件及参数文件

        RMAN> backup current controlfile;

 

        --备份数据文件时包含控制文件

        RMAN> backup datafile 4 include current controlfile;

 

        RMAN> sql "alter database backup controlfile to ''/tmp/orclcontrol.bak''";

 

        sql statement: alter database backup controlfile to ''/tmp/orclcontrol.bak''

 

        RMAN>  sql "alter database backup controlfile to trace as ''/tmp/orclcontrol.sql''";

 

        sql statement: alter database backup controlfile to trace as ''/tmp/orclcontrol.sql''

 

        --单独备份spfile

        RMAN> backup spfile format '/u01/app/oracle/rmanbak/sp_%d_%U';

 

        RMAN> backup copies 2 device type disk spfile;

 

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

    5.备份归档日志文件

        备份归档日志时仅仅备份归档过的数据文件(不备份联机重做日志文件)

        备份归档日志时总是对归档日志做完整备份

        RMAN对归档日志备份前会自动做一次日志切换,且从一组归档日志中备份未损坏的归档日志

        RMAN会自动判断哪些归档日志需要进行备份

        归档日志的备份集不能包含其它类型的文件

 

        关于Oracle日志文件请参考:Oracle 联机重做日志文件(ONLINE LOG FILE)

        关于Oracle归档日志请参考:Oracle 归档日志

 

        RMAN> backup

        2> format '/u01/app/oracle/rmanbak/lf_%d_%U'

        3> archivelog all delete input;   --delete input 删除所有已经备份过的归档日志

 

        RMAN> backup            --此种写法实现了上述相同的功能

        2> archivelog all delete input

        3> format '/u01/app/oracle/rmanbak/lf_%d_%U';

 

        RMAN>  backup archivelog sequence between 50 and 120 thread delete input;

 

        RMAN> backup archivelog from time "sysdate-15" until time "sysdate-7";

       

        RMAN> backup

        2> format '/u01/app/oracle/rmanbak/lf_%d_%U'

        3> archivelog from sequence=80

        4> delete input;

 

        使用plus archivelog时备份数据库完成的动作(backup database plus archivelog)

            1.首先执行alter system archive log current 命令(对当前日志归档)

            2.执行backup archivelog all 命令(对所有归档日志进行备份)

            3.执行backup database命令中指定的数据文件、表空间等

            4.再次执行alter system archive log current

            5.备份在备份操作期间产生的新的归档日志

 

        --执行下面的命令,并观察备份列出的信息,可以看到使用plus archivelog时使用了上面描述的步骤来进行备份

        RMAN> backup database plus archivelog

        2> format  '/u01/app/oracle/rmanbak/lg_%d_%U' delete input;

 

    6.备份闪回区

       

        RMAN> backup recovery area;

            使用backup recovery area时,将备份位于闪回区且未进行过备份的所有文件,这些文件包括完整、增量备份集、自动备份的

            控制文件(假定使用闪回区作为备份路径时)、归档日志、数据文件的镜像副本等。闪回日志,当前的控制文件。

            联机重做日志不会被备份

       

        RMAN> backup recovery files;

            使用backup recovery files时,将备份磁盘上未进行过备份的所有恢复文件,而不论是否位于闪回区

           

        注:使用上述两条命令时,备份目的地必须是磁带

       

    7.总结:

        数据文件的备份集对于未使用的块可以执行增量备份,可以跳过未使用过的数据块来进行压缩备份

        对于控制文件、归档日志文件、spfile文件则是简单的拷贝,并对其进行打包压缩而已

 

三、备份的其它特性

    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 命令中使用更好的定位备份文件

            能够在restoreswitch命令中使用

            同一个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 '

 

        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;

           

四、备份相关的动态性能视图及监控

    1.相关视图

        v$backup_files

        v$backup_set

        v$backup_piece

        v$backup_redolog

        v$backup_spfile

        v$backup_device

        v$rman_configuration

        v$archived_log

        v$backup_corruption

        v$copy_corruption

        v$database_block_corruption

        v$backup_datafile

       

    2.查看channel对应的server sessions

            使用set command id命令

        查询v$processv$session判断哪一个会话与之对应的RMAN通道

        SQL> select sid,username,client_info from v$session

          2  where client_info is not null;

 

               SID USERNAME                       CLIENT_INFO

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

               146 SYS                            rman channel=ORA_DISK_1

               148 SYS                            rman channel=ORA_DISK_2

               150 SYS                            rman channel=ORA_DISK_3

           

        --下面使用了set command id命令

        RMAN> run{

        2> allocate channel ch1 type disk;

        3> set command id to 'rman';

        4> backup as copy datafile 4

        5> format '/u01/app/oracle/rmanbak/dd_%U';

        6> }

           

        SQL> select sid,username,client_info from v$session

          2   where client_info is not null;

 

               SID USERNAME                       CLIENT_INFO

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

               140 SYS                            id=rman

          

        SQL> select sid,spid,client_info

          2  from v$process p ,v$session s

          3  where p.addr = s.paddr

          4  and client_info like '%id=%';

 

               SID SPID         CLIENT_INFO

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

               140 5002         id=rman 

          

        --查看rman完整的进度      

        SQL> select sid,serial#,context,sofar,totalwork,

          2  round(sofar/totalwork*100,2) "% Complete"

          3  from v$session_longops

          4   where opname like 'RMAN:%'

          5  and opname not like 'RMAN:aggregate%'

           and totalwork!=0;    

 

        --通过如下SQL获得rman用来完成备份操作的服务进程的SIDSPID信息:

        select sid, spid, client_info

          from v$process p, v$session s

         where p.addr = s.paddr

           and client_info like '%id=rman%'

     

    3.Linux下的rman自动备份

        备份脚本+crontab

        bak_inc0 :0级增量备份,每周日使用级增量进行备份

        bak_inc1 :1级增量备份,每周三使用级增量备份,备份从周日以来到周三所发生的数据变化

        bak_inc2 :2级增量备份,备份每天发生的差异增量。如从周日到周一的差异,从周一到周二的差异

       

        --下面是级增量的脚本,其余级与级依法炮制,所不同的是备份级别以及tag标记

        [oracle@oradb scripts]$ cat bak_inc0

        run {

        allocate channel ch1 type disk;

        backup as compressed backupset  incremental level 0

        format '/u01/oracle/bk/rmbk/incr0_%d_%U'

        tag 'day_incr0'

        database plus archivelog delete input;

        release channel ch1;

        }

               

        逐个测试脚本

        [oracle@oradb bk]$ rman target / log=/u01/oracle/bk/log/bak_inc0.log /

        > cmdfile=/u01/oracle/bk/scripts/bak_inc0.rcv

        RMAN> 2> 3> 4> 5> 6> 7> 8> 9>

        [oracle@oradb bk]$

 

        编辑crontab

        [root@oradb ~]# whoami

        root

        [root@oradb ~]# crontab --u oracle

 

        45 23 * * 0 rman target / log=/u01/oracle/bk/log/bak_inc0.log append cmdfile = /u01/oracle/bk/scripts/bak_inc0.rcv

        45 23 * * 1 rman target / log=/u01/oracle/bk/log/bak_inc2.log append cmdfile = /u01/oracle/bk/scripts/bak_inc2.rcv

        45 23 * * 2 rman target / log=/u01/oracle/bk/log/bak_inc2.log append cmdfile = /u01/oracle/bk/scripts/bak_inc2.rcv

        45 23 * * 3 rman target / log=/u01/oracle/bk/log/bak_inc1.log append cmdfile = /u01/oracle/bk/scripts/bak_inc1.rcv

        45 23 * * 4 rman target / log=/u01/oracle/bk/log/bak_inc2.log append cmdfile = /u01/oracle/bk/scripts/bak_inc2.rcv

        45 23 * * 5 rman target / log=/u01/oracle/bk/log/bak_inc2.log append cmdfile = /u01/oracle/bk/scripts/bak_inc2.rcv

        45 23 * * 6 rman target / log=/u01/oracle/bk/log/bak_inc2.log append cmdfile = /u01/oracle/bk/scripts/bak_inc2.rcv

        "/tmp/crontab.XXXXInBzgR" 7L, 791C written

        crontab: installing new crontab

        保存之后重启crontab

        [root@oradb ~]# service crond restart

        Stopping crond: [  OK  ]

        Starting crond: [  OK  ]

       

        检查自动备份是否成功执行

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29012354/viewspace-765156/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/29012354/viewspace-765156/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值