13

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,

2
  • What is your database size & version? Do you use In-Memory? Commented Feb 10, 2017 at 14:38
  • Where exactly you are trying to restore data, to the Image itself or in container? Commented Mar 2, 2017 at 8:04

4 Answers 4

7

@TOUDIdel You have to use the actual file system paths on linux rather than the virtual paths that are shown in the error.

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'

http://www.raditha.com/blog/archives/restoring-a-database-on-ms-sql-server-for-linux-docker/

Sign up to request clarification or add additional context in comments.

Comments

5

You didn't mention it, but the thing that tricked me up was that I wasn't copying the BAK file to my Docker instance.

In Terminal with docker and your mssql 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:
mssql -u sa -p 'myPassword'

3) restore db: (you can replace this with your restore script, though this was sufficient for me)
RESTORE DATABASE [MyDatabase] FROM DISK = N'/var/opt/mssql/backup.bak' WITH FILE = 1, NOUNLOAD, REPLACE, STATS = 5

4 Comments

During restore I receive: SQL Error [5133] [S0001]: Directory lookup for the file "c:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\database.mdf" failed with the operating system error 2(The system cannot find the file specified.). com.microsoft.sqlserver.jdbc.SQLServerException: Directory lookup for the file "c:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\database.mdf" failed with the operating system error 2(The system cannot find the file specified.).
Did you solve this? I'm getting the same issue @TOUDIdel
@TOUDIdel sorry, I was not able to replicate your error
@bluesummers: Unfortunately not
4

When I had this problem, it's because the restore command was taking long enough for mssql to time out (with a totally unhelpful error message). Specifying a long timeout when connecting allowed the restore to complete. eg

mssql -s localhost -p "<sa_password>" -t 36000000 -T 36000000

1 Comment

Kevin, Your post here just saved me hours of checking random things.
2

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'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.