I worked on an interesting issue today where a user couldn’t restore a backup. Here is what this customer did:
backed up a database from an on-premises server (2008 R2)
copied the file to an Azure VM
tried to restore the backup on the Azure VM (2008 R2 with exact same build#)
But he got the following error:
Msg 3241, Level 16, State 0, Line 4
The media family on device 'c:\temp\test.bak' is incorrectly formed. SQL Server cannot process this media family.
Msg 3013, Level 16, State 1, Line 4
RESTORE HEADERONLY is terminating abnormally.
We verified that he could restore the same backup on the local machine (on-premises). Initially I thought the file must have been corrupt during transferring. We used different method to transfer file and zipped the file. The behavior is the same. When we backed up a database from the same Azure VM and tried to restore, it was successful.
We were at a point I thought there might be a bug and I was planning to get the backup in house to reproduce the problem until this customer told me that they are using a tool called “
Microsoft SQL Server Backup to Microsoft Azure Tool
” which is only necessary to use for SQL 2008 R2 or below because SQL 2012 and above have builtin functionality to backup to and restore from Azure blob storage. Then I said how about we stop that service to see what happens. After stopping that service (screenshot below), restore now works perfectly fine. After restarting it, the same error.
After a little research, I found out more about this tool. The backup tool basically is a filter driver that watches any files with certain extension you have configured when SQL Server tries to access the file.
when SQL Server does a backup, the tool will redirect the file to Azure blob storage and leaves a small stub file on local computer
when SQL Server does a restore, the tool will try to access the same file from Azure blog stroage and give it to SQL Server
Now you can see the problem. In this customer’s scenario, the *.bak file was transferred from on-premise server directly to the Azure VM. there is no corresponding file on the Azure blob storage. Since the tool can’t find the file to provide content to SQL Server, the restore fails with the error.
Here are ways how you fix the issue
The cleanest way is to configure the rule to watch files only to specific path instead of watching the whole computer. By default, all path on the local machine is checked. But you can add multiple paths to watch. If you do this, you can simply put the backup you copied from remote machine (which is not part of the backup from the server watched by the tool) to a different folder and perform restore.
Alternatively, you can stop this tool when you restore a backup that you copied from a different machine.
You can also use a different file extension for the file you copied from remote machine and try to restore
Jack Li |Senior Escalation Engineer | Microsoft SQL Server