Restoring MSSQL database on linux.

To restore the MSSQL database on linux hosted MSSQL Server follow the following steps:

The following steps requires that you install MSSQL server in you linux OS. If not installed please follow this guide to install the server.

After installing the MSSQL server and its command tools,

Step 1: Prepare

Move the .bak file (i.e. the backup file of the MSSQL database) into mssql opt backup folder.

$ sudo mv yourpath/yourdb.bak /var/opt/mssql/backup


Step 2: Reconnaissance

Get the names of the files compacted in the .bak file

$ sqlcmd -U yourMsSQLUSername -P password
> RESTORE FILELISTONLY FROM DISK = '/var/opt/mssql/backup/yourdb.bak'
> GO

Check the logical names and the physical names ending with .mdf and .ldf

So now we have everything we need to backup the MSSQL database. Then to backup the database.

Step 3 : Restore

Then restore with following command

> FROM DISK = '/var/opt/mssql/backup/yourdb.bak'
> WITH MOVE 'logical_name_for_mdf' to '/var/opt/mssql/data/logical_name.mdf'
> MOVE 'logical_name_for_ldf' to '/var/opt/mssql/data/logical_name.ldf'
> GO



Leave a Reply

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