RMAN 验证 数据文件 和 备份 的有效性

时间:2022-01-21 11:52:19

 

 

有关备份验证的官网链接如下:

       Validating Database Files and Backups

      http://download.oracle.com/docs/cd/E11882_01/backup.112/e10642/rcmvalid.htm#BRADV90064

 

       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 VALIDATE 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 file section 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

 

 

 

 

 

 

 

 

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

Blog http://blog.csdn.net/tianlesoftware

Email: dvd.dba@gmail.com

DBA1 群:62697716();   DBA2 群:62697977()   DBA3 群:62697850()  

DBA 超级群:63306533();  DBA4 群: 83829929  DBA5群: 142216823   

DBA6 群:158654907  聊天 群:40132017   聊天2群:69087192

--加群需要在备注说明Oracle表空间和数据文件的关系,否则拒绝申请