RMAN的crosscheck和obsolete的用法

辛勤的小胖發表於2014-03-10
我一直對rman的crosschcek和obsolete的用法理解的不清楚,而且有點混亂,這樣對rman的備份集甚至備份的管理造成很大的影響,今天還是及時測試一下,及時彌補這個重要環節
RMAN> show all;

RMAN configuration parameters for database with db_unique_name XUPENG 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 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 '/u01/app/oracle/product/11.2.0.3/db_1/dbs/snapcf_xupeng.f'; # default
---預設策略就保留一份

---當前資料庫無備份集備份
RMAN> list backup summary;

specification does not match any backup in the repository 

做一次全備!
RMAN> backup database format '/u01/backup/ora_full_%U';

Starting backup at 10-MAR-14
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=38 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00004 name=/u01/app/oracle/oradata/XUPENG/users01.dbf
input datafile file number=00001 name=/u01/app/oracle/oradata/XUPENG/system01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/XUPENG/sysaux01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/XUPENG/undotbs01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/XUPENG/tools.dbf
input datafile file number=00006 name=/u01/app/oracle/oradata/XUPENG/test.dbf
input datafile file number=00008 name=/u01/app/oracle/oradata/XUPENG/xupeng.dbf
channel ORA_DISK_1: starting piece 1 at 10-MAR-14
channel ORA_DISK_1: finished piece 1 at 10-MAR-14
piece handle=/u01/backup/ora_full_01p2qnrf_1_1 tag=TAG20140310T105231 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00007 name=/u01/app/oracle/oradata/XUPENG/fuck.dbf
channel ORA_DISK_1: starting piece 1 at 10-MAR-14
channel ORA_DISK_1: finished piece 1 at 10-MAR-14
piece handle=/u01/backup/ora_full_02p2qnrm_1_1 tag=TAG20140310T105231 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
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 10-MAR-14
channel ORA_DISK_1: finished piece 1 at 10-MAR-14
piece handle=/u01/backup/ora_full_03p2qnrn_1_1 tag=TAG20140310T105231 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 10-MAR-14

--備份資料檔案system
RMAN> backup datafile 1 format '/u01/backup/ora_system_%U';

Starting backup at 10-MAR-14
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=/u01/app/oracle/oradata/XUPENG/system01.dbf
channel ORA_DISK_1: starting piece 1 at 10-MAR-14
channel ORA_DISK_1: finished piece 1 at 10-MAR-14
piece handle=/u01/backup/ora_system_04p2qnuc_1_1 tag=TAG20140310T105404 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
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 10-MAR-14
channel ORA_DISK_1: finished piece 1 at 10-MAR-14
piece handle=/u01/backup/ora_system_05p2qnuf_1_1 tag=TAG20140310T105404 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 10-MAR-14
----所有的備份都會包括控制檔案和spfile

---檢視所有備份集
RMAN> list backup summary;

List of Backups
===============
Key     TY LV S Device Type Completion Time #Pieces #Copies Compressed Tag
------- -- -- - ----------- --------------- ------- ------- ---------- ---
1       B  F  A DISK        10-MAR-14       1       1       NO         TAG20140310T105231
2       B  F  A DISK        10-MAR-14       1       1       NO         TAG20140310T105231
3       B  F  A DISK        10-MAR-14       1       1       NO         TAG20140310T105231
4       B  F  A DISK        10-MAR-14       1       1       NO         TAG20140310T105404
5       B  F  A DISK        10-MAR-14       1       1       NO         TAG20140310T105404

---這裡用corsscheck 檢查備份的可用性
RMAN> crosscheck backup;

using channel ORA_DISK_1
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u01/backup/ora_full_01p2qnrf_1_1 RECID=1 STAMP=841834351
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u01/backup/ora_full_02p2qnrm_1_1 RECID=2 STAMP=841834358
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u01/backup/ora_full_03p2qnrn_1_1 RECID=3 STAMP=841834360
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u01/backup/ora_system_04p2qnuc_1_1 RECID=4 STAMP=841834444
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u01/backup/ora_system_05p2qnuf_1_1 RECID=5 STAMP=841834448
Crosschecked 5 objects
---都是‘available’


---違背備份策略檢視
RMAN> report obsolete;

RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 1
Report of obsolete backups and copies
Type                 Key    Completion Time    Filename/Handle
-------------------- ------ ------------------ --------------------
Archive Log          1      10-MAR-14          /u01/app/oracle/product/11.2.0.3/db_1/dbs/arch1_34_824748936.dbf
Archive Log          2      10-MAR-14          /u01/app/oracle/product/11.2.0.3/db_1/dbs/arch1_35_824748936.dbf
Archive Log          3      10-MAR-14          /u01/app/oracle/product/11.2.0.3/db_1/dbs/arch1_36_824748936.dbf
Archive Log          4      10-MAR-14          /u01/app/oracle/product/11.2.0.3/db_1/dbs/arch1_37_824748936.dbf
Backup Set           3      10-MAR-14         
  Backup Piece       3      10-MAR-14          /u01/backup/ora_full_03p2qnrn_1_1
Backup Set           4      10-MAR-14         
  Backup Piece       4      10-MAR-14          /u01/backup/ora_system_04p2qnuc_1_1
Backup Set           5      10-MAR-14         
  Backup Piece       5      10-MAR-14          /u01/backup/ora_system_05p2qnuf_1_1
--這裡備份了兩次system,違背備份規則。。

[oracle@11g ~]$ cd /u01/backup/
[oracle@11g backup]$ ls -ltr
-rw-r----- 1 oracle oinstall   1130496 03-10 10:52 ora_full_02p2qnrm_1_1
-rw-r----- 1 oracle oinstall 298704896 03-10 10:52 ora_full_01p2qnrf_1_1
-rw-r----- 1 oracle oinstall   9601024 03-10 10:52 ora_full_03p2qnrn_1_1
-rw-r----- 1 oracle oinstall 211337216 03-10 10:54 ora_system_04p2qnuc_1_1
-rw-r----- 1 oracle oinstall   9601024 03-10 10:54 ora_system_05p2qnuf_1_1
-rw-r----- 1 oracle oinstall 211337216 03-10 10:59 ora_system_06p2qo9d_1_1
-rw-r----- 1 oracle oinstall   9601024 03-10 11:00 ora_system_07p2qo9g_1_1
[oracle@11g backup]$ mv ora_system_04p2qnuc_1_1 ora_system_04p2qnuc_1_1.bak --我們這裡mv重新命名後等與破壞了備份集
[oracle@11g backup]$ ls -ltr
-rw-r----- 1 oracle oinstall   1130496 03-10 10:52 ora_full_02p2qnrm_1_1
-rw-r----- 1 oracle oinstall 298704896 03-10 10:52 ora_full_01p2qnrf_1_1
-rw-r----- 1 oracle oinstall   9601024 03-10 10:52 ora_full_03p2qnrn_1_1
-rw-r----- 1 oracle oinstall 211337216 03-10 10:54 ora_system_04p2qnuc_1_1.bak
-rw-r----- 1 oracle oinstall   9601024 03-10 10:54 ora_system_05p2qnuf_1_1
-rw-r----- 1 oracle oinstall 211337216 03-10 10:59 ora_system_06p2qo9d_1_1
-rw-r----- 1 oracle oinstall   9601024 03-10 11:00 ora_system_07p2qo9g_1_1

[oracle@11g backup]$ rman target /
Recovery Manager: Release 11.2.0.3.0 - Production on Mon Mar 10 11:02:54 2014
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
connected to target database: XUPENG (DBID=874511048)
RMAN> crosscheck backup;

using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=1 device type=DISK
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u01/backup/ora_full_01p2qnrf_1_1 RECID=1 STAMP=841834351
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u01/backup/ora_full_02p2qnrm_1_1 RECID=2 STAMP=841834358
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u01/backup/ora_full_03p2qnrn_1_1 RECID=3 STAMP=841834360
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/u01/backup/ora_system_04p2qnuc_1_1 RECID=4 STAMP=841834444
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u01/backup/ora_system_05p2qnuf_1_1 RECID=5 STAMP=841834448
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u01/backup/ora_system_06p2qo9d_1_1 RECID=6 STAMP=841834797
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u01/backup/ora_system_07p2qo9g_1_1 RECID=7 STAMP=841834801
Crosschecked 7 objects
---這裡發現有備份片‘EXPIRED’無效。

RMAN> list backup summary;

List of Backups
===============
Key     TY LV S Device Type Completion Time #Pieces #Copies Compressed Tag
------- -- -- - ----------- --------------- ------- ------- ---------- ---
1       B  F  A DISK        10-MAR-14       1       1       NO         TAG20140310T105231
2       B  F  A DISK        10-MAR-14       1       1       NO         TAG20140310T105231
3       B  F  A DISK        10-MAR-14       1       1       NO         TAG20140310T105231
4       B  F  X DISK        10-MAR-14       1       1       NO         TAG20140310T105404
5       B  F  A DISK        10-MAR-14       1       1       NO         TAG20140310T105404
6       B  F  A DISK        10-MAR-14       1       1       NO         TAG20140310T105956
7       B  F  A DISK        10-MAR-14       1       1       NO         TAG20140310T105956
---出現X

RMAN> delete noprompt obsolete;

RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 1
using channel ORA_DISK_1
Deleting the following obsolete backups and copies:
Type                 Key    Completion Time    Filename/Handle
-------------------- ------ ------------------ --------------------
Archive Log          1      10-MAR-14          /u01/app/oracle/product/11.2.0.3/db_1/dbs/arch1_34_824748936.dbf
Archive Log          2      10-MAR-14          /u01/app/oracle/product/11.2.0.3/db_1/dbs/arch1_35_824748936.dbf
Archive Log          3      10-MAR-14          /u01/app/oracle/product/11.2.0.3/db_1/dbs/arch1_36_824748936.dbf
Archive Log          4      10-MAR-14          /u01/app/oracle/product/11.2.0.3/db_1/dbs/arch1_37_824748936.dbf
Backup Set           3      10-MAR-14         
  Backup Piece       3      10-MAR-14          /u01/backup/ora_full_03p2qnrn_1_1
Backup Set           4      10-MAR-14         
  Backup Piece       4      10-MAR-14          /u01/backup/ora_system_04p2qnuc_1_1
Backup Set           5      10-MAR-14         
  Backup Piece       5      10-MAR-14          /u01/backup/ora_system_05p2qnuf_1_1
deleted archived log
archived log file name=/u01/app/oracle/product/11.2.0.3/db_1/dbs/arch1_34_824748936.dbf RECID=1 STAMP=841833741
deleted archived log
archived log file name=/u01/app/oracle/product/11.2.0.3/db_1/dbs/arch1_35_824748936.dbf RECID=2 STAMP=841833743
deleted archived log
archived log file name=/u01/app/oracle/product/11.2.0.3/db_1/dbs/arch1_36_824748936.dbf RECID=3 STAMP=841833746
deleted archived log
archived log file name=/u01/app/oracle/product/11.2.0.3/db_1/dbs/arch1_37_824748936.dbf RECID=4 STAMP=841833748
deleted backup piece
backup piece handle=/u01/backup/ora_full_03p2qnrn_1_1 RECID=3 STAMP=841834360
deleted backup piece
backup piece handle=/u01/backup/ora_system_04p2qnuc_1_1 RECID=4 STAMP=841834444
deleted backup piece
backup piece handle=/u01/backup/ora_system_05p2qnuf_1_1 RECID=5 STAMP=841834448
Deleted 7 objects
---刪除違法的備份集。

---我們在檢視一下備份集,
RMAN> report obsolete;

RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 1
no obsolete backups found


RMAN> crosscheck backup;

using channel ORA_DISK_1
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u01/backup/ora_full_01p2qnrf_1_1 RECID=1 STAMP=841834351
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u01/backup/ora_full_02p2qnrm_1_1 RECID=2 STAMP=841834358
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u01/backup/ora_system_06p2qo9d_1_1 RECID=6 STAMP=841834797
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u01/backup/ora_system_07p2qo9g_1_1 RECID=7 STAMP=841834801
Crosschecked 4 objects
----無效的備份集已刪除!!!!
通過此次試驗得出結論crosscheck只能夠檢測備份集是否有效(最常見的情況就是物理上是否還存在),並且可以用它來刪除失效(expired)的備份集,而不是用來刪除違背備份策略(obsolete)的備份集,如果要刪除違背備份策略(廢棄)的備份集,需要使用obsolete操作。出現這個問題的主要原因應該是expired和obsolete翻譯成中文的時候理解的出入導致的,是我理解上混淆概念!!

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

相關文章