使用 Azure PowerShell 從備份還原 Web 應用程式

此範例指令碼會從現有的 Web 應用程式擷取先前完成的備份,並藉由覆寫其內容加以還原。

您可以視需要使用 Azure PowerShell 指南 \(英文\) 中的指示來安裝 Azure PowerShell,然後執行 Connect-AzAccount 來建立與 Azure 的連線。

範例指令碼

注意

建議您使用 Azure Az PowerShell 模組來與 Azure 互動。 請參閱安裝 Azure PowerShell 以開始使用。 若要了解如何移轉至 Az PowerShell 模組,請參閱將 Azure PowerShell 從 AzureRM 移轉至 Az

$resourceGroupName = "myResourceGroup"
$webappname = "<replace-with-your-app-name>"
$targetResourceGroupName = "myResourceGroup"
$targetWebappName = "<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 restore

# Get the backup object that you want to restore by specifying the BackupID
$backup = (Get-AzWebAppBackup -ResourceGroupName $resourceGroupName -Name $webappname -BackupId '<replace-with-BackupID>')

# Get the storage account URL of the backup configuration
$url = (Get-AzWebAppBackupConfiguration -ResourceGroupName $resourceGroupName -Name $webappname).StorageAccountUrl

# Restore the app by overwriting it with the backup data
Restore-AzWebAppBackup -ResourceGroupName $resourceGroupName -Name $webappname -StorageAccountUrl $url -BlobName $backup.BlobName -Overwrite

清除部署

如果您不再需要 Web 應用程式,請使用下列命令來移除資源群組、Web 應用程式和所有相關資源。

Remove-AzResourceGroup -Name $resourceGroupName -Force

指令碼說明

此指令碼會使用下列命令。 下表中的每個命令都會連結至命令特定的文件。

Command 注意
Get-AzWebAppBackupList 取得 Web 應用程式的備份清單。
Get-AzWebAppBackup 使用備份識別碼取得 Web 應用程式的備份。
Get-AzWebAppBackupConfiguration 取得 Web 應用程式的備份設定。
Restore-AzWebAppBackup 從先前完成的備份中還原 Web 應用程式。

下一步

如需有關 Azure PowerShell 模組的詳細資訊,請參閱 Azure PowerShell 文件

您可以在 Azure PowerShell 範例中找到適用於 App Service Web Apps 的其他 Azure PowerShell 範例。