RESTORE 陳述式 - VERIFYONLY (Transact-SQL)RESTORE Statements - VERIFYONLY (Transact-SQL)

適用於: 是SQL Server 是Azure SQL Database (僅限受控執行個體) 否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 Database EngineSQL Server Database Engine 會傳回成功的訊息。If the backup is valid, the SQL Server Database EngineSQL 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.

  • 部分資料庫頁面的標頭欄位,如頁面識別碼 (如同即將寫入資料)。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.

SecuritySecurity

備份作業可以選擇性地指定媒體集的密碼及 (或) 備份組的密碼。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)