使用 AD DS 切换到 Azure Storage Gen2 后,SSMS 备份和还原 SQL 到 Blob 的数据库停止工作

SSMS Back-up and Restore SQL Database to Blob Stopped Working After Switch to Azure Storage Gen2 with AD DS

几个月前,我们的团队按照此 Microsoft Tutorial 将数据库备份和恢复到 blob 存储容器,使我们能够将大型数据库附加到我们的 SQL 服务器实例,但是由 blob 而不是昂贵的磁盘支持。

RESTORE DATABASE SomeDatabase
    FROM URL = 'https://azeusanblbstranonimized.blob.core.windows.net/sql-storage/SomeDatabase.bak'
    WITH
        MOVE 'some_database_data' TO 'https://azeusanblbstranonimized.blob.core.windows.net/sql-storage/SomeDatabase.mdf',
        MOVE 'some_database_log'  TO 'https://azeusanblbstranonimized.blob.core.windows.net/sql-storage/SomeDatabase.ldf'
, REPLACE

我们成功了,并以这种方式附加了大约 20 个数据库。就在上周,我们配置了一个启用了“分层命名空间”的新 Azure Storage Gen2 帐户,复制了所有旧存储帐户配置和数据,并将所有内容切换到它。唯一坏掉的是这个脚本。现在当它运行时,我们得到以下错误(为便于阅读而格式化):

Operation on target Move Database to Blob failed: Execution fail against sql server. Sql error number: 3634. Error Message:

The operating system returned the error '13(The data is invalid.)' while attempting 'RestoreContainer::ValidateTargetForCreation' on 'https://azeusanblbstranonimized.blob.core.windows.net/sql-storage/SomeDatabase.mdf'. File 'some_database_data' cannot be restored to 'https://azeusanblbstranonimized.blob.core.windows.net/sql-storage/SomeDatabase.mdf'. Use WITH MOVE to identify a valid location for the file.

The operating system returned the error '13(The data is invalid.)' while attempting 'RestoreContainer::ValidateTargetForCreation' on 'https://azeusanblbstranonimized.blob.core.windows.net/sql-storage/SomeDatabase.ldf'. File 'some_database_log' cannot be restored to 'https://azeusanblbstranonimized.blob.core.windows.net/sql-storage/SomeDatabase.ldf'. Use WITH MOVE to identify a valid location for the file.

在规划 RESTORE 语句时发现了问题。以前的消息提供了详细信息。 RESTORE DATABASE 异常终止。 为文件 1 上的数据库 'SomeDatabase'、文件 'some_database' 处理了 816 页。为文件 1 上的数据库 'SomeDatabase'、文件 'some_database_log' 处理了 2 页。BACKUP DATABASE 在 0.431 中成功处理了 818 页秒(14.827 MB/sec)。不合格的事务正在回滚。预计回滚完成:0%。不合格的事务正在回滚。预计回滚完成:100%。无法将数据库 'SomeDatabase' 中的文件“2”缩小到 1280 页,因为它只包含 352 页。 DBCC 执行完成。如果 DBCC 打印出错误消息,请联系您的系统管理员。

我的猜测是引用的错误 13(The data is invalid.) 有点转移注意力。作为健全性检查,我们尝试将备份(仍在 blob 上)恢复到 SQL 服务器的本地磁盘,并且工作正常(RESTORE VERIFYONLY FROM URL = 'https://azeusanblbstranonimized.blob.core.windows.net/sql-storage/SomeDatabase.bak' 也是如此)——所以 .bak 文件本身,从 blob 读取它没有问题,只是 SSMS 将 .mdf/.ldf 放在 blob 上突然出现问题。

我希望利用此功能的其他人了解 Gen2 blob 存储的一些细微差别,可能需要调整脚本才能继续工作。

一些可能很重要的细节:


值得注意的是,我什至无法遵循在 blob 存储上创建新数据库的最基本教程。当目标 blob 服务器是 Azure Data Lake Gen2 存储容器时,也会出现同样的错误:

CREATE DATABASE testdb   
ON     ( NAME = testdb_dat, FILENAME = 'https://azeusanblbstranonimized.blob.core.windows.net/sql-storagee/TestData.mdf' )  
LOG ON ( NAME = testdb_log, FILENAME = 'https://azeusanblbstranonimized.blob.core.windows.net/sql-storage/TestLog.ldf')  

Msg 5120, Level 16, State 156, Line 1 Unable to open the physical file "https://azeusanblbstranonimized.blob.core.windows.net/sql-storage/TestData.mdf". Operating system error 13: "13(The data is invalid.)". Msg 1802, Level 16, State 4, Line 1 CREATE DATABASE failed. Some file names listed could not be created. Check related errors.

得到了微软付费支持的回复。

Hello Alain,

We were able to complete the investigation and confirm we cannot use ADLS to store SQL Server datafiles because it uses Block Blob. We only use Page Blobs for storing data on Azure Storage due to requirement for Random writes.

We are working on updating the document to explicitly document the same about the supportability of ADLS Gen2.

Thank you once again for bring this to us and we hope to have this feature in future.

简而言之,Gen2 的 Blob 存储 known issue 不支持 PUT PageGET Page Ranges 的 Blob REST API。 SQL 在幕后使用这些 API,因此当指向 Gen2 容器时该功能会中断。


不幸的是,tutorial 没有披露有关将数据库放置在 blob 上的详细信息。事实上,上面的文章声称页面和块 blob 都可以使用,块 blob 是首选 - 但事实证明这是错误的。即使按照步骤使用块 blob,页面 blob API 也会在幕后使用,因此会引发上述错误。

我在 Microsoft 上只找到一个其他教程暗示在 blob 上存储 SQL 文件的功能:SQL Server data files in Microsoft Azure

在这种情况下,文档中实际上有一个提示,说明事情可能会向南发展:

This new feature uses Page blobs, which are more efficient when ranges of bytes in a file are modified frequently.