使用 Azure PowerShell 删除 Web 应用的备份Delete a backup for a web using Azure PowerShell

此示例脚本使用其相关资源,在应用服务中创建 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.

示例脚本Sample script

备注

本文进行了更新,以便使用新的 Azure PowerShell Az 模块。This article has been updated to use the new Azure PowerShell Az module. 你仍然可以使用 AzureRM 模块,至少在 2020 年 12 月之前,它将继续接收 bug 修补程序。You can still use the AzureRM module, which will continue to receive bug fixes until at least December 2020. 若要详细了解新的 Az 模块和 AzureRM 兼容性,请参阅新 Azure Powershell Az 模块简介To learn more about the new Az module and AzureRM compatibility, see Introducing the new Azure PowerShell Az module. 有关 Az 模块安装说明,请参阅安装 Azure PowerShellFor Az module installation instructions, see Install Azure PowerShell.

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

# List statuses of all backups that are complete or currently executing.
Get-AzWebAppBackupList -ResourceGroupName $resourceGroupName -Name $webappname

# Note the BackupID property of the backup you want to delete

# Delete the backup by specifying the BackupID
Remove-AzWebAppBackup -ResourceGroupName $resourceGroupName -Name $webappname `
-BackupId <replace-with-BackupID>

清理部署Clean up deployment

运行脚本示例后,可以使用以下命令删除资源组、Web 应用以及所有相关资源。After the script sample has been run, the following command can be used to remove the resource group, web app, and all related resources.

Remove-AzResourceGroup -Name myResourceGroup -Force

脚本说明Script explanation

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

CommandCommand 说明Notes
Get-AzWebAppBackupListGet-AzWebAppBackupList 获取 Web 应用的备份列表。Gets a list of backups for a web app.
Remove-AzWebAppBackupRemove-AzWebAppBackup 删除 Web 应用的指定备份。Removes the specified backup of a web app.

后续步骤Next steps

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

可以在 Azure PowerShell 示例中找到 Azure 应用服务 Web 应用的其他 Azure Powershell 示例。Additional Azure Powershell samples for Azure App Service Web Apps can be found in the Azure PowerShell samples.