SQL Database Repair

How to convert SQL .BAK file to .MDF

info-icon Our content follows trusted Editorial Standards - accurate & unbiased.

Summary: In this article, we will show how to convert SQL .bak file to MDF. We will show different ways to do it. The article will also cover what to do if the bak file is corrupt, how to restore it using SQL database toolkit and get the .mdf file

Table of Contents

What is a file with .bak extension?

In SQL Server, the .bak extension is used to store the backup. You could use any extension, but it is a good practice to use the bak file. A SQL Server backup can be restored and when it is restored, it extracts the .mdf file and the log file. A backup file can have 1 or multiple data files and transaction log files.

How to backup the database into a .bak file

In order to backup your database to a bak, in SSMS (SQL Server Management Studio) select the database and go to Tasks>Back Up:

Select the database and go to Tasks>Back Up

By default, the backup type is full. You can specify the destination and the backup name:

Back UP database window

How to convert the .bak to MDF

In order to restore your bak file to MDF file(s) and transaction files (LDF), right-click the database node and select Restore Database:

Restore Database option window

If you select the device, you can choose your .bak file to restore. Usually, the backup files are stored in a path like this one:

C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\MSSQL\Backup\yourfile.bak
Restore Database window - choose your .bak file to restore

If you go to the Files page, you can set the path for the MDF and LDF files:

path for the MDF and LDF files

When you press restore, you will be able to restore the information.

Note that there are several types of backups. A full backup will contain all the information, whereas a differential backup will backup only the differences between the last backup and the changes of the current database. A differential backup takes less space because it does not store all the information.

The restoration is not exactly converting a bak file into MDF file, basically, it is extracting the information from the bak file to get the MDF file and the transaction log files also. Finally, for backup strategies, refer to this link.

What is an MDF

MDF is a SQL Server database extension for the main data files. The database is stored in physical files that can be an MDF file and NDF files. A database can have 1 MDF file and 0 or multiple NDF files.

The NDF files are secondary files that can be used to distribute the information to reduce the backup time or restoration time.

You can see where your MDF file is by right-clicking the database in SSMS and selecting properties:

Object Explorer Option

In the files page, you can see the path of your files including the MDF and LDF.

Database Properties option window

How to convert .bak file to MDF if the .bak file is corrupt

If your backup is corrupt, you cannot restore the information or you may not be able to restore all the information required. You can use the Stellar Toolkit for MS SQL Server. There are 3 applications in the Toolkit, select the Extract from MS SQL Backup. This application is used to restore a SQL Server backup if it is corrupt.

free-download
Stellar Toolkit for MS SQL

Then you need to select the .bak file and press the Scan button:

Stellar Backup Extractor for MS SQL

You can select the backup set:

Select BackupSet window

You will need to select your SQL Server version. The version 2016  is compatible with SQL Server 2017.

select your SQL Server version

You can check the preview of database objects. If everything is fine, you will be able to see the success message:

MS SQL Database Recovered Success window

The software will restore the database backup. You can restore the bak file into SQL Server using the software specified.

Restored bak file into SQL Server

Once restored, it can be converted to an MDF file when the data is restored.

Conclusion

The bak file is a compressed file that includes the main data file, transaction log files and secondary files (if any). When a file is restored, the backup file is converted to a database composed in an MDF file, transaction logs and sometimes a secondary file with ndf extension. You can use the Stellar Toolkit for MS SQL to get the MDF file from the bak file. The Toolkit can repair not only SQL Server backups, but also includes tools to restore MDF files or recover passwords.

About The Author

Priyanka Chauhan linkdin

Priyanka is a technology expert working for key technology domains that revolve around Data Recovery and related software's. She got expertise on related subjects like SQL Database, Access Database, Q...

1 comment

  1. Hi,
    Just completed the conversion of SQL .BAK file to .MDF successfully. I can give entire credit to stellar for sharing a completely free guide in public domain.

Leave a comment

Your email address will not be published. Required fields are marked *

Google Trust
Related Posts

WHY STELLAR® IS GLOBAL LEADER

Why Choose Stellar?

  • 0M+

    Customers

  • 0+

    Years of Excellence

  • 0+

    R&D Engineers

  • 0+

    Countries

  • 0+

    PARTNERS

  • 0+

    Awards Received

BitRaser With 30 Years of Excellence
Technology You Can Trust
Data Care Experts since 1993
×