现在,我需要一个新环境,并且这个新环境的数据库需要每天在最近的生产快照之上重新创建。
由于有多个数据库,我猜 Azure SQL 会很昂贵,所以我想使用 SQL Server,就像我已经在临时环境中所做的那样。
到目前为止我所做的:
RESTORE DATABASE [test1] FROM URL = 'https://<myblobaccount>.blob.core.windows.net/<container>/database_latest.bacpac'
时,它失败了:设备上的媒体系列 'https://.blob.core.windows.net//database_latest.bacpac' 形成不正确。 SQL Server 无法处理此媒体系列。
似乎无法将 Azure SQL 导出的 BACPAC 导入 SQL Server。
设备“https://.blob.core.windows.net//database_latest.bacpac”上的媒体系列格式不正确。 SQL Server 无法处理此媒体系列。
此错误的原因是恢复数据库处理
.bak
文件,并且您向其提供 .bacpac
文件。
解决方案可以按照@Martin Smith的建议使用SqlPackage.exe实用程序包,但首先您需要从blob存储下载
.bacpac
文件,您可以在cmd/powershell中使用以下命令:
Invoke-WebRequest -Uri https://storage_acc_name.blob.core.windows.net/storage_cont_name/WideWorldImporters-Standard.bacpac -OutFile "C:\destination_path\WideWorldImporters-Standard.bacpac"
文件下载后,您可以使用 SqlPackage.exe 实用程序
将其导出C:\Program Files\Microsoft SQL Server\160\DAC\bin>sqlpackage.exe /Action:Import /tsn:MSSQLSERVER01 /tdn:Importdb1 /tu:user /tp:password /sf:"C:\destination_path\WideWorldImporters-Standard.bacpac"