Azure PowerShell を使用して Web アプリをバックアップから復元する

このサンプル スクリプトでは、既存の Web アプリから以前に完了したバックアップを取得し、コンテンツを上書きすることによってアプリを復元します。

必要に応じて、Azure PowerShell ガイドの手順に従って Azure PowerShell をインストールし、Connect-AzAccount を実行して、Azure との接続を作成します。

サンプル スクリプト

注意

Azure を操作するには、Azure Az PowerShell モジュールを使用することをお勧めします。 作業を開始するには、Azure PowerShell のインストールに関する記事を参照してください。 Az PowerShell モジュールに移行する方法については、「AzureRM から Az への Azure PowerShell の移行」を参照してください。

$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

スクリプトの説明

このスクリプトでは、次のコマンドを使用します。 表内の各コマンドは、それぞれのドキュメントにリンクされています。

コマンド Notes
Get-AzWebAppBackupList Web アプリのバックアップの一覧を取得します。
Get-AzWebAppBackup バックアップ ID を使用して Web アプリのバックアップを取得します。
Get-AzWebAppBackupConfiguration Web アプリのバックアップ構成を取得します。
Restore-AzWebAppBackup 以前に完了したバックアップから Web アプリを復元します。

次のステップ

Azure PowerShell モジュールの詳細については、Azure PowerShell のドキュメントを参照してください。

その他の Azure App Service Web Apps 用 Azure PowerShell サンプルは、Azure PowerShell サンプルのページにあります。