RMAN筆記之備份集和備份片

花花蘑菇發表於2016-11-04
RMAN的backup命令是可以產生兩種型別的備份:備份集和映象複製。
具體產生哪種型別的備份,取決於backup命令,如果是backup as backupset,則生成備份集;如果是backup as copy,則生成映象複製。
RMAN> show device type;      //檢視預設裝置設定
using target database control file instead of recovery catalog
RMAN configuration parameters for database with db_unique_name STEST are:
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default   預設設定是備份生成備份集。
RMAN> configure device type disk backup type to copy;   //設定備份生成映象複製
=====================================================================================
備份集(backup set):
備份集就是輸入檔案的備份,它是一個邏輯概念,物理上由備份片(backup piece)組成。一個備份集可以包含多個輸入檔案,一個輸入檔案可以分散在多個備份片上。例子如下:
RMAN> list backupset;
List of Backup Sets
===================
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
1       Full    1005.80M   DISK        00:00:04     23-OCT-14      
        BP Key: 1   Status: AVAILABLE  Compressed: NO  Tag: TAG20141023T111812
        Piece Name: /oracle/app/oracle/fast_recovery_area/ZLB/backupset/2014_10_23/o1_mf_nnndf_TAG20141023T111812_b4jwvo17_.bkp
  List of Datafiles in backup set 1
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 1094205    23-OCT-14 /oracle/app/oracle/oradata/zlb/system01.dbf
  2       Full 1094205    23-OCT-14 /oracle/app/oracle/oradata/zlb/sysaux01.dbf
  3       Full 1094205    23-OCT-14 /oracle/app/oracle/oradata/zlb/undotbs01.dbf
  4       Full 1094205    23-OCT-14 /oracle/app/oracle/oradata/zlb/users01.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
2       Full    9.36M      DISK        00:00:01     23-OCT-14      
        BP Key: 2   Status: AVAILABLE  Compressed: NO  Tag: TAG20141023T111812
        Piece Name: /oracle/app/oracle/fast_recovery_area/ZLB/backupset/2014_10_23/o1_mf_ncsnf_TAG20141023T111812_b4jwvx3s_.bkp
  SPFILE Included: Modification time: 22-OCT-14
  SPFILE db_unique_name: ZLB
  Control File Included: Ckp SCN: 1094209      Ckp time: 23-OCT-14

BS Key Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
3       Full    1.01G      DISK        00:00:10     23-OCT-14      
  List of Datafiles in backup set 3
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 1122962    23-OCT-14 /oracle/app/oracle/oradata/zlb/system01.dbf
  2       Full 1122962    23-OCT-14 /oracle/app/oracle/oradata/zlb/sysaux01.dbf
  3       Full 1122962    23-OCT-14 /oracle/app/oracle/oradata/zlb/undotbs01.dbf
  4       Full 1122962    23-OCT-14 /oracle/app/oracle/oradata/zlb/users01.dbf

  Backup Set Copy #1 of backup set 3
  Device Type Elapsed Time Completion Time Compressed Tag
  ----------- ------------ --------------- ---------- ---
  DISK        00:00:10     23-OCT-14       NO         TAG20141023T225841

    List of Backup Pieces for backup set 3 Copy #1
    BP Key  Pc# Status      Piece Name
    ------- --- ----------- ----------
    3       1   AVAILABLE   /oracle/app/oracle/fast_recovery_area/ZLB/backupset/2014_10_23/o1_mf_nnndf_TAG20141023T225841_b4l5x1ph_.bkp
    4       2   AVAILABLE   /oracle/app/oracle/fast_recovery_area/ZLB/backupset/2014_10_23/o1_mf_nnndf_TAG20141023T225841_b4l5x8pw_.bkp
    5       3   AVAILABLE   /oracle/app/oracle/fast_recovery_area/ZLB/backupset/2014_10_23/o1_mf_nnndf_TAG20141023T225841_b4l5xcq0_.bkp

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
4       Full    9.36M      DISK        00:00:01     23-OCT-14      
        BP Key: 6   Status: AVAILABLE  Compressed: NO  Tag: TAG20141023T225841
        Piece Name: /oracle/app/oracle/fast_recovery_area/ZLB/backupset/2014_10_23/o1_mf_ncsnf_TAG20141023T225841_b4l5xftm_.bkp
  SPFILE Included: Modification time: 23-OCT-14
  SPFILE db_unique_name: ZLB
  Control File Included: Ckp SCN: 1122966      Ckp time: 23-OCT-14
=================================================================================================================
backup命令生成的備份集的數量由以下幾個因素決定:
1、輸入檔案的數量:
    一個備份集預設情況下最多可以容納64個輸入檔案。這個預設值可以由filesperset子句來修改:
    backup as backupset tablespace users filesperset 1;    //定義一個備份集只能有一個輸入檔案
2、並行度:
    備份集的數量不會低於backuo並行度的數量。
(並行度:和通道數有關,一般情況下,有幾個通道就可以認為並行度是幾。但是,也有例外情況,如:
   RMAN>  configure device type disk parallelism 2;   //設定預設並行度為2,備份的時候,rman會自動分配兩個通道。但是這兩個通道只有在輸入檔案有兩個或者兩個以上時,才有意義。否則,只有一個通道會工作,此時,並行度可以認為是1。
   可以為每一個通道設定備份路徑,如:
   RMAN>  configure channel 1 device type disk to destination '/home/oracle/disk1/';
    RMAN>  configure channel 2 device type disk to destination '/home/oracle/disk2/';

   如果配置的通道數目少於parallelism定義的並行度,則少的通道的備份路徑會由快速恢復區或者$ORACLE_HOME/dbs目錄代替。

3、輸入檔案的種類:
    有些檔案是不能再同一個備份集中的。資料檔案、歸檔日誌是單獨佔用備份集,控制檔案和引數檔案可以共用備份集。
    這是因為組成這些檔案的最小單位block_size不一致:
    SQL> select distinct  BLOCK_SIZE from v$datafile;
            BLOCK_SIZE
            -----------------
                  8192

    SQL> select distinct  BLOCK_SIZE from v$controlfile; 
            BLOCK_SIZE
            ----------------
                 16384

    SQL> select distinct  BLOCK_SIZE from  v$archived_log; 
            BLOCK_SIZE
            -----------------
                   512
另外:只要備份1號資料檔案(即system表空間),rman就會自發備份控制檔案和引數檔案,如:
RMAN> backup as backupset datafile 1;
Starting backup at 05-NOV-16
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=+DATA1/stest/datafile/system.256.926893851
channel ORA_DISK_1: starting piece 1 at 05-NOV-16
channel ORA_DISK_1: finished piece 1 at 05-NOV-16
piece handle=/opt/test/channel_0qrk3vo1_1_1 tag=TAG20161105T000001 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:58
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set   
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 05-NOV-16
channel ORA_DISK_1: finished piece 1 at 05-NOV-16
piece handle=/opt/test/channel_0rrk3vps_1_1 tag=TAG20161105T000001 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 05-NOV-16
4、小括號的使用
    小括號起到隔離的作用,不在同一個小括號內的輸入檔案一定不會再同一個備份集中,但是在一個小括號內的輸入檔案不一定會在一個備份集中。
例子:
RMAN> run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
backup (datafile 4) (datafile 5);
}     //生成兩個備份集

RMAN> run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
backup (datafile 4,5) (datafile 6);
}      //生產三個備份集,因為通道有三個,並行度為3

RMAN> run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
backup (datafile 4,5 channel c1) (datafile 6 channel c2);
}      //生成兩個備份集,因為指定了通道
5、“plus archivelog”子句
   如果備份時使用了該子句,rman會切換當前線上日誌,歸檔該日誌,然後備份剛剛產生的歸檔日誌。因此,會多一個額外的只有一個歸檔日誌的備份集。

最後:
 在備份時,一個通道中,RMAN同時讀取多個輸入檔案的資料並將其寫入到同一個備份片中的操作被稱為多路傳輸。同時被讀取的輸入檔案的數量稱之為多路傳輸等級。該等級等於以下三個數中的最小值:
(1)通道的maxopenfiles,如 RMAN> allocate channel c1 device type disk maxopenfiles 2;
(2)通道的輸入檔案數量
(3)backup命令中的filesperset的值,如果沒有定義filesperset,則取預設值64

總結:一個通道時:備份集產生個數的多少,可以用輸入檔案的個數除以多路傳輸等級來計算。多路傳輸等級的確定上面已經介紹了。
    一個以上的通道時,考慮上文中的第二點並行度。
  然後,無論一個通道還是一個以上通道,需要考慮上文中的第三點、第四點、第五點,基本上就可以知道會生成多少個備份集了。


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28497416/viewspace-2127829/,如需轉載,請註明出處,否則將追究法律責任。

相關文章