使用 Exchange 2013 中的 CHKSGFILES API 验证备份完整性Validate backup integrity by using the CHKSGFILES API in Exchange 2013

了解如何使用 CHKSGFILES API 验证 exchange 存储在 Exchange 2013 中的备份。Find out how to use the CHKSGFILES API to validate a backup of the Exchange store in Exchange 2013.

适用于: Exchange Server 2013Applies to: Exchange Server 2013

在卷影复制服务(VSS)管理的备份操作过程中,Exchange Server 2013 无法完全读取每个数据库文件,并验证其校验和完整性。During backup operations managed by the Volume Shadow Copy Service (VSS), Exchange Server 2013 cannot read each database file in its entirety and verify its checksum integrity. 因此,您可能希望备份应用程序验证数据库和事务日志文件的完整性。Therefore, you might want your backup application to verify database and transaction log file integrity. 我们建议您的备份应用程序先验证卷影副本集的物理一致性,然后再通知 Exchange 编写器备份已完成。We recommend that your backup application verify the physical consistency of the shadow copy set prior to informing the Exchange writer that the backup is complete. 成功备份后,Exchange 存储将更新已备份数据库的标头,以反映上次成功备份的时间,并从服务器中删除不再需要的事务日志,以从上次成功的备份中向前滚动。After a successful backup, the Exchange store updates the headers of the backed-up databases to reflect the last successful backup times and removes transaction logs from the server that are no longer required to roll forward from the last successful backup.

验证备份完整性的先决条件Prerequisites for validating backup integrity

在您的应用程序可以验证备份的完整性之前,您必须能够访问以下内容:Before your application can validate the integrity of your backup, you must have access to the following:

  • Exchange 存储备份中的文件。Files from your Exchange store backup.
  • 以 Visual Studio 2010 开头的 Visual Studio 版本。A version of Visual Studio starting with Visual Studio 2010.
  • CHKSGFILES 库和头文件。The CHKSGFILES library and header files. 您可以从Microsoft 下载中心下载库和头文件。You can download the library and header files from the Microsoft Download Center.

验证备份完整性Validate backup integrity

以下过程介绍如何验证备份和还原应用程序中的数据完整性。The following procedure describes how to validate data integrity in your backup and restore application.

验证备份完整性To validate backup integrity

  1. 创建CChkSGFiles类的新实例。Create a new instance of the CChkSGFiles class.

    CCheckSGFiles::ERRerr = CCheckSGFiles::errSuccess;
    ULONGiDbError = (ULONG)CCheckSGFiles::iDbInvalid;
    CCheckSGFiles * const pcchecksgfiles = CCheckSGFiles::New();
    if ( NULL == pcchecksgfiles )
    {
      err = CCheckSGFiles::errOutOfMemory;
      printf( "ERROR: Could not allocate CCheckSGFiles object.\n" );
      goto HandleError;
    }
    

    代码的第一行创建一个 error 对象,并将其初始值设置为 "成功",并创建一个用于检查数据库有效性的对象。The first lines of code create an error object and set its initial value to success, and create an object that checks the validity of the database. 然后, CChkSGFiles 函数创建CChkSGFiles类的新实例。Then, the CChkSGFiles.New function creates a new instance of the CChkSGFiles class. 新对象的快速检查指示创建新实例时是否出现任何问题。A quick check of the new object indicates whether any issues occurred when the new instance was created.

  2. 初始化CChkSGFiles对象。Initialize the CChkSGFiles object.

    Call( pcchecksgfiles->ErrInit(
    rgwszDb,
    cDb,
    wszLogPath,
    wszBaseName ) );
    

    有关参数的详细信息,请参阅CChkSGFiles 函数For more information about the parameters, see CChkSGFiles.ErrInit function.

  3. 通过检查数据库标头,使用ErrCheckDbHeaders 函数来验证数据库的完整性 CChkSGFiles。Use the CChkSGFiles.ErrCheckDbHeaders function to validate database integrity by checking the database headers.

    err = pcchecksgfiles->ErrCheckDbHeaders(
    &cbDbPageSize,
    &cDbHeaderPages,
    &iDbError );
    if ( CCheckSGFiles::errSuccess != err )
    {
    if ( CCheckSGFiles::iDbInvalid != iDbError )
    {
    printf(
    "ERROR: Database header validation for '%S' failed with error %d (0x%x)\n",
    rgwszDb[ iDbError ],
    err,
    err );
    }
    goto HandleError;
    }
    

    有关参数的详细信息,请参阅CChkSGFiles 函数For more information about the parameters, see CChkSGFiles.ErrCheckDbHeaders function.

  4. 处理错误,并使用CChkSGFiles 函数从内存中删除CChkSGFiles类。Handle errors, and use the CChkSGFiles.Delete function to remove the CChkSGFiles class from memory.

    HandleError:
    CCheckSGFiles::Delete( pcchecksgfiles );  
    

另请参阅See also