Wednesday, 11 January 2017

'SetEndOfFile' error during Backup

Below is the error.

Message
Executed as user:. Date and time: 2016-12-11 04:10:11  Server:  Version: 11.0.6537.0  Edition: Enterprise Edition: Core-based  Procedure: [master].[dbo].[Database]  Parameters: @Databases = 'DB_Name', @Directory = 'Backup path1', @BackupType = 'FULL', @Verify = 'N', @CleanupTime = 240, @CleanupMode = 'AFTER_BACKUP', @Compress = 'Y', @CopyOnly = 'N', @ChangeBackupType = 'Y', @BackupSoftware = NULL, @CheckSum = 'Y', @BlockSize = NULL, @BufferCount = 256, @MaxTransferSize = 2097152, @NumberOfFiles = 4, @CompressionLevel = NULL, @Description = NULL, @Threads = NULL, @Throttle = NULL, @Encrypt = 'N', @EncryptionAlgorithm = NULL, @ServerCertificate = NULL, @ServerAsymmetricKey = NULL, @EncryptionKey = NULL, @ReadWriteFileGroups = 'N', @OverrideBackupPreference = 'N', @NoRecovery = 'N', @URL = NULL, @Credential = NULL, @MirrorDirectory = NULL, @MirrorCleanupTime = NULL, @MirrorCleanupMode = 'AFTER_BACKUP', @LogToTable = 'Y', @Execute = 'Y'  Source: https://ola.hallengren.com [SQLSTATE 01000] (Message 50000)  Date and time: 2016-12-11 04:10:11  Database: []  Status: ONLINE  Standby: No  Updateability: READ_WRITE  User access: MULTI_USER  Is accessible: Yes  Recovery model: FULL  Differential base LSN: 151862000023530400068  Last log backup LSN: 151862000025621600001 [SQLSTATE 01000] (Message 50000)  Date and time: 2016-12-11 04:10:11  Command: DECLARE @ReturnCode int EXECUTE @ReturnCode = [master].dbo.xp_create_subdir N'\\' IF @ReturnCode <> 0 RAISERROR('Error creating directory.', 16, 1) [SQLSTATE 01000] (Message 50000)  Outcome: Succeeded  Duration: 00:00:00  Date and time: 2016-12-11 04:10:11 [SQLSTATE 01000] (Message 50000)  Date and time: 2016-12-11 04:10:11  Command: BACKUP DATABASE [EDDS2623458] TO DISK =  WITH CHECKSUM, OMPRESSION, BUFFERCOUNT = 256, MAXTRANSFERSIZE = 2097152 [SQLSTATE 01000] (Message 50000)  Processed 388889392 pages for database '', file '' on file 1. [SQLSTATE 01000] (Message 4035)  Processed 56314928 pages for database '', file '' on file 1. [SQLSTATE 01000] (Message 4035)  Processed 2 pages for database '', file '' on file 1. [SQLSTATE 01000] (Message 4035)  The operating system returned the error '1359(An internal error occurred.)' while attempting 'SetEndOfFile' on ''. [SQLSTATE 42000] (Error 3634)  BACKUP DATABASE is terminating abnormally. [SQLSTATE 42000] (Error 3013)  Outcome: Failed  Duration: 01:45:31  Date and time: 2016-12-11 05:55:42 [SQLSTATE 01000] (Message 50000)  Date and time: 2016-12-11 05:55:42 [SQLSTATE 01000] (Message 50000).  The step failed.


When performing a backup dump using compression we may get an error like this.

It doesn’t always happen every backup. The problem appears to be related to the way that SQL server creates the backup file. When using compression, the SQL server pre-allocates space for the backup file and the data is then written into it. Since the data is compressed the backup takes less space than was allocated and SQL server instructs the filesystem to truncate the file (set the end of the file). On local disk this can happen quickly but over a network to a share it can take longer.


When the backup file is written to a SMB share the truncation can take longer than expected, especially if the amount of data to be truncated is quite large (i.e. it was compressed quite alot) and the request can timeout.


Resolution :

We can tweak the timeout by adding the following registry entry:

1. Click Start, click Run, type regedit.exe, and then click OK.
2. In Registry Editor, locate and then right-click the following registry subkey:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanWorkstation\Parameters
3. On the Edit menu, point to New, and then click DWORD Value.
4. Type SessTimeout, and then press ENTER.
5. On the Edit menu, click Modify.
6. In the Edit DWORD Value dialog box, click Decimal under Base, type 300 under Value data, and then click OK.

The default SessTimeout setting is 50 seconds. This changes it to 300 seconds (5 minutes).

For more information check out:

The function used to truncate the file is SetEndOfFile :

No comments:

Post a Comment