使用 CLI 从备份中还原 Web 应用Restore a web app from a backup using CLI

此示例脚本使用其相关资源,在应用服务中创建 Web 应用,然后为其创建一次性备份。This sample script creates a web app in App Service with its related resources, and then creates a one-time backup for it.

若要运行此脚本,需要 Web 应用的现有备份。To run this script, you need an existing backup for a web app. 若要创建备份,请参阅备份 Web 应用创建 Web 应用的计划备份To create one, see Backup up a web app or Create a scheduled backup for a web app.

如果选择在本地安装并使用 CLI,则需使用 Azure CLI 2.0 或更高版本。If you choose to install and use the CLI locally, you need Azure CLI version 2.0 or later. 若要查找版本,请运行 az --versionTo find the version, run az --version. 如需进行安装或升级,请参阅安装 Azure CLIIf you need to install or upgrade, see Install the Azure CLI.

示例脚本Sample script

#!/bin/bash

groupname="myResourceGroup"
webappname="<replace-with-your-app-name>"

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

# Note the backupItemName and storageAccountUrl properties of the backup you want to restore

# Restore the app by overwriting it with the backup data
# Be sure to replace <backupItemName> and <storageAccountUrl>
az webapp config backup restore --resource-group $groupname --webapp-name $webappname \
--backup-name <backupItemName> --container-url <storageAccountUrl> --overwrite

清理部署Clean up deployment

运行示例脚本后,可以使用以下命令删除资源组以及与其关联的所有资源。After the sample script has been run, the following command can be used to remove the resource group and all resources associated with it.

az group delete --name myResourceGroup

脚本说明Script explanation

此脚本使用以下命令。This script uses the following commands. 表中的每条命令均链接到特定于命令的文档。Each command in the table links to command specific documentation.

命令Command 注释Notes
az webapp config backup list 获取 Web 应用的备份列表。Gets a list of backups for a web app.
az webapp config backup restore 从备份中还原 Web 应用。Restores a web app from a backup.

后续步骤Next steps

有关 Azure CLI 的详细信息,请参阅 Azure CLI 文档For more information on the Azure CLI, see Azure CLI documentation.

可以在 Azure 应用服务文档中找到其他应用服务 CLI 脚本示例。Additional App Service CLI script samples can be found in the Azure App Service documentation.