Restore SQL Server database to Linux Docker Restore SQL Server database to Linux Docker docker docker

Restore SQL Server database to Linux Docker


@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/


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


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