Azure CLI を使用してストレージ アカウントにマネージド ディスクをエクスポート/コピーする

このスクリプトは、マネージド ディスクの基盤となる VHD を、同じまたは別の地域のストレージ アカウントにエクスポートします。 最初にマネージド ディスクの SAS URI を生成し、続いてそれを使用して VHD をストレージ アカウントにコピーします。 このスクリプトを使用して、地域拡張のために、マネージド ディスクを別の地域にコピーします。 Azure Marketplace でマネージド ディスクの VHD ファイルを公開する場合は、このスクリプトを使って、VHD ファイルをストレージ アカウントにコピーした後、Marketplace で公開するためのコピーした VHD の SAS URI を生成できます。

このサンプルを実行するには、最新バージョンの Azure CLI をインストールします。 開始するには、az login を実行して、Azure との接続を作成します。

Azure CLI のサンプルは、bash シェル用に記述されています。 このサンプルを Windows PowerShell またはコマンド プロンプトで実行するには、スクリプトの要素を変更する必要があります。

Azure サブスクリプションをお持ちでない場合は、開始する前に無料アカウントを作成してください。

サンプル スクリプト

# 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>

スクリプトの説明

このスクリプトでは、次のコマンドを使用してマネージド ディスク用の SAS URI を生成し、SAS URI を使用して基盤となる VHD をストレージ アカウントにコピーします。 表内の各コマンドは、それぞれのドキュメントにリンクされています。

コマンド メモ
az ディスク アクセスの許可 基盤となる VHD ファイルをストレージ アカウントにコピーするか、オンプレミスにダウンロードするために使用される、読み取り専用の SAS を生成します。
az storage blob copy start BLOB を、あるストレージ アカウントから別のストレージ アカウントに非同期的にコピーします

次のステップ

VHD からマネージド ディスクを作成する

マネージド ディスクから仮想マシンを作成する

Azure CLI の詳細については、Azure CLI のドキュメントのページをご覧ください。

その他の仮想マシンとマネージド ディスクの CLI サンプル スクリプトは、Azure Linux VM のドキュメントにあります。