SQL Server in Docker restore the database

Last time demonstrates how to install SQL Server in Docker environment at this time we 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.
SQL Server in Docker restore the database
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

SQL Server in Docker restore the database
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

SQL Server in Docker restore the database
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"'

SQL Server in Docker restore the database


SQL Server in Docker restore the database
See RESTORE DATABASE successfully represented when the database is restored successfully. Let's see if the database using SSMS really restore a success.
SQL Server in Docker restore the database
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.linuxidc.com/Linux/2019-08/159788.htm