Restore a MSSQL database from SQL

If you really want to restore a .bak
into a MSSQL
database, then do this
RESTORE DATABASE [database] FROM DISK = N'/mnt/data/database.bak'
WITH MOVE N'database' TO N'/var/opt/mssql/data/database.mdf',
MOVE N'database_Log' TO N'/var/opt/mssql/log/database.ldf',
RECOVERY,
REPLACE;
Easy!
This is quite useful if you have a .bak
file at your hand (maybe you have downloaded it from some internal file repository), or have some base data that you want to load into a fresh database (if you want to test out something on localhost). If you have a docker
setup, then it is easy to map the .bak
into your image, just use the -v
parameter, when you call docker run
: docker run -v /local/path:/docker/path alpine
. Then you could have a local directory with your .bak
files, fx called mssql
, and then map it into your docker container, and then have script that connects to the docker container, and fires the above piece of sql!
Nice!!
Read other posts