Anteckning
Åtkomst till den här sidan kräver auktorisering. Du kan prova att logga in eller ändra kataloger.
Åtkomst till den här sidan kräver auktorisering. Du kan prova att ändra kataloger.
Det här exempelskriptet hämtar en tidigare slutförd säkerhetskopia från en befintlig webbapp och återställer den till en webbapp i en annan prenumeration.
Om det behövs installerar du Azure PowerShell med hjälp av instruktionerna i Azure PowerShell-guiden och kör sedan Connect-AzAccount
för att skapa en anslutning till Azure.
Exempelskript
Kommentar
Vi rekommenderar att du använder Azure Az PowerShell-modulen för att interagera med Azure. Information om hur du kommer igång finns i Installera Azure PowerShell. Information om hur du migrerar till Az PowerShell-modulen finns i artikeln om att migrera Azure PowerShell från AzureRM till Az.
# This sample script retrieves a previously completed backup from an existing web app and restores it to a web app in another subscription.
# If needed, install the Azure PowerShell using the instruction found in the Azure PowerShell guide, and then run Connect-AzAccount to create a connection with Azure.
$resourceGroupNameSub1 = "<replace-with-your-group-name>"
$resourceGroupNameSub2 = "<replace-with-desired-new-group-name>"
$webAppNameSub1 = "<replace-with-your-app-name>"
$webAppNameSub2 = "<replace-with-desired-new-app-name>"
$appServicePlanSub2 = "<replace-with-desired-new-plan-name>"
$locationSub2 = "West Europe"
# Log into the subscription with the backup
Add-AzAccount
# List statuses of all backups that are complete or currently executing.
Get-AzWebAppBackupList -ResourceGroupName $resourceGroupNameSub1 -Name $webAppNameSub1
# 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 $resourceGroupNameSub1 -Name $webAppNameSub1 -BackupId '<replace-with-BackupID>')
# Get the storage account URL of the backup configuration
$url = (Get-AzWebAppBackupConfiguration -ResourceGroupName $resourceGroupNameSub1 -Name $webAppNameSub1).StorageAccountUrl
# Log into the subscription that you want to restore the app to
Add-AzAccount
# Create a new web app
New-AzWebApp -ResourceGroupName $resourceGroupNameSub2 -AppServicePlan $appServicePlanSub2 -Name $webAppNameSub2 -Location $locationSub2
# Restore the app by overwriting it with the backup data
Restore-AzWebAppBackup -ResourceGroupName $resourceGroupNameSub2 -Name $webAppNameSub2 -StorageAccountUrl $url -BlobName $backup.BlobName -Overwrite
Rensa distribution
Om du inte behöver webbappen längre kan du använda följande kommando för att ta bort resursgruppen, webbappen och alla relaterade resurser.
Remove-AzResourceGroup -Name $resourceGroupName -Force
Förklaring av skript
Det här skriptet använder följande kommandon. Varje kommando i tabellen länkar till kommandospecifik dokumentation.
Command | Kommentar |
---|---|
Add-AzAccount | Lägger till ett autentiserat konto som ska användas för Azure Resource Manager-cmdlet-begäranden. |
Get-AzWebAppBackupList | Hämtar en lista över säkerhetskopior för en webbapp. |
Get-AzWebAppBackup | Hämtar en säkerhetskopia för en webbapp med hjälp av säkerhetskopierings-ID:t. |
Get-AzWebAppBackupConfiguration | Hämtar säkerhetskopieringskonfigurationen för en webbapp. |
New-AzWebApp | Skapar en webbapp |
Restore-AzWebAppBackup | Återställer en webbapp från en tidigare slutförd säkerhetskopia. |
Nästa steg
Mer information om Azure PowerShell-modulen finns i Azure PowerShell-dokumentationen.
Ytterligare Azure PowerShell-exempel för Azure App Service Web Apps finns i Azure PowerShell-exemplen.