إنشاء قرص مدار من لقطة باستخدام CLI (Linux)

تحتوي هذه المقالة على برنامجين نصيين لإنشاء قرص مدار من لقطة. البرنامج النصي الأول هو لقرص مدار مع مفاتيح مدارة من قبل النظام الأساسي والبرنامج النصي الثاني هو لقرص مدار مع مفاتيح يديرها العميل. استخدم هذه البرامج النصية لاستعادة جهاز ظاهري من لقطات نظام التشغيل وأقراص البيانات. قم بإنشاء أقراص إدارة نظام التشغيل والبيانات من اللقطات ذات الصلة ثم قم بإنشاء جهاز ظاهري جديد عن طريق إرفاق الأقراص المدارة. يمكنك أيضًا استعادة أقراص البيانات الخاصة بجهاز ظاهري موجود عن طريق إرفاق أقراص البيانات التي تم إنشاؤها من لقطات.

إذا لم يكن لديك اشتراك في Azure، فأنشئ حساب Azure مجاني قبل أن تبدأ.

المتطلبات الأساسية

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

إطلاق Azure Cloud Shell

Azure Cloud Shell هو shell تفاعلية مجانية التي يمكنك استخدامها لتشغيل الخطوات في هذه المقالة. يحتوي على أدوات Azure الشائعة المثبتة مسبقًا والمهيئة للاستخدام مع حسابك.

لفتح Cloud Shell، ما عليك سوى تحديد جربه من الزاوية اليمنى العليا من مجموعة التعليمات البرمجية. يمكنك أيضًا تشغيل Cloud Shell في علامة تبويب مستعرض منفصلة بالانتقال إلى https://shell.azure.com.

عند فتح Cloud Shell، تحقق من تحديد Bash لبيئتك. ستستخدم الجلسات اللاحقة Azure CLI في بيئة Bash، حدد نسخ لنسخ كتل التعليمات البرمجية، وألصقها في Cloud Shell، واضغط على Enter لتشغيلها.

تسجيل الدخول إلى Azure

يُصادق Cloud Shell تلقائياً بموجب الحساب الأولي الذي سُجل الدخول به. استخدم البرنامج النصي التالي لتسجيل الدخول باستخدام اشتراك مختلف، واستبدال subscriptionId بمعرف اشتراك Azure الخاص بك.

إذا لم يكن لديك اشتراك في Azure، فأنشئ حساب Azure مجاني قبل أن تبدأ.

subscription="subscriptionId" # Set Azure subscription ID here

az account set -s $subscription # ...or use 'az login'

لمزيد من المعلومات، راجع تعيين الاشتراك النشط أو تسجيل الدخول بشكل تفاعلي.

الأقراص ذات المفاتيح المدارة بواسطة النظام الأساسي

#Provide the subscription Id of the subscription where you want to create Managed Disks
subscriptionId="<subscriptionId>"

#Provide the name of your resource group
resourceGroupName=myResourceGroupName

#Provide the name of the snapshot that will be used to create Managed Disks
snapshotName=mySnapshotName

#Provide the name of the new Managed Disks that will be create
diskName=myDiskName

#Provide the size of the disks in GB. It should be greater than the VHD file size.
diskSize=128

#Provide the storage type for Managed Disk. Acceptable values are Standard_LRS, Premium_LRS, PremiumV2_LRS, StandardSSD_LRS, UltraSSD_LRS, Premium_ZRS, and StandardSSD_ZRS.
storageType=Premium_LRS

#Required for Premium SSD v2 and Ultra Disks
#Provide the Availability Zone you'd like the disk to be created in, default is 1
zone=1

#Set the context to the subscription Id where Managed Disk will be created
az account set --subscription $subscriptionId

#Get the snapshot Id 
snapshotId=$(az snapshot show --name $snapshotName --resource-group $resourceGroupName --query [id] -o tsv)

#Create a new Managed Disks using the snapshot Id
#Note that managed disk will be created in the same location as the snapshot
#If you're creating a Premium SSD v2 or an Ultra Disk, add "--zone $zone" to the end of the command
az disk create --resource-group $resourceGroupName --name $diskName --sku $storageType --size-gb $diskSize --source $snapshotId

الأقراص التي بها مفاتيح يديرها العميل

#Provide the subscription Id of the subscription where you want to create Managed Disks
subscriptionId="<subscriptionId>"

#Provide the name of your resource group
resourceGroupName=myResourceGroupName

#Provide the name of the snapshot that will be used to create Managed Disks
snapshotName=mySnapshotName

#Provide the name of the new Managed Disks that will be create
diskName=myDiskName

#Provide the size of the disks in GB. It should be greater than the VHD file size.
diskSize=128

#Provide the storage type for Managed Disk. Premium_LRS or Standard_LRS.
storageType=Premium_LRS

#Provide the name of the target disk encryption set
diskEncryptionSetName=myName

#Provide the target disk encryption set resource group
diskEncryptionResourceGroup=myGroup

#Required for Premium SSD v2 and Ultra Disks
#Provide the Availability Zone you'd like the disk to be created in, default is 1
zone=1

#Set the context to the subscription Id where Managed Disk will be created
az account set --subscription $subscriptionId

#Get the snapshot Id 
snapshotId=$(az snapshot show --name $snapshotName --resource-group $resourceGroupName --query [id] -o tsv)

#Get the disk encryption set ID
diskEncryptionSetId=$(az disk-encryption-set show --name $diskEncryptionSetName --resource-group $diskEncryptionResourceGroup)

#Create a new Managed Disks using the snapshot Id
#Note that managed disk will be created in the same location as the snapshot
#To change the location, add the --location parameter
#If you're creating a Premium SSD v2 or an Ultra Disk, add "--zone $zone" to the end of the command
az disk create -g $resourceGroupName -n $diskName --source $snapshotId --disk-encryption-set $diskEncryptionSetID --location eastus2euap

تأثير الأداء - عملية نسخ الخلفية

عند إنشاء قرص مدار من لقطة، فإنه يبدأ عملية نسخ الخلفية. يمكنك إرفاق قرص بجهاز ظاهري أثناء تشغيل هذه العملية ولكنك ستختبر تأثير الأداء (تواجه الأقراص 4k تأثير القراءة، تجربة 512e على حد سواء تأثير القراءة والكتابة) مع زمن انتقال أعلى، وانخفاض عمليات الإدخال والإخراج في الثانية ومعدل النقل حتى اكتمال نسخ الخلفية. بالنسبة إلى Ultra Disks وPremium SSD v2، يمكنك التحقق من حالة عملية النسخ في الخلفية باستخدام الأوامر التالية:

هام

لا يمكنك استخدام الأقسام التالية للحصول على حالة عملية نسخ الخلفية وأنواع الأقراص بخلاف Ultra Disk أو Premium SSD v2. أنواع الأقراص الأخرى دائما ما تبلغ عن 100٪.

subscriptionId=yourSubscriptionID
resourceGroupName=yourResourceGroupName
diskName=yourDiskName
az account set --subscription $subscriptionId
az disk show -n $diskName -g $resourceGroupName --query [completionPercent] -o tsv

تنظيف الموارد

قم بتشغيل الأمر التالي لإزالة مجموعة الموارد، VM، وجميع الموارد ذات الصلة.

az group delete --name myResourceGroupName

نموذج مرجع

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

الأمر ملاحظات
عرض لقطة az يمكن الحصول على كل خصائص اللقطة باستخدام خصائص الاسم ومجموعة الموارد الخاصة باللقطة. يتم استخدام خاصية المعرف لإنشاء قرص مدار.
إنشاء قرص az إنشاء قرص مدار باستخدام معرف اللقطة للقطة مدارة

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

إنشاء جهاز ظاهري عن طريق إرفاق قرص مدار كقرص نظام تشغيل

لمزيد من المعلومات عن Azure CLI، راجع وثائق Azure CLI.

يمكن العثور على المزيد من عينات البرنامج النصي CLI للجهاز الظاهري والأقراص المدارة في وثائق Azure Linux VM.