Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restore SQL Server database to Linux Docker

I need to restore a large SQL Server database on a Linux Docker instance (https://hub.docker.com/r/microsoft/mssql-server-linux/)

I'm moving my .bak file to the docker and executing this command in mssql shell:

RESTORE DATABASE gIMM_Brag FROM DISK = '/var/opt/mssql/backup/BackupFull8H_gIMM.bak' WITH MOVE '[gIMM].Data' T'/var/opt/mssql/data/gIMM.mdf', MOVE '[gIMM].Log' TO '/var/opt/mssql/data/gIMM.ldf', MOVE 'TraceabilityData' TO '/var/opt/mssql/data/gIMM.TraceData.mdf', MOVE 'TraceabilityIndexes' TO '/var/opt/mssql/data/gIMM.TraceIndex.mdf', MOVE 'KpiData' TO '/var/opt/mssql/data/gIMM.KpiData.mdf', MOVE 'KpiIndexes' TO '/var/opt/mssql/data/gIMM.KpiIndex.mdf'

I'm mapping correctly every file that need to and I definitely have enough space on the docker instance but I'm getting this error:

Error: The backup or restore was aborted.

The same error occurs with a windows version of this docker actually... And as it's not supposed to be a Express version, the database size shouldn't be the issue here.

If anyone has more information about what is causing this error !

Thanks,

like image 782
Vincent Avatar asked Jan 18 '17 10:01

Vincent


People also ask

Can you Dockerize SQL Server?

You can connect to the SQL Server instance on your Docker machine from any external Linux, Windows, or macOS tool that supports SQL connections. Some common tools include: sqlcmd. Azure Data Studio.

How do I run a SQL database in Docker?

Here are the steps you can follow to set up and deploy a SQL Server Docker Container seamlessly: SQL Server Docker Setup: Install Docker on your System. SQL Server Docker Setup: Execute and Run Docker. SQL Server Docker Setup: Pull & Run the Docker Image for SQL Server.

How do I restore an existing SQL Server database?

Open Microsoft SQL Server Management Studio. In the left navigation bar, right-click on Databases and then click Restore Database. In the Source section, select Device and click the button with three dots. In the pop up window that opens, click Add and browse for your backup file.

Can a database server run inside a docker container?

In ConclusionDocker is great for running databases in a development environment! You can even use it for databases of small, non-critical projects which run on a single server. Just make sure to have regular backups (as you should in any case), and you'll be fine.


1 Answers

I am not sure it is worth mentioning, but neither of the answers alone worked when moving a .bak made in Windows server to the docker running in Linux version.

(Note that I am using the code from the two previous answers and thus any credit should go to the below-mentioned authors)

TabsNotSpaces' solution was good until step 3 where the restore crashed with path mismatch (C:/path_to_mssql_server could not be found).

Vinicius Krauspenhar's answer was then necessary to remap the MDF and LOG files to fully complete the backup.

Thus the solution that worked for me when importing a windows-server-made .bak file into the Linux docker instance was:

In Terminal with docker and your SQL Server container running...

1) get container ID: $docker inspect -f '{{.Id}}' <container_name>

2) copy BAK file to docker instance: docker exec -i <container_id> bash -c 'cat > /var/opt/mssql/backup.bak' < '/source/path/backup.bak'

3) log into mssql or in any DB software and RESTORE DATABASE Northwind FROM DISK='/var/opt/mssql/Northwind.bak' WITH MOVE 'Northwind' TO '/var/opt/mssql/data/NORTHWND.MDF', MOVE 'Northwind_log' TO '/var/opt/mssql/data/NORTHWND_log.ldf'

like image 111
Simas Joneliunas Avatar answered Oct 09 '22 15:10

Simas Joneliunas