Search code examples
sql-servermacosazuredockerazure-sql-database

Physical Folder of SQL Server Using Docker Connection


I'm working on Visual Studio and for the database Azure Data Studio, I need MS SQL Server since my OS is Mac I have to use Docker to create the connection. The only problem I have is when I back up the database, it's saved in a virtual folder where I cannot use it in Visual Studio. How can I find or backup my database so I can use it? The virtual folders when I choose to back up the database

I expect to find a physical folder of my database.


Solution

  • Here's the tutorial SQL Server : Backup and Restore on Docker can help you copy the backup file from the running container to the host(actual machine where docker container is running).

    Summary:

    We will be using SQL Operations studio to run our Backup and Restore queries. To take the backup, you need to execute the following query in your query window –

    BACKUP DATABASE project1 TO DISK = N’/var/opt/mssql/data/project1.bak’
    GO
    

    where DISK=”Specify the location where you want to generate the backup of your database in your container” enter image description here

    This query will generate the backup file(.bak) inside the container. To restore it to somewhere else, we need to first copy the backup file from the running container to the host(actual machine where docker container is running).

    Going back to the terminal and running the following docker copy command –

    docker cp mssqlserver:/var/opt/mssql/data/project1.bak /Users/jbond/
    

    where,

    • mssqlserver= Name of our running container
    • /var/opt/mssql/data/project1.bak = Path of our backup file inside our container
    • /Users/jbond/ = Path where we want to copy the file(Host Machine) enter image description here

    Now I’m going to restore it to the SQL Server running on my windows machine.

    Note: Since I took the backup on SQL Server version 2017, I need to restore it on the same version for compatibility.

    Hope this helps.