Skip to content

Instantly share code, notes, and snippets.

@rhuanbarreto
Created April 12, 2018 12:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rhuanbarreto/7000c5f3ac47b3d17ff264e03d0c1faa to your computer and use it in GitHub Desktop.
Save rhuanbarreto/7000c5f3ac47b3d17ff264e03d0c1faa to your computer and use it in GitHub Desktop.
Import Database from Backup File on SQL Server for Linux / Docker
# Copy backup file to Docker Container
# Remember to name your container with the --name parameter on docker start, so you can
# replace the SQL_Server name on the following command.
# Remember also to change the backup file path.
docker cp ~/database.bak SQL_Server:/var/opt/mssql/data/
-- Use the following command to list the contents of the backup file.
-- Change database.bak for the file that you copied to your machine or container
-- The root path to sql server files is /var/opt/mssql/data/
RESTORE FILELISTONLY
FROM DISK = '/var/opt/mssql/data/database.bak'
GO
-- Use the column LogicalName from the result o the command above to fill
-- the fields database_Data and database_Log on the following command.
-- Don't forget to change the backup file path and destination mdf and ldf file paths
RESTORE DATABASE NAV_ODS_2016
FROM DISK = '/var/opt/mssql/data/database.bak'
WITH MOVE 'database_Data' TO '/var/opt/mssql/data/database.mdf',
MOVE 'database_Log' TO '/var/opt/mssql/data/database.ldf'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment