2

I have a database backup file with .bak extension and I want to restore/ import this file to my SQL Server instance using Jetbrains IDE, i.e. DataGrip, Rider, IntelliJ etc.

I have installed a plugin from JetBrains: SQL Server Backup And Restore but haven't been able to make it work. Please help.

Link: https://plugins.jetbrains.com/plugin/13913-sql-server-backup-and-restore.

4
  • Is there any problem or error? or just you want to know the instruction? Commented Apr 17, 2023 at 6:47
  • Dear! yes I want to know the instruction. I'm using Datagrip not SQL Management Studio Commented Apr 17, 2023 at 6:58
  • DataGrip is not a SQL Server. You need to connect to a SQL Server to perform the restore, then you'll be able to use DataGrip to query the restored database. Commented Apr 17, 2023 at 8:15
  • All the information about the plug-in is provided in the Overview section. But as was mentioned by @TZHX, you should have a running SQL Server instance configured as datasource in DataGrip in order to perform actions advertised by the plug-in. If you have it set up and experiencing issues with the plug-in, you should get in touch with the plug-in author directly. To contact the author, use either Email or Issue Tracker on that page. Commented Apr 17, 2023 at 16:20

2 Answers 2

3

You don't need any plugin to do this. Just follow the Microsoft Learn docs. I'll summarize the instructions here.

  1. Get the backup file ready. For example, I downloaded AdventureWorks2022.bak file from here.

  2. Put it inside backup folder. For eg: C:\Program Files\Microsoft SQL Server\MSSQL16.MSSQLSERVER\MSSQL\Backup\ folder in Windows or /var/opt/mssql/backup/ in Linux.

  3. Run below T-SQL command to restore the database:

    For Windows

    USE [master];
    GO
    RESTORE DATABASE [AdventureWorks2022]
    FROM DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL16.MSSQLSERVER\MSSQL\Backup\AdventureWorks2022.bak'
    WITH
        FILE = 1,
        NOUNLOAD,
        STATS = 5;
    GO
    
    

    For Linux

    USE [master];
    GO
    RESTORE DATABASE [AdventureWorks2022]
    FROM DISK = '/var/opt/mssql/backup/AdventureWorks2022.bak'
    WITH
        MOVE 'AdventureWorks2022' TO '/var/opt/mssql/data/AdventureWorks2022_Data.mdf',
        MOVE 'AdventureWorks2022_log' TO '/var/opt/mssql/data/AdventureWorks2022_log.ldf',
        FILE = 1,
        NOUNLOAD,
        STATS = 5;
    GO
    
    
  4. Done!


Bonus answer: For Mac users👨‍💻 running SQL Server in a container🫙

  1. Run SQL server with -v flag. Note that I created /Users/ashk/Database/sqlserver2022 folder.

    docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=VeryStr0ngP@ssw0rd" \
        -p 1433:1433 --name sql2022 --hostname sql2022 \
        -v /Users/ashk/Database/sqlserver2022:/var/opt/mssql \
        -d \
        mcr.microsoft.com/mssql/server:2022-latest
    
  2. Create backup folder inside /Users/ashk/Database/sqlserver2022 folder.

  3. Get the .bak file ready. For example, I downloaded AdventureWorks2022.bak file from here.

  4. Put the .bak file inside /Users/ashk/Database/sqlserver2022/backup folder.

  5. Go to Database window in your JetBrains IDE and connect to the database using connection string. For eg:

    open database window
    Server=localhost,1433;User Id=sa;Password=VeryStr0ngP@ssw0rd
    
    use connection string
  6. Open Query Console

    shows console
  7. Run below T-SQL command to restore the database:

    USE [master];
    GO
    RESTORE DATABASE [AdventureWorks2022]
    FROM DISK = '/var/opt/mssql/backup/AdventureWorks2022.bak'
    WITH
        MOVE 'AdventureWorks2022' TO '/var/opt/mssql/data/AdventureWorks2022_Data.mdf',
        MOVE 'AdventureWorks2022_log' TO '/var/opt/mssql/data/AdventureWorks2022_log.ldf',
        FILE = 1,
        NOUNLOAD,
        STATS = 5;
    GO
    
    
  8. Click the tag (for eg: 1 of 5) next to the Db server name (for eg: @localhost) and select the Database you just added (for eg: AdventureWorks2022), expand it and select the schemas you want to load.

    select database
  9. Done!

    database imported
Sign up to request clarification or add additional context in comments.

Comments

1

To restore from .bak file you need:

  1. Select the data source where you intend to restore the backup selecting data source to restore backup to

  2. Choose .bak file and click OK locating bak file to restore from

  3. Specify database name and click OK specifying database name

2 Comments

Thanks for your feedback. I'm on Windows OS (DataGrip 2022.1.4) there is no Backup/Restore option here. screenshot: Screen-Capture
A bit strange, could you contact plugin author for your problem investigation?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.