Webalkalmazás biztonsági mentése a PowerShell használatával
Ez a példaszkript egy webalkalmazást hoz létre az App Service-ben a kapcsolódó erőforrásokkal együtt, majd egyszeri biztonsági mentést hajt végre.
Szükség esetén telepítse az Azure PowerShellt az Azure PowerShell útmutatójának utasításait követve, majd a Connect-AzAccount
futtatásával hozza létre a kapcsolatot az Azure-ral.
Példaszkript
Feljegyzés
Javasoljuk, hogy az Azure Az PowerShell modult használja az Azure-ral való interakcióhoz. Első lépésként tekintse meg az Azure PowerShell telepítését ismertető témakört. Az Az PowerShell-modulra történő migrálás részleteiről lásd: Az Azure PowerShell migrálása az AzureRM modulból az Az modulba.
# This sample script creates a web app in App Service with its related resources, and then creates a one-time backup for it.
# 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.
$webappname="mywebapp$(Get-Random -Minimum 100000 -Maximum 999999)"
$storagename="$($webappname)storage"
$container="appbackup"
$location="West Europe"
$backupname="backup1"
# Create a resource group.
New-AzResourceGroup -Name myResourceGroup -Location $location
# Create a storage account.
$storage = New-AzStorageAccount -ResourceGroupName myResourceGroup `
-Name $storagename -SkuName Standard_LRS -Location $location
# Create a storage container.
New-AzStorageContainer -Name $container -Context $storage.Context
# Generates an SAS token for the storage container, valid for one month.
# NOTE: You can use the same SAS token to make backups in Web Apps until -ExpiryTime
$sasUrl = New-AzStorageContainerSASToken -Name $container -Permission rwdl `
-Context $storage.Context -ExpiryTime (Get-Date).AddMonths(1) -FullUri
# Create an App Service plan in Standard tier. Standard tier allows one backup per day.
New-AzAppServicePlan -ResourceGroupName myResourceGroup -Name $webappname `
-Location $location -Tier Standard
# Create a web app.
New-AzWebApp -ResourceGroupName myResourceGroup -Name $webappname `
-Location $location -AppServicePlan $webappname
# Create a one-time backup
New-AzWebAppBackup -ResourceGroupName myResourceGroup -Name $webappname `
-StorageAccountUrl $sasUrl -BackupName $backupname
# List statuses of all backups that are complete or currently executing.
Get-AzWebAppBackupList -ResourceGroupName myResourceGroup -Name $webappname
Az üzemelő példány eltávolítása
A példaszkript futtatása után a következő paranccsal távolítható el az erőforráscsoport, a webalkalmazás és az összes kapcsolódó erőforrás.
Remove-AzResourceGroup -Name myResourceGroup -Force
Szkript ismertetése
A szkript a következő parancsokat használja. A táblázatban lévő összes parancs a hozzá tartozó dokumentációra hivatkozik.
Parancs | Jegyzetek |
---|---|
New-AzResourceGroup | Létrehoz egy erőforráscsoportot, amely az összes erőforrást tárolja. |
New-AzStorageAccount | Létrehoz egy tárfiókot. |
New-AzStorageContainer | Létrehoz egy Azure Storage-tárolót. |
New-AzStorageContainerSASToken | Létrehoz egy SAS-tokent egy Azure Storage-tárolóhoz. |
New-AzAppServicePlan | Létrehoz egy App Service-csomagot. |
New-AzWebApp | Webalkalmazást hoz létre. |
New-AzWebAppBackup | Biztonsági másolatot készít egy webalkalmazásról. |
Get-AzWebAppBackupList | Lekéri egy webalkalmazás biztonsági másolatainak listáját. |
Következő lépések
Az Azure PowerShell modullal kapcsolatos további információért lásd az Azure PowerShell dokumentációját.
További Azure PowerShell-minták találhatók a Azure-alkalmazás Service Web Appshez az Azure PowerShell-mintákban.