【问题标题】:New-AzWebAppBackup: Operation returned an invalid status code 'Bad Request'New-AzWebAppBackup:操作返回了无效状态代码“错误请求”
【发布时间】:2020-01-17 23:14:32
【问题描述】:

当我尝试使用New-AzWebAppBackup cmdlet 在 Azure Powershell 上执行 Azure 应用服务备份时,如下所述:

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

有人知道我错过了什么吗?我很感谢任何建议。非常感谢。

【问题讨论】:

  • 无法确定,请添加-Debug 并提供正在发送的请求和实际答案

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


【解决方案1】:

您好,欢迎来到 Stack Overflow!

希望您的 Web 应用满足能够进行备份的先决条件。备份和还原功能要求应用服务计划位于 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>"

成功执行上述命令应该可以让您创建备份。响应看起来像这样:

希望这会有所帮助!

【讨论】:

  • 嗨 :-) 完美!非常感谢。这真的帮助了我并且工作得很好。只是为了让您和所有其他可能的用户知道在最后一个带有 $sasurl 的命令中有错字。旧:New-AzureRmWebAppBackup -ResourceGroupName "" -Name "" -StorageAccountUrl $sas -BackupName "" 新:New-AzureRmWebAppBackup -ResourceGroupName "" -Name "" -StorageAccountUrl $sasurl -BackupName ""
  • @JAST 啊,很好,谢谢!很高兴知道它帮助了你。 :)
  • @JAST 看起来有编辑冲突。请随时重新提交编辑。 ;)
猜你喜欢
  • 1970-01-01
  • 2019-03-13
  • 2021-03-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-09
  • 1970-01-01
相关资源
最近更新 更多