无法使用Azure Cli az webapp配置备份创建备份功能/ Web应用程序

时间:2020-09-22 09:05:18

标签: azure azure-cli azure-function-app azure-appservice azure-cli2

执行Azure Cli命令备份我的Azure App Service时遇到问题:

Cli命令:

az webapp配置备份创建--resource-group --webapp-name
--backup-name testbackup --container-url

我生成了一个新的SaS密钥,将其与命令一起传递。

这是正确的方法吗?

Cli输出:

{ "backupId": 64862, "backupItemName": "testbackup", "blobName": "testbackup", "correlationId": "3e9ae4d0-9aa9-46e0-9926-53ec1ef6ef2c", "created": "2020-09-22T08:50:35.555268+00:00", "databases": null, "finishedTimeStamp": null, "id": "value", "kind": null, "lastRestoreTimeStamp": null, "location": "Central US", "log": null, "name": "testbackuppr", "resourceGroup": "RG-POC", "scheduled": false, **"sizeInBytes": 0,** "status": "Created", "storageAccountUrl": "", "type": "Microsoft.Web/sites", "websiteSizeInBytes": null }

门户中的日志信息:存储访问失败。远程服务器返回错误:(404)找不到。。请删除并重新创建备份计划以减轻压力。

Error Message when executing the command

1 个答案:

答案 0 :(得分:0)

似乎存储帐户或其访问权限不正确。在执行az webapp config backup create命令之前,请确保您具有有效的存储帐户,存储容器和具有适当到期日期的SAS令牌。可以使用az storage container generate-sas命令生成SAS令牌。

以下脚本对我有用:

#!/bin/bash

groupname="myResourceGroup"
planname="myAppServicePlan"
webappname=mywebapp$RANDOM
storagename=mywebappstorage$RANDOM
location="WestEurope"
container="appbackup"
backupname="backup1"
expirydate=$(date -I -d "$(date) + 1 month")

# Create a Resource Group 
az group create --name $groupname --location $location

# Create a Storage Account
az storage account create --name $storagename --resource-group $groupname --location $location \
--sku Standard_LRS

# Create a storage container
az storage container create --account-name $storagename --name $container

# Generates an SAS token for the storage container, valid for one month.
# NOTE: You can use the same SAS token to make backups in App Service until --expiry
sastoken=$(az storage container generate-sas --account-name $storagename --name $container \
--expiry $expirydate --permissions rwdl --output tsv)

# Construct the SAS URL for the container
sasurl=https://$storagename.blob.core.windows.net/$container?$sastoken

# Create an App Service plan in Standard tier. Standard tier allows one backup per day.
az appservice plan create --name $planname --resource-group $groupname --location $location \
--sku S1

# Create a web app
az webapp create --name $webappname --plan $planname --resource-group $groupname

# Create a one-time backup
az webapp config backup create --resource-group $groupname --webapp-name $webappname \
--backup-name $backupname --container-url $sasurl

# List statuses of all backups that are complete or currently executing.
az webapp config backup list --resource-group $groupname --webapp-name $webappname

输出将类似于: Output

参考: