RMAN 驗證 資料檔案 和 備份 的有效性

dawn009發表於2014-03-28

有關備份驗證的官網連結如下:

       Validating Database Files and Backups

      

 

       Rman 對資料檔案的驗證,主要是驗證壞塊,包括邏輯壞塊和物理壞塊。 關於壞塊的說明,參考我的Blog

       Oracle 壞塊 總結

       http://blog.csdn.net/tianlesoftware/archive/2009/12/17/5024966.aspx

 

 

備份DB並檢視備份

 

備份指令碼參考:

              Nocatalog 下的RMAN 增量備份 shell指令碼

              http://blog.csdn.net/tianlesoftware/archive/2011/01/26/6164931.aspx

 

RMAN> list backup summary;

 

using target database control file instead of recovery catalog

 

List of Backups

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

Key     TY LV S Device Type Completion Time #Pieces #Copies Compressed Tag

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

9   b  1  a disk    01-jun-11       1       1       no         dave_lev1

10  b  1  a disk    01-jun-11       1       1       no         dave_lev1

13  b  a  a disk    01-jun-11       1       1       no         arc_bak

14  b  a  a disk    01-jun-11       1       1       no         arc_bak

15  b  a  a disk    01-jun-11       1       1       no         arc_bak

16  b  a  a disk    01-jun-11       1       1       no         arc_bak

17   b  a  a disk   01-jun-11       1       1       no         arc_bak

18   b  a  a disk   01-jun-11       1       1       no         arc_bak

19   b  a  a disk   01-jun-11       1       1       no         arc_bak

20   b  a  a disk   01-jun-11       1       1       no         arc_bak

21   b  a  a disk   01-jun-11       1       1       no         arc_bak

22  b  f  a disk    01-jun-11       1       1       no         bak_ctlfile

23  b  f  a disk    01-jun-11       1       1       no         spfile

 

 

驗證備份

 

RMAN的驗證有三種方法:

       1VALIDATE

       2BACKUP ... VALIDATE

       3RESTORE ... VALIDATE

 

2.1 使用Validate 命令

       You can use the  command to manually check for physical and logical corruptions in database files. This command performs the same types of checks as BACKUP VALIDATE, but VALIDATE can check a larger selection of objects.

       For example, you can validate individual blocks with the VALIDATE DATAFILE ... BLOCK command.

 

       When validating whole files, RMAN checks every block of the input files. If the backup validation discovers previously unmarked corrupt blocks, then RMAN updates the V$DATABASE_BLOCK_CORRUPTION view with rows describing the corruptions.

     -- 如果backup validation 發現了之前沒有標記為corrupt block,則更新V$database_block_corruption 表。

 

 

驗證示例:

       Use VALIDATE BACKUPSET when you suspect that one or more backup pieces in a backup set are missing or have been damaged. This command checks every block in a backup set to ensure that the backup can be restored. If RMAN finds block corruption, then it issues an error and terminates the validation. The command VALIDATE BACKUPSET enables you to choose which backups to check, whereas the VALIDATE option of the RESTORE command lets RMAN choose.

 

       For example, to validate all datafiles and control files (and the server parameter file if one is in use), execute the following command at the RMAN prompt:

       RMAN> VALIDATE DATABASE;

 

       Alternatively, you can validate a particular backup set by using the form of the command shown in the following example (sample output included).

 

RMAN> list backupset summary;

--檢視backupset 的編號

List of Backups

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

Key     TY LV S Device Type Completion Time #Pieces #Copies Compressed Tag

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

9   b  1  a disk    01-jun-11       1       1       no         dave_lev1

10  b  1  a disk    01-jun-11       1       1       no         dave_lev1

13  b  a  a disk    01-jun-11       1       1       no         arc_bak

14  b  a  a disk    01-jun-11       1       1       no         arc_bak

15  b  a  a disk    01-jun-11       1       1       no         arc_bak

16  b  a  a disk    01-jun-11       1       1       no         arc_bak

17   b  a  a disk   01-jun-11       1       1       no         arc_bak

18   b  a  a disk   01-jun-11       1       1       no         arc_bak

19   b  a  a disk   01-jun-11       1       1       no         arc_bak

20   b  a  a disk   01-jun-11       1       1       no         arc_bak

21   b  a  a disk   01-jun-11       1       1       no         arc_bak

22  b  f  a disk    01-jun-11       1       1       no         bak_ctlfile

23  b  f  a disk    01-jun-11       1       1       no         spfile

 

RMAN> validate backupset 9;

-- 驗證某一個validate

using channel ORA_DISK_1

channel ORA_DISK_1: starting validation of datafile backupset

channel ORA_DISK_1: reading from backup piece /u01/backup/dave_lev1_0cmdpuof_1_1_20110601

channel ORA_DISK_1: restored backup piece 1

piece handle=/u01/backup/dave_lev1_0cmdpuof_1_1_20110601 tag=DAVE_LEV1

channel ORA_DISK_1: validation complete, elapsed time: 00:00:03

 

       The following example illustrates how you can check individual data blocks within a datafile for corruption.

-- validate 某一個資料塊

 

RMAN> VALIDATE DATAFILE 1 BLOCK 10;

-- 這個功能據說是oracle 11g才有的。 我才10g裡測試確實沒有。

Starting validate at 17-AUG-06

using channel ORA_DISK_1

channel ORA_DISK_1: starting validation of datafile

channel ORA_DISK_1: specifying datafile(s) for validation

input datafile file number=00001 name=/disk1/oracle/dbs/tbs_01.f

channel ORA_DISK_1: validation complete, elapsed time: 00:00:01

List of Datafiles

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

File Status Marked Corrupt Empty Blocks Blocks Examined High SCN

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

1    OK     0              2            127             481907

  File Name: /disk1/oracle/dbs/tbs_01.f

  Block Type Blocks Failing Blocks Processed

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

  Data       0              36

  Index      0              31

  Other      0              58

 

Finished validate at 17-AUG-06

 

Make Parallel the Validation of a Datafile

       If you need to validate a large datafile, then RMAN can make the work parallel by dividing the file into sections and processing each  in parallel. If multiple channels are configured or allocated, and if you want the channels to make parallel the validation, then specify the SECTION SIZE parameter of the VALIDATE command.

       If you specify a section size that is larger than the size of the file, then RMAN does not create file sections. If you specify a small section size that would produce more than 256 sections, then RMAN increases the section size to a value that results in exactly 256 sections.

 

To make parallel the validation of a datafile:

       Run VALIDATE with the SECTION SIZE parameter. The following example allocates two channels and validates a large datafile. The section size is 1200 MB.

 

       RUN

       {

            ALLOCATE CHANNEL c1 DEVICE TYPE DISK;

            ALLOCATE CHANNEL c2 DEVICE TYPE DISK;

            VALIDATE DATAFILE 1 SECTION SIZE 1200M;

       }

 

2.2  使用BACKUP ... VALIDATE 命令

You can use the BACKUP VALIDATE command to do the following:

       1Check datafiles for physical and logical block corruption

       2Confirm that all database files exist and are in the correct locations

 

       When you run BACKUP VALIDATE, RMAN reads the files to be backed up in their entirety, as it would during a real backup. RMAN does not, however, actually produce any backup sets or image copies.

 

       You cannot use the BACKUPSET, MAXCORRUPT, or PROXY parameters with BACKUP VALIDATE. To validate specific backup sets, run the VALIDATE command.

 

To validate files with the BACKUP VALIDATE command:

       1.Start RMAN and connect to a target database and recovery catalog (if used).

       2.Run the BACKUP VALIDATE command.

 

       For example, you can validate that all database files and archived logs can be backed up by running a command as shown in the following example. This command checks for physical corruptions only.

RMAN>backup validate database archivelog all;

 

To check for logical corruptions in addition to physical corruptions, run the following variation of the preceding command:

RMAN>backup validate check logical database archivelog all;

 

注意: 如果加上了archivelog all,就必須要有歸檔檔案存在,如果沒有歸檔檔案,會報如下錯誤:

 

RMAN> backup validate database archivelog all;

starting backup at 01-jun-11

using channel ora_disk_1

rman-00571: ========================================

rman-00569: ========= error message stack follows ==========

rman-00571: ========================================

rman-03002: failure of backup command at 06/01/2011 18:49:11

rman-20242: specification does not match any archive log in the recovery catalog

 

 

示例:

RMAN> backup validate check logical database archivelog all;

 

Starting backup at 01-JUN-11

using channel ORA_DISK_1

channel ORA_DISK_1: starting full datafile backupset

channel ORA_DISK_1: specifying datafile(s) in backupset

input datafile fno=00002 name=+DATA/anqing/datafile/undotbs01.dbf

input datafile fno=00005 name=+DATA/anqing/datafile/undotbs02.dbf

input datafile fno=00001 name=+DATA/anqing/datafile/system01.dbf

input datafile fno=00003 name=+DATA/anqing/datafile/sysaux01.dbf

input datafile fno=00004 name=+DATA/anqing/datafile/users.273.751548233

channel ORA_DISK_1: backup set complete, elapsed time: 00:07:25

channel ORA_DISK_1: starting archive log backupset

channel ORA_DISK_1: specifying archive log(s) in backup set

input archive log thread=1 sequence=44 recid=51 stamp=752698203

--驗證歸檔

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02

channel ORA_DISK_1: starting full datafile backupset

channel ORA_DISK_1: specifying datafile(s) in backupset

including current control file in backupset

including current SPFILE in backupset

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03

Finished backup at 01-JUN-11

 

如果資料庫較大,檢查的時間會較長。

 

 

       In the preceding examples, the RMAN client displays the same output that it would if it were really backing up the files. If RMAN cannot back up one or more of the files, then it issues an error message.

       如果RMAN 不能備份某個檔案,則報如下錯誤:

For example, RMAN may show output similar to the following:

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

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

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

RMAN-03002: failure of backup command at 08/29/2007 14:33:47

ORA-19625: error identifying file /oracle/oradata/trgt/arch/archive1_6.dbf

ORA-27037: unable to obtain file status

SVR4 Error: 2: No such file or directory

Additional information: 3

 

 

2.3  使用 RESTORE ... VALIDATE 命令

       You can run RESTORE ... VALIDATE to test whether RMAN can restore a specific file or set of files from a backup. RMAN chooses which backups to use.

       The database must be mounted or open for this command. You do not have to take datafiles offline when validating the restore of datafiles, because validation of backups of the datafiles only reads the backups and does not affect the production datafiles.

-- validate 只讀取backup file,不影響production datafiles

 

       When validating files on disk or tape, RMAN reads all blocks in the backup piece or image copy. RMAN also validates offsite backups. The validation is identical to a real restore operation except that RMAN does not write output files.

 

To validate backups with the RESTORE command:

Run the RESTORE command with the VALIDATE option.

       1. This following example illustrates validating the restore of the database and all archived redo logs:

       RESTORE DATABASE VALIDATE;

       RESTORE ARCHIVELOG ALL VALIDATE;

 

       If you do not see an RMAN error stack, then skip the subsequent steps. The lack of error messages means that RMAN had confirmed that it can use these backups successfully during a real restore and recovery.

 

       2. If you see error messages in the output and the RMAN-06026 message, then investigate the cause of the problem. If possible, correct the problem that is preventing RMAN from validating the backups and retry the validation.

 

       The following error means that RMAN cannot restore one or more of the specified files from your available backups:

 

RMAN-06026: some targets not found - aborting restore

The following sample output shows that RMAN encountered a problem reading the specified backup:

RMAN-03009: failure of restore command on c1 channel at 12-DEC-06 23:22:30

ORA-19505: failed to identify file "oracle/dbs/1fafv9gl_1_1"

ORA-27037: unable to obtain file status

SVR4 Error: 2: No such file or directory

Additional information: 3

 

示例:

 

--驗證控制檔案

RMAN> restore controlfile validate;

 

Starting restore at 01-JUN-11

using channel ORA_DISK_1

 

channel ORA_DISK_1: starting validation of datafile backupset

channel ORA_DISK_1: reading from backup piece /u01/backup/ctl_file_0omdpvv7_1_1_20110601

channel ORA_DISK_1: restored backup piece 1

piece handle=/u01/backup/ctl_file_0omdpvv7_1_1_20110601 tag=BAK_CTLFILE

channel ORA_DISK_1: validation complete, elapsed time: 00:00:01

Finished restore at 01-JUN-11

 

--驗證spfile 有效性

RMAN> restore spfile validate;

 

Starting restore at 01-JUN-11

using channel ORA_DISK_1

 

channel ORA_DISK_1: starting validation of datafile backupset

channel ORA_DISK_1: reading from backup piece /u01/backup/dave_spfile_0pmdpvva_1_1_20110601

channel ORA_DISK_1: restored backup piece 1

piece handle=/u01/backup/dave_spfile_0pmdpvva_1_1_20110601 tag=SPFILE

channel ORA_DISK_1: validation complete, elapsed time: 00:00:01

Finished restore at 01-JUN-11

 

--驗證資料庫

RMAN> restore database validate;

 

Starting restore at 01-JUN-11

using channel ORA_DISK_1

 

channel ORA_DISK_1: starting validation of datafile backupset

channel ORA_DISK_1: reading from backup piece /u01/backup/dave_lev0_10mdqqtd_1_1_20110601

channel ORA_DISK_1: restored backup piece 1

piece handle=/u01/backup/dave_lev0_10mdqqtd_1_1_20110601 tag=DAVE_LEV0

channel ORA_DISK_1: validation complete, elapsed time: 00:00:07

channel ORA_DISK_1: starting validation of datafile backupset

channel ORA_DISK_1: reading from backup piece /u01/backup/dave_lev0_0vmdqqtd_1_1_20110601

channel ORA_DISK_1: restored backup piece 1

piece handle=/u01/backup/dave_lev0_0vmdqqtd_1_1_20110601 tag=DAVE_LEV0

channel ORA_DISK_1: validation complete, elapsed time: 00:00:15

Finished restore at 01-JUN-11

 

在驗證這塊的時候有個小插曲,參考:

       RMAN-06023 : no backup or copy of datafile found to restore 說明

       http://blog.csdn.net/tianlesoftware/archive/2011/06/02/6460459.aspx

 

--驗證歸檔有效性

 

開始驗證的是所有的歸檔檔案,但是no backup found的錯誤。如下:

 

RMAN> restore archivelog all validate;

 

Starting restore at 01-JUN-11

using channel ORA_DISK_1

 

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

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

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

RMAN-03002: failure of restore command at 06/01/2011 22:10:42

RMAN-06026: some targets not found - aborting restore

RMAN-06025: no backup of log thread 2 seq 3 lowscn 1829719 found to restore

RMAN-06025: no backup of log thread 2 seq 2 lowscn 1746388 found to restore

RMAN-06025: no backup of log thread 2 seq 1 lowscn 946447 found to restore

.....

RMAN-06025: no backup of log thread 1 seq 2 lowscn 480030 found to restore

RMAN-06025: no backup of log thread 1 seq 1 lowscn 460026 found to restore

RMAN-06025: no backup of log thread 1 seq 3 lowscn 460020 found to restore

RMAN-06025: no backup of log thread 1 seq 2 lowscn 451150 found to restore

 

       因為我之前已經刪除了一些歸檔的備份,我這次備份只有3個歸檔,檢視了一下日誌的最大序列數:

SYS@anqing1(rac1)> select max(sequence#) from v$archived_log;

 

MAX(SEQUENCE#)

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

  47

 

所以從45 開始驗證,執行透過:

 

RMAN> restore archivelog sequence 45 validate;

 

Starting restore at 01-JUN-11

using channel ORA_DISK_1

 

channel ORA_DISK_1: starting validation of archive log backupset

channel ORA_DISK_1: reading from backup piece /u01/backup/arch_14mdqrcs_1_1_20110601

channel ORA_DISK_1: restored backup piece 1

piece handle=/u01/backup/arch_14mdqrcs_1_1_20110601 tag=ARC_BAK

channel ORA_DISK_1: validation complete, elapsed time: 00:00:00

Finished restore at 01-JUN-11

---------------------------------------------------------------------------
轉載於--&gt>http://blog.csdn.net/tianlesoftware/article/details/6460464

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

相關文章