استعادة تطبيق ويب من نسخة احتياطية في حساب اشتراك آخر باستخدام PowerShell

يقوم هذا البرنامج النصي النموذجي باسترداد نسخة احتياطية تم إكمالها مسبقاً من تطبيق ويب قائم ويعيدها إلى تطبيق ويب في اشتراك آخر.

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

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

إشعار

نوصي باستخدام الوحدة النمطية Azure Az PowerShell للتفاعل مع Azure. راجع تثبيت Azure PowerShell للبدء. لمعرفة كيفية الترحيل إلى الوحدة النمطية Az PowerShell، راجع ترحيل Azure PowerShell من AzureRM إلى 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

تنظيف النشر

إذا لم تعد بحاجة إلى تطبيق الويب، فاستخدم الأمر التالي لإزالة مجموعة الموارد وتطبيق الويب وجميع الموارد ذات الصلة.

Remove-AzResourceGroup -Name $resourceGroupName -Force

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

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

الأمر ملاحظات
Add-AzAccount أضف حساب مصدق عليه لاستخدامه لطلبات cmdlet لـ Azure Resource Manager.
Get-AzWebAppBackupList الحصول على قائمة النسخ الاحتياطي لتطبيق ويب.
الحصول على AzWebAppBackup يحصل على نسخة احتياطية لتطبيق ويب باستخدام معرف النسخ الاحتياطي.
Get-AzWebAppBackupConfiguration يحصل على تكوين النسخ الاحتياطي لتطبيق ويب.
New-AzWebApp لإنشاء تطبيق ويب
Restore-AzWebAppBackup استعادة تطبيق ويب من نسخة احتياطية معتمدة مسبقا.

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

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

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