在 docker 容器中恢复数据库 [英] Restore database in docker container

查看:75
本文介绍了在 docker 容器中恢复数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 docker 容器中恢复 AdventureWorks2017 数据库时出现以下错误.运行 SQL Server 2019 CTP 2.0 (mcr.microsoft.com/mssql/server:vNext-CTP2.0-ubuntu)备份和目标数据量都被持久化.创建新数据库没有问题.检查了路径,它们是正确的.使用 2017 最新版 docker 镜像恢复时没有任何问题.

Getting an error below when restoring a AdventureWorks2017 database within a docker container. Running SQL Server 2019 CTP 2.0 (mcr.microsoft.com/mssql/server:vNext-CTP2.0-ubuntu) Both backup and target data volume are persisted. No problems creating new database. Checked the paths and they are correct. Do not have any problems when restoring using 2017-latest docker image.

还有其他人在 2019-CTP2 中遇到此问题吗?解决方法?

Anybody else have this issue with 2019-CTP2, workarounds?

消息 3634,级别 16,状态 1,第 7 行操作系统返回了尝试时出现错误2(系统找不到指定的文件.)"'RestoreContainer::ValidateTargetForCreation' on'/var/opt/mssql/data/AdventureWorks2017.mdf'.消息 3156,级别 16,状态 5,第 7 行文件AdventureWorks2017"无法恢复到'/var/opt/mssql/data/AdventureWorks2017.mdf'.使用 WITH MOVE 到确定文件的有效位置.消息 3634,级别 16,状态 1,第 7 行操作系统返回错误 '2(The system can't找到指定的文件.)'同时尝试'RestoreContainer::ValidateTargetForCreation' on'/var/opt/mssql/log/AdventureWorks2017_log.ldf'.消息 3156,级别 16,状态 5,第 7 行文件AdventureWorks2017_log"无法恢复到'/var/opt/mssql/log/AdventureWorks2017_log.ldf'.使用 WITH MOVE 到确定文件的有效位置.消息 3119,级别 16,状态 1,第 7 行 规划 RESTORE 时发现的问题陈述.以前的消息提供了详细信息.消息 3013,级别 16,状态 1,第 7 行 RESTORE DATABASE 异常终止.

Msg 3634, Level 16, State 1, Line 7 The operating system returned the error '2(The system cannot find the file specified.)' while attempting 'RestoreContainer::ValidateTargetForCreation' on '/var/opt/mssql/data/AdventureWorks2017.mdf'. Msg 3156, Level 16, State 5, Line 7 File 'AdventureWorks2017' cannot be restored to '/var/opt/mssql/data/AdventureWorks2017.mdf'. Use WITH MOVE to identify a valid location for the file. Msg 3634, Level 16, State 1, Line 7 The operating system returned the error '2(The system cannot find the file specified.)' while attempting 'RestoreContainer::ValidateTargetForCreation' on '/var/opt/mssql/log/AdventureWorks2017_log.ldf'. Msg 3156, Level 16, State 5, Line 7 File 'AdventureWorks2017_log' cannot be restored to '/var/opt/mssql/log/AdventureWorks2017_log.ldf'. Use WITH MOVE to identify a valid location for the file. Msg 3119, Level 16, State 1, Line 7 Problems were identified while planning for the RESTORE statement. Previous messages provide details. Msg 3013, Level 16, State 1, Line 7 RESTORE DATABASE is terminating abnormally.

创建容器.

$datapath = "D:\Foo";
$logpath = "D:\Foo";
$backuppath = "D:\Foo";
$pass = ":-)"

$ct = (docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=$pass" `
    -e "MSSQL_PID=Developer" -p 2017:1433 `
    -e "MSSQL_TCP_PORT=1433" `
    -v ${datapath}:/var/opt/mssql/data `
    -v ${logpath}:/var/opt/mssql/log `
    -v ${backuppath}:/var/opt/mssql/backup `
    -e "MSSQL_BACKUP_DIR=/var/opt/mssql/backup" `
    -e "MSSQL_DATA_DIR=/var/opt/mssql/data" ` 
    -e "MSSQL_LOG_DIR=/var/opt/mssql/log" `
    -d mcr.microsoft.com/mssql/server:vNext-CTP2.0-ubuntu)

恢复命令.

RESTORE DATABASE [AdventureWorks2017] FROM  DISK = N'/var/opt/mssql/backup/AdventureWorks2017.bak' 
WITH  FILE = 1,  
MOVE N'AdventureWorks2017' TO N'/var/opt/mssql/data/AdventureWorks2017.mdf',  
MOVE N'AdventureWorks2017_log' TO N'/var/opt/mssql/log/AdventureWorks2017_log.ldf', 
NOUNLOAD,  STATS = 1 

推荐答案

能够解决这个问题,方法是先创建一个空数据库,然后使用替换选项进行恢复.

Was able to workaround this problem, by creating an empty database first and then restoring with replace option.

这篇关于在 docker 容器中恢复数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆