无法使用T-SQL从blob容器还原数据库

问题描述 投票:0回答:1

我正在将我的数据库备份到Azure blob存储。我可以从维护计划中备份和恢复。但是,我无法使用脚本还原数据库。下面是我使用的T-SQL:

RESTORE DATABASE database_name
FROM URL = 'https://StorageAccount.blob.core/Container/FileName.bak'
WITH CREDENTIAL   = 'https://StorageAccount.blob.core.windows.net/Container', STATS = 10

我收到此错误:

Msg 3225,Level 16,State 1,Line 1 使用WITH CREDENTIAL语法对包含共享访问签名的凭据无效。

Msg 3013,Level 16,State 1,Line 1 RESTORE DATABASE异常终止。

你能帮忙吗?

azure-storage-blobs restore sql-server-2017
1个回答
0
投票

更新:如何将其标记为答案:

在我的帖子的左侧,你可以看到类似下面的截图,只需点击它变成绿色:

enter image description here

您的凭据有误,请点击此链接到create a credential

CREATE CREDENTIAL mycredential   
WITH IDENTITY= 'msftutorialstorage', -- this is the name of the storage account you specified when creating a storage account   
SECRET = '<storage account access key>' -- this should be either the Primary or Secondary Access Key for the storage account

然后在您的还原代码中,使用此凭据,如下所示:

RESTORE DATABASE AdventureWorks2016 
FROM URL = 'https://msftutorialstorage.blob.core.windows.net/sql-backup/AdventureWorks2016.bak' 
WITH CREDENTIAL = 'mycredential',
STATS = 5 -- use this to see monitor the progress
GO
© www.soinside.com 2019 - 2024. All rights reserved.