ערוך

שתף באמצעות


Specify backup or restore to continue or stop after error

Applies to: SQL Server

This topic describes how to specify whether a backup or restore operation continues or stops after encountering an error in SQL Server by using SQL Server Management Studio or Transact-SQL.

In This Topic

Before You Begin

Security

Permissions

BACKUP
BACKUP DATABASE and BACKUP LOG permissions default to members of the sysadmin fixed server role and the db_owner and db_backupoperator fixed database roles.

Ownership and permission problems on the backup device's physical file can interfere with a backup operation. SQL Server must be able to read and write to the device; the account under which the SQL Server service runs must have write permissions. However, sp_addumpdevice, which adds an entry for a backup device in the system tables, does not check file access permissions. Such problems on the backup device's physical file may not appear until the physical resource is accessed when the backup or restore is attempted.

RESTORE
If the database being restored does not exist, the user must have CREATE DATABASE permissions to be able to execute RESTORE. If the database exists, RESTORE permissions default to members of the sysadmin and dbcreator fixed server roles and the owner (dbo) of the database (for the FROM DATABASE_SNAPSHOT option, the database always exists).

RESTORE permissions are given to roles in which membership information is always readily available to the server. Because fixed database role membership can be checked only when the database is accessible and undamaged, which is not always the case when RESTORE is executed, members of the db_owner fixed database role do not have RESTORE permissions.

Using SQL Server Management Studio

To specify whether backup continues or stops after an error is encountered

  1. Follow the steps to create a database backup.

  2. On the Options page, in the Reliability section, click Perform checksum before writing to media and Continue on error.

Using Transact-SQL

To specify whether a backup operation continues or stops after encountering an error

  1. Connect to the Database Engine.

  2. From the Standard bar, click New Query.

  3. In the BACKUP statement, specify the CONTINUE_AFTER ERROR option to continue or the STOP_ON_ERROR option to stop. The default behavior is to stop after encountering an error. This example instructs the backup operation to continue despite encountering an error.

BACKUP DATABASE AdventureWorks2022   
 TO DISK = 'Z:\SQLServerBackups\AdvWorksData.bak'  
   WITH CHECKSUM, CONTINUE_AFTER_ERROR;  
GO  

To specify whether a restore operation continues or stops after encountering an error

  1. Connect to the Database Engine.

  2. From the Standard bar, click New Query.

  3. In the RESTORE statement, specify the CONTINUE_AFTER ERROR option to continue or the STOP_ON_ERROR option to stop. The default behavior is to stop after encountering an error. This example instructs the restore operation to continue despite encountering an error.

RESTORE DATABASE AdventureWorks2022   
 FROM DISK = 'Z:\SQLServerBackups\AdvWorksData.bak'   
   WITH CHECKSUM, CONTINUE_AFTER_ERROR;  
GO  

See Also

RESTORE FILELISTONLY (Transact-SQL)
RESTORE HEADERONLY (Transact-SQL)
RESTORE LABELONLY (Transact-SQL)
RESTORE VERIFYONLY (Transact-SQL)
BACKUP (Transact-SQL)
backupset (Transact-SQL)
RESTORE Arguments (Transact-SQL)
Possible Media Errors During Backup and Restore (SQL Server)
Enable or Disable Backup Checksums During Backup or Restore (SQL Server)