HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMajor

Can I restore a SQL Server .bak files without SQL Server?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
canwithoutsqlfilesserverbakrestore

Problem

I have some large .bak files from a SQL Server 2005 dump.

Can I restore these without using SQL Server, either to PostgreSQL, MySQL, or to flat text files?

An open source solution would be most useful.

Solution

Here is what I suggest:

  • build a virtual machine running Windows, with enough disk space to hold the backup. Copy the backup file there. If you don't already have the ability to build virtual machines, you could do so with free products like Oracle VirtualBox.



  • download and install the evaluation edition of SQL Server. Make sure you include both the database engine and Management Tools - Complete.



-
if the VM has enough space to hold the backup but not enough space to also restore it, you can
perform a "virtual restore" using the trial version of a product
from Red-Gate with the same name (which allows you to interact with the backup file as if it had been restored). Otherwise, restore the database the normal way.

-
Once the database is available (either through a normal restore or virtual restore), you can generate scripts for the schema and data in the following way:

  • Open Management Studio and connect to your instance.



  • Open Object Explorer.



  • Right-click your newly restored database, choose Tasks > Generate Scripts...



  • Click Next, Click Next



  • On the "Choose Script Options" page, scroll down and set "Script Data" to True



  • Click Next



  • Check all of the relevant objects and click Next



  • Check the tables you want and click Next



  • Choose to script to a file. Now you'll have a file that contains all your objects and data using SQL Server insert syntax, you will have to play with the output to get it in a format that works for Postgres (I am not privy to any minor syntax differences).



Alternatively you can try and play with the bcp utility to extract data to CSV files or similar, but you'll have to do this table-by-table or use some clever scripting (PowerShell, T-SQL, C#/SMO, etc.) to generate all of the bcp commands for you. Once in CSV files, it should be trivial to bulk load the data into Postgres (but you will still have some work to generate the tables).

As a final suggestion, if the .bak file is not ginormous, and the data is not confidential, I am more than willing to try and generate files for you in the format you need. I have plenty of Windows VMs with space, the challenge would be getting the .BAK file to a place where I can retrieve it - especially if it's larger than most of the file-sharing services support.

Context

StackExchange Database Administrators Q#20078, answer score: 20

Revisions (0)

No revisions yet.