Azure CLI kullanarak yönetilen diski depolama hesabına dışarı aktarma/kopyalama
Bu betik yönetilen diskin VHD dosyasını aynı veya farklı bölgede bulunan bir depolama hesabına aktarır. İlk olarak yönetilen diskin SAS URI'sini oluşturur ve sonra onu VHD dosyasını bir depolama hesabına kopyalamak için kullanır. Bu betiği bölgesel genişleme için yönetilen diskleri farklı bölgelere kopyalama amacıyla kullanabilirsiniz. Yönetilen diskin VHD dosyasını Azure Market'de yayımlamak istiyorsanız, bu betiği kullanarak VHD dosyasını bir depolama hesabına kopyalayabilir ve ardından kopyalanan VHD'nin SAS URI'sini oluşturarak Market'te yayımlayabilirsiniz.
Bu örneği çalıştırmak için Azure CLI'nın en son sürümünü yükleyin. Başlangıç olarak, Azure ile bağlantı oluşturmak için az login
komutunu çalıştırın.
Azure CLI örnekleri kabuk için bash
yazılmıştır. Bu örneği Windows PowerShell veya Komut İstemi'nde çalıştırmak için betiğin öğelerini değiştirmeniz gerekebilir.
Azure aboneliğiniz yoksa başlamadan önce birücretsiz Azure hesabı oluşturun.
Örnek betik
# Verified per Raman Kumar as of 2/23/2022
# <FullScript>
#Provide the subscription Id where managed disk is created
subscriptionId="<subscriptionId>"
#Provide the name of your resource group where managed disk is created
resourceGroupName=myResourceGroupName
#Provide the managed disk name
diskName=myDiskName
#Provide Shared Access Signature (SAS) expiry duration in seconds e.g. 3600.
#Know more about SAS here: https://docs.microsoft.com/en-us/azure/storage/storage-dotnet-shared-access-signature-part-1
sasExpiryDuration=3600
#Provide storage account name where you want to copy the underlying VHD file of the managed disk.
storageAccountName=mystorageaccountname
#Name of the storage container where the downloaded VHD will be stored
storageContainerName=mystoragecontainername
#Provide the key of the storage account where you want to copy the VHD
storageAccountKey=mystorageaccountkey
#Provide the name of the destination VHD file to which the VHD of the managed disk will be copied.
destinationVHDFileName=myvhdfilename.vhd
az account set --subscription $subscriptionId
sas=$(az disk grant-access --resource-group $resourceGroupName --name $diskName --duration-in-seconds $sasExpiryDuration --query [accessSas] -o tsv)
az storage blob copy start --destination-blob $destinationVHDFileName --destination-container $storageContainerName --account-name $storageAccountName --account-key $storageAccountKey --source-uri $sas
# </FullScript>
Betik açıklaması
Bu betik bir yönetilen diskin SAS URI'sini oluşturmak için aşağıdaki komutları kullanır ve SAS URI'sini kullanarak VHD dosyasını bir depolama hesabına kopyalar. Tablodaki her komut, komuta özgü belgelere yönlendirir.
Komut | Notlar |
---|---|
az disk grant-access | Temel alınan VHD dosyasını bir depolama hesabına kopyalamak veya şirket içine indirmek üzere kullanılan salt okunur SAS oluşturur |
az storage blob copy start | Bir blobu bir depolama hesabından diğerine zaman uyumsuz olarak kopyalar |
Sonraki adımlar
VHD'den yönetilen disk oluşturma
Yönetilen diskten sanal makine oluşturma
Azure CLI hakkında daha fazla bilgi için bkz. Azure CLI belgeleri.
Ek sanal makine ve yönetilen disk CLI betiği örnekleri, Azure Linux VM belgeleri içinde bulunabilir.