37

I am trying to restore a .BAK in SQL server but get the following error:

Msg 3241, Level 16, State 7, Line 1 The media family on device 'c:\glyn\JA.bak' is incorrectly formed. SQL Server cannot process this media family. Msg 3013, Level 16, State 1, Line 1 RESTORE DATABASE is terminating abnormally.

I have tried restoring using 2012, 2008 and even 2005 but nothing works, I have used the following query and through the Tasks >> Back up but nothing works, here's my SQL:

RESTORE DATABASE JA FROM DISK='c:\glyn\JA.bak'

Does anyone have any suggestions? I've read that the bak could be corrupt, it was sent to my by another developer on DVD who is working on the project.

1

8 Answers 8

12

If you are attempting to restore newer database to older SQL version you can always simply manually create the database in the older SQL version and utilize the task - generate scripts and include the data.

Save to File --> Advanced--> Types of data to script --> Schema and data.

Also make sure to Script for Server Version.

This might be the only supported option if you're trying to go from newer SQL Server to older version.

Related: Restore SQL Server 2012 backup to a SQL Server 2008 database?

1
  • Seems like a hack but I guess this worked around this issue in my case.
    – jpierson
    Commented Oct 31, 2016 at 19:12
10

I had the same problem, my script was specifying the incorrect FILE type, I had a .bak and I was specifying FILE = 2 which is a .trn.

USE [master]
RESTORE DATABASE [MyNewDB] FROM
DISK = N'D:\MyOldDB.bak'
WITH
    FILE = 1, -- 1 = .bak, 2 = .trn type backup
    MOVE N'MyOldDB' TO N'd:\data\MyOldDB.mdf',
    MOVE N'MyOldDB_log' TO N'd:\data\MyOldDB_log.ldf',
    NOUNLOAD,
    STATS = 5    
GO

I'm not sure if the RESTORE command auto-detects or sets a default for this...

1
  • 1
    The error turns around this, the problem is when you use the GUI to restore databases, SQL Managment Studio does not provide you detailed information. If you try to restore using t-sql script, sql server will report you to use MOVE option. Commented Dec 1, 2015 at 9:37
8

I found this that says that your backup file is corrupted. Possibly transfered by FTP in text mode rather than binary.

And this blog that lists how someone else fixed the same problem.

1
  • 9
    "lists how someone else fixed the same problem" generally on SE network sites you should post the relevant bits of things like blog posts; it prevents link decay
    – jcollum
    Commented Dec 31, 2014 at 20:57
8

Run the following script on source and destination SQL Servers, the versions should either match or the destination should have a higher version of SQL Server otherwise you cannot restore the .bak file:

SELECT @@Version

Simple check to confirm if this is the problem, even if the source and target databases are both the same version, eg SQL 2019 the source might have a Cumulative Update applied:

Source:

Microsoft SQL Server 2019 (RTM-CU16) (KB5011644) - 15.0.4223.1 (X64) Apr 11 2022 16:24:07 Copyright (C) 2019 Microsoft Corporation Developer Edition (64-bit) on Windows Server 2019 Datacenter 10.0 (Build 17763: ) (Hypervisor)

Target:

Microsoft SQL Server 2019 (RTM) - 15.0.2000.5 (X64) Sep 24 2019 13:48:23 Copyright (C) 2019 Microsoft Corporation Developer Edition (64-bit) on Windows 10 Pro 10.0 (Build 19044: ) (Hypervisor)

Applying the Cumulative Update to the target resolved the problem.

2
  • 1
    The point about versions has been repeated in other answers.
    – Andriy M
    Commented May 21, 2016 at 23:01
  • 1
    @AndriyM you are right, but a practical action was missing. We are not talking about history or geography, some command or code should be mentioned. Commented May 22, 2016 at 10:45
0

The only reason is you are trying to restore lower version backup, Refer: http://www.sqlservercentral.com/Forums/Topic1675066-1550-1.aspx?Update=1

0

If you are restoring from S3 into RDS make sure you mention the key you encrypted the file with when the backup was taken. I.e.:

exec msdb.dbo.rds_restore_database
    @restore_db_name='Test',
    @s3_arn_to_restore_from='arn:aws:s3:::bucket-name/test.bak',
    @kms_master_key_arn='arn:aws:kms:eu-west-2:<kms key id>';
0

I had this issue. Just checking around the database that had this problem, I found out that if encryption is turned on we can't restore to the other server. You can use these commands to turn off the encryption:

Use Master
Go
Alter database [testDB] Set encryption off
Go

After the above commands, wait for some time to process the following command, as it takes time to decrypt the database.

use  [testDB]
go
drop database encryption key
go

Hope this helps.

-7

delete corrupted file and re-run the backup

1
  • 4
    Hi, Welcome to the site. We like a bit more detail on how why or how this would work.
    – Tom V
    Commented Oct 27, 2016 at 20:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.