RESTORE 语句 - VERIFYONLY (Transact-SQL)RESTORE Statements - VERIFYONLY (Transact-SQL)

适用对象:是SQL Server 是Azure SQL 数据库(仅限托管实例)否Azure Synapse Analytics (SQL DW) 否并行数据仓库 APPLIES TO: yesSQL Server yesAzure SQL Database (Managed Instance only) noAzure Synapse Analytics (SQL DW) noParallel Data Warehouse

验证备份但不还原备份,检查备份集是否完整以及整个备份是否可读。Verifies the backup but does not restore it, and checks to see that the backup set is complete and the entire backup is readable. 但是,RESTORE VERIFYONLY 不尝试验证备份卷中的数据结构。However, RESTORE VERIFYONLY does not attempt to verify the structure of the data contained in the backup volumes. MicrosoftMicrosoft SQL ServerSQL Server 中,RESTORE VERIFYONLY 得到了增强以对数据进行附加检查,从而提高检测到错误的可能性。In MicrosoftMicrosoft SQL ServerSQL Server, RESTORE VERIFYONLY has been enhanced to do additional checking on the data to increase the probability of detecting errors. 其目标是尽可能接近实际的还原操作。The goal is to be as close to an actual restore operation as practical. 有关详细信息,请参阅“备注”部分。For more information, see the Remarks.

如果备份有效,SQL Server 数据库引擎SQL Server Database Engine 会返回一条成功消息。If the backup is valid, the SQL Server 数据库引擎SQL Server Database Engine returns a success message.

备注

有关参数的说明,请参阅 RESTORE 参数 (Transact-SQL)For the descriptions of the arguments, see RESTORE Arguments (Transact-SQL).

主题链接图标 Transact-SQL 语法约定Topic link icon Transact-SQL Syntax Conventions

语法Syntax

  
RESTORE VERIFYONLY  
FROM <backup_device> [ ,...n ]  
[ WITH    
 {  
   LOADHISTORY   
  
--Restore Operation Option  
 | MOVE 'logical_file_name_in_backup' TO 'operating_system_file_name'   
          [ ,...n ]   
  
--Backup Set Options  
 | FILE = { backup_set_file_number | @backup_set_file_number }   
 | PASSWORD = { password | @password_variable }   
  
--Media Set Options  
 | MEDIANAME = { media_name | @media_name_variable }   
 | MEDIAPASSWORD = { mediapassword | @mediapassword_variable }  
  
--Error Management Options  
 | { CHECKSUM | NO_CHECKSUM }   
 | { STOP_ON_ERROR | CONTINUE_AFTER_ERROR }  
  
--Monitoring Options  
 | STATS [ = percentage ]   
  
--Tape Options  
 | { REWIND | NOREWIND }   
 | { UNLOAD | NOUNLOAD }    
 } [ ,...n ]  
]  
[;]  
  
<backup_device> ::=  
{   
   { logical_backup_device_name |  
      @logical_backup_device_name_var }  
   | { DISK | TAPE | URL } = { 'physical_backup_device_name' |  
       @physical_backup_device_name_var }   
}  
  

备注

URL 是用于为 Microsoft Azure Blob 存储指定位置和文件名的格式,从 SQL Server 2012 (11.x)SQL Server 2012 (11.x) SP1 CU2 开始受支持。URL is the format used to specify the location and the file name for Microsoft Azure Blob Storage and is supported starting with SQL Server 2012 (11.x)SQL Server 2012 (11.x) SP1 CU2. 虽然 Microsoft Azure 存储是一种服务,不过实现与磁盘和磁带类似,从而可为所有三种设备提供一致且无缝的还原体验。Although Microsoft Azure storage is a service, the implementation is similar to disk and tape to allow for a consistent and seamless restore experience for all the three devices.

参数Arguments

有关 RESTORE VERIFYONLY 参数的说明,请参阅 RESTORE 参数 (Transact-SQL)For descriptions of the RESTORE VERIFYONLY arguments, see RESTORE Arguments (Transact-SQL).

一般备注General Remarks

介质集或备份集必须包含最低限度的正确信息,才能被解释为 Microsoft Tape Format。The media set or the backup set must contain minimal correct information to enable it to be interpreted as Microsoft Tape Format. 如果没有这些信息,RESTORE VERIFYONLY 将停止,并且指示备份格式无效。If not, RESTORE VERIFYONLY stops and indicates that the format of the backup is invalid.

RESTORE VERIFYONLY 执行下列检查:Checks performed by RESTORE VERIFYONLY include:

  • 备份集是否完整以及所有卷是否可读。That the backup set is complete and all volumes are readable.

  • 数据库页中的一些标头字段,例如页 ID(就如同要写入数据一样)。Some header fields of database pages, such as the page ID (as if it were about to write the data).

  • 校验和(如果介质中提供的话)。Checksum (if present on the media).

  • 目标设备中是否有足够的空间。Checking for sufficient space on destination devices.

备注

RESTORE VERIFYONLY 不对数据库快照进行检查。RESTORE VERIFYONLY does not work on a database snapshot. 要在恢复操作之前验证数据库快照,可以运行 DBCC CHECKDB。To verify a database snapshot before a revert operation, you can run DBCC CHECKDB.

备注

借助快照备份,RESTORE VERIFYONLY 可确认快照是否在备份文件中指定的位置处存在。With snapshot backups, RESTORE VERIFYONLY confirms the existence of the snapshots in the locations specified in the backup file. 快照备份是 SQL Server 2016 (13.x)SQL Server 2016 (13.x) 中的新功能。Snapshot backups are a new feature in SQL Server 2016 (13.x)SQL Server 2016 (13.x). 有关快照备份的详细信息,请参阅 Azure 中数据库文件的文件快照备份For more information about Snapshot Backups, see File-Snapshot Backups for Database Files in Azure.

安全性Security

在备份时,可以根据需要为介质集、备份集或这两者指定密码。A backup operation may optionally specify passwords for a media set, a backup set, or both. 如果已经在介质集或备份集上定义了密码,则必须在 RESTORE 语句中指定正确的密码。When a password has been defined on a media set or backup set, you must specify the correct password or passwords in the RESTORE statement. 这些密码可防止未经授权而使用 SQL ServerSQL Server 工具执行还原操作以及向介质追加备份集。These passwords prevent unauthorized restore operations and unauthorized appends of backup sets to media using SQL ServerSQL Server tools. 但是,密码不会阻止使用 BACKUP 语句的 FORMAT 选项覆盖介质。However, a password does not prevent overwrite of media using the BACKUP statement's FORMAT option.

重要

此密码提供的安全性较低。The protection provided by this password is weak. 它旨在防止经过授权的用户或未经授权的用户使用 SQL ServerSQL Server 工具执行不正确的还原操作。It is intended to prevent an incorrect restore using SQL ServerSQL Server tools by authorized or unauthorized users. 但是不能防止通过其他方式或通过替换密码来读取备份数据。It does not prevent the reading of the backup data by other means or the replacement of the password. 此功能处于维护模式并且可能会在 Microsoft SQL Server 将来的版本中被删除。This feature is in maintenance mode and may be removed in a future version of Microsoft SQL Server. 请避免在新的开发工作中使用该功能,并着手修改当前还在使用该功能的应用程序。Avoid using this feature in new development work, and plan to modify applications that currently use this feature. 保护备份的最佳做法是将备份磁带存储在安全位置,或者备份到由适当的访问控制列表 (ACL) 保护的磁盘文件。The best practice for protecting backups is to store backup tapes in a secure location or back up to disk files that are protected by adequate access control lists (ACLs). ACL 应设置在创建备份的根目录下。The ACLs should be set on the directory root under which backups are created.

权限Permissions

SQL Server 2008SQL Server 2008 开始,获取有关备份集或备份设备的信息需要具有 CREATE DATABASE 权限。Beginning in SQL Server 2008SQL Server 2008, obtaining information about a backup set or backup device requires CREATE DATABASE permission. 有关详细信息,请参阅 GRANT 数据库权限 (Transact-SQL)For more information, see GRANT Database Permissions (Transact-SQL).

示例Examples

以下示例从磁盘验证备份。The following example verifies the backup from disk.

RESTORE VERIFYONLY FROM DISK = 'D:\AdventureWorks.bak';
GO

另请参阅See Also

BACKUP (Transact-SQL) BACKUP (Transact-SQL)
媒体集、媒体簇和备份集 (SQL Server) Media Sets, Media Families, and Backup Sets (SQL Server)
RESTORE REWINDONLY (Transact-SQL) RESTORE REWINDONLY (Transact-SQL)
RESTORE (Transact-SQL) RESTORE (Transact-SQL)
备份历史记录和标头信息 (SQL Server)Backup History and Header Information (SQL Server)