简体   繁体   English

如何在 SQL 服务器容器中更改数据库备份的文件所有权

[英]How to change file ownership of DB backup in SQL Server container

I'm following this guide to restore a database backup https://docs.microsoft.com/en-us/sql/linux/tutorial-restore-backup-in-sql-server-container?view=sql-server-ver15我正在按照本指南恢复数据库备份https://docs.microsoft.com/en-us/sql/linux/tutorial-restore-backup-in-sql-server-container?view=sql-server-ver15

I used docker cp command to copy the DB backup files to the container docker exec -it SQLContainer mkdir /var/opt/mssql/backup我使用 docker cp 命令将数据库备份文件复制到容器 docker exec -it SQLContainer mkdir /var/opt/mssql/backup

docker cp MyDb.bak SQLContainer:/var/opt/mssql/backup/

However when trying to restore the DB by running the following query in SSMS, an error message is shown但是,当尝试通过在 SSMS 中运行以下查询来恢复数据库时,会显示一条错误消息

RESTORE DATABASE MyDB FROM DISK='/var/opt/mssql/backup/MyDB.bak'

Operating system error 5(Access is denied.).

I tried copying using docker cp -a, which sets file ownership to same as destination, but I got this error.我尝试使用 docker cp -a 进行复制,它将文件所有权设置为与目标相同,但出现此错误。

docker cp -a MyDb.bak SQLContainer:/var/opt/mssql/backup/

Error response from daemon: getent unable to find entry "mssql" in passwd database

I'm using Microsoft's image and I don't know the password for root user, the container runs using mssql user, so chown doesn't work either.我使用的是微软的镜像,我不知道root用户的密码,容器使用mssql用户运行,所以chown也不起作用。 How can I change the file permissions so DB restore works?如何更改文件权限以便数据库恢复正常工作?

Turns out when I copied the database backup files from the Windows host to the Ubuntu machine, the files were owned by root user and all other users didn't have read permission.原来,当我将数据库备份文件从 Windows 主机复制到 Ubuntu 机器时,这些文件归 root 用户所有,所有其他用户都没有读取权限。 Adding read permission to the file before copying to the docker container works and the server was able to read the files.在复制到 docker 容器之前向文件添加读取权限可以正常工作,并且服务器能够读取文件。

sudo chmod a+r MyDb.bak

sudo docker cp MyDb.bak SQLContainer:/var/opt/mssql/backup/

I had a similar issue just today, about the same time as this incident, just attaching MDF and LDF files.我今天也遇到了类似的问题,和这次事件差不多,只是附加了 MDF 和 LDF 文件。

By doing the chmod go+w before copying files without the -a I was able to get SQL Server to treat them as writeable.通过在没有 -a 的情况下复制文件之前执行 chmod go+w,我能够让 SQL 服务器将它们视为可写。 Prior to that I was getting error messages whenever any update was performed.在此之前,每当执行任何更新时,我都会收到错误消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM