إجراء نسخ احتياطي لتطبيق ويب باستخدام PowerShell

ينشئ هذا البرنامج النصي نموذج تطبيق ويب في خدمة التطبيقات مع الموارد المرتبطة به، ثم ينشئ نسخة احتياطية لمرة واحدة له.

إذا لزم الأمر، فقم بتثبيت Azure PowerShell باستخدام الإرشادات المذكورة في دليل Azure PowerShell ، ثم قم بتشغيله Connect-AzAccount لإنشاء اتصال مع Azure.

نموذج البرنامج النصي

إشعار

نوصي باستخدام الوحدة النمطية Azure Az PowerShell للتفاعل مع Azure. راجع تثبيت Azure PowerShell للبدء. لمعرفة كيفية الترحيل إلى الوحدة النمطية Az PowerShell، راجع ترحيل Azure PowerShell من AzureRM إلى Az.

# 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

تنظيف النشر

بعد تشغيل نموذج البرنامج النصي، يمكن استخدام الأمر التالي لإزالة مجموعة الموارد وتطبيق الويب مع كافة الموارد المقترنة بها.

Remove-AzResourceGroup -Name myResourceGroup -Force

شرح السيناريو

يستخدم هذا البرنامج النصي الأوامر التالية. يرتبط كل أمر في الجدول بأمر وثائق معينة.

الأمر ملاحظات
New-AzResourceGroup إنشاء مجموعة موارد يتم تخزين كل الموارد فيها.
New-AzStorageAccount إنشاء حساب تخزين.
New-AzStorageContainer إنشاء حاوية تخزين Azure.
New-AzStorageContainerSASToken إنشاء رمز مميز SAS لحاوية تخزين Azure.
New-AzAppServicePlan ينشئ خطة خدمة التطبيق.
New-AzWebApp ينشئ تطبيق ويب.
New-AzWebAppBackup إنشاء نسخة احتياطية لتطبيق ويب.
Get-AzWebAppBackupList الحصول على قائمة النسخ الاحتياطي لتطبيق ويب.

الخطوات التالية

لمزيد من المعلومات حول وحدةAzure PowerShell، يرجى الاطلاع على وثائق Azure PowerShell.

يمكن العثور على نماذج Azure PowerShell الإضافية لتطبيقات Azure App Service Web Apps في نماذج Azure PowerShell.