Categories
Sql Server

How to Restore SQL Server database from Windows to SQL Server on Linux

Restore SQL Server database from Windows to SQL Server on Linux

Hi friends, in this post we are going to learn How to Restore SQL Server database from Windows to SQL Server on Linux. Recently SQL Server team releases SQL Server vNext CTP 1.4 for Linux, and to migrate SQL Sever from windows to SQL Server on Linux backup and restore is best method and recommended by Microsoft also.

First of all we have to take a backup of our database from windows machine and then transfer it to Linux machine, for that you can use Putty or scp. Now transfer this backup file to backup directory in /var/opt/mssql.

To create backup directory in /var/opt/mssql use below command:

mkdir /var/opt/mssql/backup

Move command:

mv /home/user1/testdb.bak /var/opt/mssql/backup/

Now connect to SQL Server instance with sqlcmd.

sqlcmd -S loclahost -u SA

It will prompt for password, enter SA password.

After connecting, enter the following RESTORE DATABASE command to restore TestDB database.

restore database TestDB from disk='/var/opt/mssql/backup/testdb.bak' with move 'TestDB' TO
 '/var/opt/mssql/Data/TestDB.mdf', move 'TestDB_log' To '/var/opt/mssql/log/TestDB.ldf'

You should get a message the database is successfully restored. Verify the restoration by first changing the context to the TestDB database.

use TestDB

Run the following query that lists all record in a table.

select * from table_name

Video Tutorial: