Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot open backup device '/var/opt/mssql/backup/MyDB.bak'. Operating system error 5(Access is denied.)

I found a lot of cases, where people try to open a file from outside the docker container. But mine is clearly inside.

The whole message I am getting is:

$ /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "mypw" -Q 
"RESTORE FILELISTONLY FROM DISK = '/var/opt/mssql/backup/MyDB.bak'"
Msg 3201, Level 16, State 2, Server 1c7bf85afdaf, Line 1
Cannot open backup device '/var/opt/mssql/backup/MyDB.bak'. Operating system error 5(Access is denied.).
Msg 3013, Level 16, State 1, Server 1c7bf85afdaf, Line 1
RESTORE FILELIST is terminating abnormally.

Same happens when I try to actually restore the database. Any idea what is going wrong?

I have the feeling it might be some permission things where need to change permissions for the file

$ ls -la var/opt/mssql/backup/MyDB.bak
-rw-r----- 1 501 dialout 3395584 Jan 16 02:12 var/opt/mssql/backup/MyDB.bak
like image 229
Julian Avatar asked Jan 16 '20 20:01

Julian


People also ask

What is operating system error 5?

However, in the majority of cases, “System error 5 has occurred' emerges due to the lack of administrative privileges. Even if the PC user is logged into the system as an administrator, Command Prompt may deny access if it is not run as administrator.


1 Answers

The solution was to change the permission of the file. I needed to do:

docker exec -it -u root MicrosoftSQLServer "bash"

Then change the user (whoami returns mssql when I run the docker container not as root)

chown mssql /var/opt/mssql/backup/TestDB.bak

And then it works.

like image 161
Julian Avatar answered Sep 18 '22 17:09

Julian