Sql server keeps data after I delete all files in /var/opt/mssql/data directory (docker mount)?

VŨ DUY 20 Reputation points
2023-03-02T10:34:45.7833333+00:00

I bind mount the sqlData directory to container: -v sqlData:/var/opt/mssql/data.

Then I deleted the sqlData folder (where the .mdf ldf files are). Containers still do not lose data. And I can use backup feature to restore data.

But is there a way to restore .mdf, .ldf files?

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,361 questions
0 comments No comments
{count} votes

Accepted answer
  1. LiHongMSFT-4306 25,651 Reputation points
    2023-03-03T02:48:50.0533333+00:00

    Hi @VŨ DUY

    You could repair SQL MDF and NDF file by this TSQL command:

    EXEC sp_resetstatus [YourDatabase];
    ALTER DATABASE [YourDatabase] SET EMERGENCY
    DBCC checkdb([YourDatabase])
    ALTER DATABASE [YourDatabase] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
    DBCC CheckDB ([YourDatabase], REPAIR_ALLOW_DATA_LOSS)
    ALTER DATABASE [YourDatabase] SET MULTI_USER
    

    Please refer to this article for more details or other methods: Repair Crashed SQL Server.

    Best regards,

    Cosmog Hong


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful