Error trying to import . Bak file from Sql Server on Linux

Asked

Viewed 361 times

2

I am very beginner in SQL Server and am trying to import a file . Bak from a backup that came from another server (Windows) on Linux (Linux Mint 19)

The command I used in the terminal was that:

sqlcmd -S localhost -U SA -Q "RESTORE DATABASE [demodb] FROM DISK = N'/home/usuario/html/projeto_sql/backup.bak' WITH FILE = 1, NOUNLOAD, REPLACE, STATS = 5"

The mistakes are:

Msg 5133, Level 16, State 1, Server homepc, Line 1
Directory lookup for the file "E:\Banco Dados\Banco1.mdf" failed with the operating system error 2(The system cannot find the file specified.).

Msg 3156, Level 16, State 3, Server homepc, Line 1
File 'Banco1' cannot be restored to 'E:\Banco Dados\Banco1.mdf'. Use WITH MOVE to identify a valid location for the file.

Msg 5133, Level 16, State 1, Server homepc, Line 1
Directory lookup for the file "E:\Banco Dados\Banco1_log.ldf" failed with the operating system error 2(The system cannot find the file specified.).

Msg 3156, Level 16, State 3, Server homepc, Line 1
File 'Banco1_log' cannot be restored to 'E:\Banco Dados\Banco1_log.ldf'. Use WITH MOVE to identify a valid location for the file.

Msg 3119, Level 16, State 1, Server homepc, Line 1
Problems were identified while planning for the RESTORE statement. Previous messages provide details.

Msg 3013, Level 16, State 1, Server homepc, Line 1
RESTORE DATABASE is terminating abnormally.

OBS:

  1. My version of SQL SERVER running is

    Microsoft SQL Server 2017 (RTM-CU13) (KB4466404) - 14.0.3048.4 (X64) Nov 30 2018 12:57:58 Copyright (C) 2017 Microsoft Corporation Developer Edition (64-bit) on Linux (Linux Mint 19.1)

  2. I don’t know which version of SQL Server/ or how the file . Bak was created, it matters?

  3. I come from Mysql, there is some kind of file . sql that can be created or SQL Server backup needs several files and not only . Bak?

  • Installing SQL Server 2017 for Linux was via Docker?

  • No, I installed following the manual on microsoft website same

1 answer

1

SQL Server 2017 for Linux is compatible with Ubuntu 16.04; I don’t know if it is stable in Linux Mint 19.1, which is derived from Ubuntu 18.04. In the article Installing SQL Server 2017 for Linux on Ubuntu 18.04 LTS how to install SQL Server 2017 for Linux on Ubuntu 18.04.

The REPLACE option is only required when the database already exists and you want to replace it with the backup contents. As the database was created in another operating environment, remove the REPLACE and use WITH MOVE. The complete instructions on how to restore the backup in the GNU/linux distribution are at Migrate a SQL Server database from Windows to Linux using backup and Restore.

Example:

RESTORE DATABASE Banco1 
   FROM DISK = '/home/usuario/html/projeto_sql/backup.bak'
   WITH MOVE 'Banco1' TO '/home/usuario/html/projeto_sql/Banco1.mdf',
        MOVE 'Banco1_Log' TO '/home/usuario/html/projeto_sql/Banco1_Log.ldf'
GO

I suggest you install Azure Data Studio to manipulate SQL Server directly in the GNU/Linux environment, in a graphical interface. Get it from SQL Port, menu SQL Server, item download.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.