使用RMAN備份與恢復數據庫(7)——管理備份集

使用RMAN備份與恢復數據庫(7)——管理備份集

通過RMAN有兩種不同類型的備份方式:使用鏡像備份和使用備份集備份。

鏡像備份(Image Copies):鏡像複製其實就是創建數據文件、控制文件或歸檔文件的副本,與用戶通過操作系統命令創建的備份一樣,RMAN利用目標數據庫中的服務進程來完成文件複製。

備份集(Backup Sets):爲RMAN默認的備份選項。備份集是RMAN創建的具有特定格式的邏輯備份對象,備份集在邏輯上由一個或多個備份片段(Backup Piece)組成,每個備份片段在物理上對應一個操作系統文件,一個備份片段中可能包含多個數據文件、控制文件或歸檔文件。使用備份集備份時只讀取數據庫中已經使用的數據塊,因此備份文件的體積更小。

一、查看和修改RMAN的備份方式

1、查看RMAN的備份方式

RMAN> show all;

RMAN configuration parameters for database with db_unique_name ORCL 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   '/home/oracle/rmanbak/%u';
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/usr/local/oracle/product/11.2.0/db_1/dbs/snapcf_orcl.f'; # default

2、修改RMAN的備份方式

RMAN> CONFIGURE DEVICE TYPE DISK PARALLELISM 2 BACKUP TYPE TO COPY; 

new RMAN configuration parameters:
CONFIGURE DEVICE TYPE DISK PARALLELISM 2 BACKUP TYPE TO COPY;
new RMAN configuration parameters are successfully stored
released channel: ORA_DISK_1

RMAN> show all;

RMAN configuration parameters for database with db_unique_name ORCL 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 2 BACKUP TYPE TO COPY;
--#################################################################################
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   '/home/oracle/rmanbak/%u';
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/usr/local/oracle/product/11.2.0/db_1/dbs/snapcf_orcl.f'; # default

3、把備份方式重新修改爲備份集

RMAN> CONFIGURE DEVICE TYPE DISK PARALLELISM 2 BACKUP TYPE TO BACKUPSET; 

old RMAN configuration parameters:
CONFIGURE DEVICE TYPE DISK PARALLELISM 2 BACKUP TYPE TO COPY;
new RMAN configuration parameters:
CONFIGURE DEVICE TYPE DISK PARALLELISM 2 BACKUP TYPE TO BACKUPSET;
new RMAN configuration parameters are successfully stored

RMAN> show all;

RMAN configuration parameters for database with db_unique_name ORCL 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
--#################################################################################
--備份方式修改爲備份集備份
--PARALLELISM參數爲並行數
CONFIGURE DEVICE TYPE DISK PARALLELISM 2 BACKUP TYPE TO BACKUPSET;
--#################################################################################
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   '/home/oracle/rmanbak/%u';
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/usr/local/oracle/product/11.2.0/db_1/dbs/snapcf_orcl.f'; # default

在備份集備份方式下也可以使用鏡像備份,只需要使用backup as copy命令即可。

二、查看備份集

1、查看參數文件備份集

RMAN> list backup of spfile;


List of Backup Sets
===================


BS Key  Type LV Size       Device Type Elapsed Time Completion Time    
------- ---- -- ---------- ----------- ------------ -------------------
59      Full    80.00K     DISK        00:00:00     2020-04-10 06:13:03
        BP Key: 91   Status: AVAILABLE  Compressed: NO  Tag: TAG20200410T061303
        Piece Name: /home/oracle/rmanbak/spfileorcl.old
  SPFILE Included: Modification time: 2020-04-10 05:34:50
  SPFILE db_unique_name: ORCL

2、查看控制文件備份集

RMAN> list backup of controlfile;


List of Backup Sets
===================


BS Key  Type LV Size       Device Type Elapsed Time Completion Time    
------- ---- -- ---------- ----------- ------------ -------------------
60      Full    9.83M      DISK        00:00:02     2020-04-10 06:13:38
        BP Key: 92   Status: AVAILABLE  Compressed: NO  Tag: TAG20200410T061336
        Piece Name: /home/oracle/rmanbak/control01.old
  Control File Included: Ckp SCN: 1766092      Ckp time: 2020-04-10 06:13:36

3、查看數據文件備份集

RMAN> list backup of datafile 5;


List of Backup Sets
===================


BS Key  Type LV Size       Device Type Elapsed Time Completion Time    
------- ---- -- ---------- ----------- ------------ -------------------
57      Full    18.42M     DISK        00:00:00     2020-04-09 20:28:34
        BP Key: 89   Status: AVAILABLE  Compressed: NO  Tag: TAG20200409T202834
        Piece Name: /home/oracle/rmanbak/data01.dbf
  List of Datafiles in backup set 57
  File LV Type Ckp SCN    Ckp Time            Name
  ---- -- ---- ---------- ------------------- ----
  5       Full 1741852    2020-04-09 20:28:34 /usr/local/oradata/orcl/data01.dbf

4、查看錶空間備份集

說明:表空間和數據文件備份結果相同。

RMAN> list backup of tablespace data01;


List of Backup Sets
===================


BS Key  Type LV Size       Device Type Elapsed Time Completion Time    
------- ---- -- ---------- ----------- ------------ -------------------
57      Full    18.42M     DISK        00:00:00     2020-04-09 20:28:34
        BP Key: 89   Status: AVAILABLE  Compressed: NO  Tag: TAG20200409T202834
        Piece Name: /home/oracle/rmanbak/data01.dbf
  List of Datafiles in backup set 57
  File LV Type Ckp SCN    Ckp Time            Name
  ---- -- ---- ---------- ------------------- ----
  5       Full 1741852    2020-04-09 20:28:34 /usr/local/oradata/orcl/data01.dbf

5、查看歸檔日誌備份集

RMAN> list backup of archivelog all;


List of Backup Sets
===================


BS Key  Size       Device Type Elapsed Time Completion Time    
------- ---------- ----------- ------------ -------------------
58      14.20M     DISK        00:00:02     2020-04-09 20:32:06
        BP Key: 90   Status: AVAILABLE  Compressed: YES  Tag: TAG20200409T203204
        Piece Name: /home/oracle/rmanbak/archivelog_ORCL_1559168802_81_1_20200409

  List of Archived Logs in backup set 58
  Thrd Seq     Low SCN    Low Time            Next SCN   Next Time
  ---- ------- ---------- ------------------- ---------- ---------
  1    9       1741038    2020-04-09 20:20:23 1741173    2020-04-09 20:21:58
  1    10      1741173    2020-04-09 20:21:58 1741284    2020-04-09 20:22:27
  1    11      1741284    2020-04-09 20:22:27 1741391    2020-04-09 20:22:58
  1    12      1741391    2020-04-09 20:22:58 1741661    2020-04-09 20:23:41
  1    13      1741661    2020-04-09 20:23:41 1742829    2020-04-09 20:30:10
  1    14      1742829    2020-04-09 20:30:10 1743756    2020-04-09 20:30:52
  1    15      1743756    2020-04-09 20:30:52 1743788    2020-04-09 20:32:04

6、查看所有的備份集

RMAN> list backup;


List of Backup Sets
===================


BS Key  Type LV Size       Device Type Elapsed Time Completion Time    
------- ---- -- ---------- ----------- ------------ -------------------
57      Full    18.42M     DISK        00:00:00     2020-04-09 20:28:34
        BP Key: 89   Status: AVAILABLE  Compressed: NO  Tag: TAG20200409T202834
        Piece Name: /home/oracle/rmanbak/data01.dbf
  List of Datafiles in backup set 57
  File LV Type Ckp SCN    Ckp Time            Name
  ---- -- ---- ---------- ------------------- ----
  5       Full 1741852    2020-04-09 20:28:34 /usr/local/oradata/orcl/data01.dbf

BS Key  Size       Device Type Elapsed Time Completion Time    
------- ---------- ----------- ------------ -------------------
58      14.20M     DISK        00:00:02     2020-04-09 20:32:06
        BP Key: 90   Status: AVAILABLE  Compressed: YES  Tag: TAG20200409T203204
        Piece Name: /home/oracle/rmanbak/archivelog_ORCL_1559168802_81_1_20200409

  List of Archived Logs in backup set 58
  Thrd Seq     Low SCN    Low Time            Next SCN   Next Time
  ---- ------- ---------- ------------------- ---------- ---------
  1    9       1741038    2020-04-09 20:20:23 1741173    2020-04-09 20:21:58
  1    10      1741173    2020-04-09 20:21:58 1741284    2020-04-09 20:22:27
  1    11      1741284    2020-04-09 20:22:27 1741391    2020-04-09 20:22:58
  1    12      1741391    2020-04-09 20:22:58 1741661    2020-04-09 20:23:41
  1    13      1741661    2020-04-09 20:23:41 1742829    2020-04-09 20:30:10
  1    14      1742829    2020-04-09 20:30:10 1743756    2020-04-09 20:30:52
  1    15      1743756    2020-04-09 20:30:52 1743788    2020-04-09 20:32:04

BS Key  Type LV Size       Device Type Elapsed Time Completion Time    
------- ---- -- ---------- ----------- ------------ -------------------
59      Full    80.00K     DISK        00:00:00     2020-04-10 06:13:03
        BP Key: 91   Status: AVAILABLE  Compressed: NO  Tag: TAG20200410T061303
        Piece Name: /home/oracle/rmanbak/spfileorcl.old
  SPFILE Included: Modification time: 2020-04-10 05:34:50
  SPFILE db_unique_name: ORCL

BS Key  Type LV Size       Device Type Elapsed Time Completion Time    
------- ---- -- ---------- ----------- ------------ -------------------
60      Full    9.83M      DISK        00:00:02     2020-04-10 06:13:38
        BP Key: 92   Status: AVAILABLE  Compressed: NO  Tag: TAG20200410T061336
        Piece Name: /home/oracle/rmanbak/control01.old
  Control File Included: Ckp SCN: 1766092      Ckp time: 2020-04-10 06:13:36

三、使用crosscheck命令覈對備份集

crosscheck命令用於覈對磁盤和磁帶上的備份文件,以確保RMAN資料庫與備份文件保持同步。當執行crosscheck命令時,如果資料庫記錄不匹配於備份文件的物理狀態,那麼該命令會更新資料庫記錄的狀態信息。備份文件的狀態包括:AVALIABLE(可用的)、UNAVALIABLE(不可用的)、EXPIRED(失效的)。crosscheck命令的格式如下:

1)crosscheck backup;   --覈對所有備份集2)crosscheck backup of database;   --覈對所有數據文件的備份集3)crosscheck backup of tablespace data01;   --覈對特定表空間的備份集4)crosscheck backup of datafile 4;   --覈對特定數據文件的備份集5)crosscheck backup of controlfile;   --覈對控制文件的備份集6)crosscheck backup of spfile;   --覈對SPFILE的備份集7)crosscheck backup of archivelog sequence 3;   --覈對歸檔日誌的備份集8)crosscheck copy;   --覈對所有鏡像副本9)crosscheck copy of database;   --覈對所有數據文件的鏡像副本10)crosscheck copy of tablespace users;   --覈對特定表空間的鏡像副本11)crosscheck copy of datafile 6;   --覈對特定數據文件的鏡像副本12)crosscheck copy of archivelog sequence 4;   --覈對歸檔日誌的鏡像副本13)crosscheck copy of controlfile;  --覈對控制文件的鏡像副本

舉例:

--控制文件的備份被刪除,檢查之後該備份集的狀態變成expired(失效)
RMAN> crosscheck backup of controlfile;

using channel ORA_DISK_1
using channel ORA_DISK_2
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/home/oracle/rmanbak/control01.old RECID=92 STAMP=1037340817
Crosschecked 1 objects

RMAN> list backup of controlfile;

List of Backup Sets
===================

BS Key  Type LV Size       Device Type Elapsed Time Completion Time    
------- ---- -- ---------- ----------- ------------ -------------------
60      Full    9.83M      DISK        00:00:02     2020-04-10 06:13:38
        BP Key: 92   Status: EXPIRED  Compressed: NO  Tag: TAG20200410T061336
        Piece Name: /home/oracle/rmanbak/control01.old
  Control File Included: Ckp SCN: 1766092      Ckp time: 2020-04-10 06:13:36

四、刪除備份集

刪除備份集之前通常先使用crosscheck命令進行檢查。刪除備份集的命令如下:

1、刪除過期備份

當使用RMAN命令執行備份操作時,RMAN會根據備份冗餘策略確定備份是否過期。

RMAN> crosscheck backup;

using channel ORA_DISK_1
using channel ORA_DISK_2
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/home/oracle/rmanbak/data01.dbf RECID=89 STAMP=1037305714
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/home/oracle/rmanbak/archivelog_ORCL_1559168802_81_1_20200409 RECID=90 STAMP=1037305924
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/home/oracle/rmanbak/spfileorcl.old RECID=91 STAMP=1037340783
Crosschecked 3 objects

crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/home/oracle/rmanbak/control01.old RECID=92 STAMP=1037340817
Crosschecked 1 objects


RMAN> delete obsolete;

RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 1
using channel ORA_DISK_1
using channel ORA_DISK_2
Deleting the following obsolete backups and copies:
Type                 Key    Completion Time    Filename/Handle
-------------------- ------ ------------------ --------------------
Backup Set           60     2020-04-10 06:13:38
  Backup Piece       92     2020-04-10 06:13:38 /home/oracle/rmanbak/control01.old

Do you really want to delete the above objects (enter YES or NO)? yes
deleted backup piece
backup piece handle=/home/oracle/rmanbak/control01.old RECID=92 STAMP=1037340817
Deleted 1 objects

2、刪除無效備份

首先執行CROSSCHECK命令覈對備份集,如果發現備份無效(比如備份對應的數據文件損壞或丟失),RMAN會將該備份集標記爲 EXPIRED狀態。

說明:noprompt參數表示刪除時不提示yes或no。

RMAN> delete noprompt expired backup;

using channel ORA_DISK_1
using channel ORA_DISK_2
specification does not match any backup in the repository

3、刪除EXPIRED鏡像副本

delete expired copy;

4、刪除特定備份集

 RMAN> delete noprompt backupset 57;

using channel ORA_DISK_1
using channel ORA_DISK_2

List of Backup Pieces
BP Key  BS Key  Pc# Cp# Status      Device Type Piece Name
------- ------- --- --- ----------- ----------- ----------
89      57      1   1   AVAILABLE   DISK        /home/oracle/rmanbak/data01.dbf
deleted backup piece
backup piece handle=/home/oracle/rmanbak/data01.dbf RECID=89 STAMP=1037305714
Deleted 1 objects

5、刪除特定備份片

RMAN> delete noprompt backuppiece '/home/oracle/rmanbak/archivelog_ORCL_1559168802_81_1_20200409';

using channel ORA_DISK_1
using channel ORA_DISK_2

List of Backup Pieces
BP Key  BS Key  Pc# Cp# Status      Device Type Piece Name
------- ------- --- --- ----------- ----------- ----------
90      58      1   1   AVAILABLE   DISK        /home/oracle/rmanbak/archivelog_ORCL_1559168802_81_1_20200409
deleted backup piece
backup piece handle=/home/oracle/rmanbak/archivelog_ORCL_1559168802_81_1_20200409 RECID=90 STAMP=1037305924
Deleted 1 objects

6、刪除所有備份集

delete noprompt backup;

7、刪除所有鏡像副本

delete noprompt copy;

8、刪除特定鏡像副本

delete datafile copy '/home/oracle/rmanbak/data01.dbf';
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章