Caza
Caza

Reputation: 35

Docker - duplicate mssql database

I'm working with docker to test a web application, and this application needs a database. I copied my application in a tomcat container and created a mssql container.

However, I need to copy my mssql database located in a server called "tstsupsq" with all datas (not only the schema) in my mssql container.

PS : I don't have access to mdf files of the tstsupsq server

Do someone can help me ?

Thanks

EDIT :

After many tries, I fixed this issue with command lines.

How to copy mssql database from any server to docker with command lines :

sqlcmd.exe -S myServer -U myUser -P myPassword -Q "BACKUP DATABASE [databaseName] TO DISK='backupLocation\databaseName.bak'"

docker run -d -p 1433:1433 -e ACCEPT_EULA=Y -e SA_PASSWORD=myPassword --name containerName microsoft/mssql-server-linux:latest

docker cp backupLocation\databaseName.bak containerName:/var/opt/mssql/data

docker exec -it containerName /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P myPassword -Q "RESTORE DATABASE [databaseName] FROM DISK='/var/opt/mssql/data\databaseName.bak' WITH MOVE 'databaseName' TO '/var/opt/mssql/data/databaseName.mdf', MOVE 'databaseName_Log' TO '/var/opt/mssql/data/databaseName.ldf'"

Your database is now avaible with all its datas in your docker container.

Upvotes: 0

Views: 1102

Answers (1)

neer
neer

Reputation: 4082

Use cp command to copy your bak file to container

docker cp YourDbBackup.bak YourContainer:/YourDbBackup.bak

Then use SSMS to restore bak file.

Upvotes: 1

Related Questions