SQL Server in Docker - Restore database

SQL Server in Docker restore the database

A demonstration of the will if you install SQL Server at Docker environment, we at this time to demonstrate how to restore a database backup files to the database instance.

Use winscp upload files to the linux server bak

Last time we start docker container using the -v parameter losses the local directory / hd2 / sqlserver2019_data into the container directory / var / opt / mssql, so we just need to upload files testdb.bak / hd2 / sqlserver2019_data directory, docker container to access.

I used the next Sql Server Management Studio Restore Features tried, without success, maybe it is SSMS version of the problem. Since SSMS can not be restored, then use the command line to try it.

Use docker exec command execution command in the container

Because SQL Server is installed in a Docker container, so the need to execute the command rows into the container.

sudo docker exec -it sqlserver2019 /bin/bash


The following commands are all performed in sqlserver2019 container.

Use RESTORE FILELISTONLY command to list the logical name of the backup data file

/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'dev@123,' -Q 'RESTORE FILELISTONLY FROM DISK = "/var/opt/mssql/testdb.bak"' | tr -s ' ' | cut -d ' ' -f 1-2


Use this command to the database data files, log file name is displayed. Useful in the next recovery operation.

Use RESTORE DATABASE command to restore the database

/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'dev@123,' -Q 'RESTORE DATABASE testdb FROM DISK = "/var/opt/mssql/testdb.bak" WITH MOVE "testdb" TO "/var/opt/mssql/data/testdb.mdf" , MOVE "testdb_log" TO "/var/opt/mssql/data/testdb.ldf"'



See RESTORE DATABASE successfully represented when the database is restored successfully. Let's see if the database using SSMS really restore a success.

Can restore the database has up inside the table, the data can be normal operation. So far, the database file restore success.

Guess you like

Origin www.cnblogs.com/kklldog/p/sqlserver_in_docker_restore.html