New-AzWebAppBackup:操作返回了无效的状态码“ Bad Request”

时间:2020-01-17 23:14:32

标签: azure powershell azure-web-app-service backup

当我尝试使用New-AzWebAppBackup cmdlet通过Azure Powershell执行Azure App Service备份时,如下所述:

https://docs.microsoft.com/en-us/powershell/module/az.websites/New-AzWebAppBackup?view=azps-3.3.0

我收到以下错误消息:

PS Azure:\> New-AzWebAppBackup -ResourceGroupName "MyResourceGroup" -Name "MyWebApp" -StorageAccountUrl "https://mystorageaccount.file.core.windows.net/"
New-AzWebAppBackup : Operation returned an invalid status code 'BadRequest'
At line:1 char:1
+ New-AzWebAppBackup -ResourceGroupName "MyResourceGroup" -Name " ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : CloseError: (:) [New-AzWebAppBackup], DefaultErrorResponseException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.WebApps.Cmdlets.WebApps.NewAzureWebAppBackup

Azure Powershell Screenshot

有人知道我想念什么吗?感谢您的建议。非常感谢。

1 个答案:

答案 0 :(得分:1)

您好,欢迎来到Stack Overflow!

希望您的Web应用程序满足能够进行备份的先决条件。备份和还原功能要求App Service计划位于 Standard 层或 Premium 层。有关完整的详细信息,请参见Requirements and restrictions

我在执行cmdlet时最初遇到了相同的错误。但是,通过cmdlet传递-debug开关可以帮助我更好地理解错误:

{
 "ErrorEntity": {
 "ExtendedCode": "04205",
 "MessageTemplate": "The provided URI is not a SAS URL for a container (it needs to be https and it has to have 2 segments).",
 "Parameters": [],
 "Code": "BadRequest",
 "Message": "The provided URI is not a SAS URL for a container (it needs to be https and it has to have 2 segments)."
}

-StorageAccountUrl参数要求传递SAS URL(请参阅this文档)。您的存储帐户的SAS URL格式为:

sasurl=https://$storagename.blob.core.windows.net/$container$sastoken

要生成SAS令牌,请运行以下命令:

# Retrieve one of the Storage Account keys
$key = (Get-AzStorageAccountKey -ResourceGroupName "<rg-name>" -AccountName "<storage-account-name>").Value[0]

# Populate the Storage Account context
$ctx = New-AzureStorageContext -StorageAccountName "<storage-account-name>" -StorageAccountKey $key

# Generate the SAS token
$sastoken = New-AzureStorageContainerSASToken -Name "<container-name>" -Permission rwdl -Context $ctx

# Generate the SAS URL
$sasurl = "https://<storage-account-name>.blob.core.windows.net/<container-name>$sastoken"

# Create a backup
New-AzureRmWebAppBackup -ResourceGroupName "<rg-name>" -Name "<app-name>" -StorageAccountUrl $sas -BackupName "<backup-name>"

成功执行上述命令应该可以创建备份。响应如下所示: webapp backup

希望这会有所帮助!