이 스크립트는 관리 디스크의 기본 VHD를 동일하거나 다른 지역의 스토리지 계정으로 내보냅니다. 먼저 관리 디스크의 SAS URI를 생성한 다음 VHD를 스토리지 계정에 복사하는 데 사용합니다. 이 스크립트를 사용하여 지역 확장을 위해 관리 디스크를 다른 지역으로 복사합니다. Azure Marketplace에서 관리 디스크의 VHD 파일을 게시하려면 이 스크립트를 사용하여 VHD 파일을 스토리지 계정에 복사한 다음 복사한 VHD의 SAS URI를 생성하여 Marketplace에 게시할 수 있습니다.
이 샘플을 실행하려면 최신 버전의 Azure CLI를 설치합니다. 시작하려면 az login을 실행하여 Azure와 연결합니다.
Azure CLI 샘플은 bash 셸용으로 작성됩니다. Windows PowerShell 또는 명령 프롬프트에서 이 샘플을 실행하려면 스크립트의 요소를 변경해야 할 수도 있습니다.
Azure 구독이 없는 경우 시작하기 전에 Azure 체험 계정을 만듭니다.
샘플 스크립트
# Verified by Liam Kelly as of 12/08/2025
# <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/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 복사 시작) | Blob을 한 스토리지 계정에서 다른 스토리지 계정으로 비동기적으로 복사합니다. |
다음 단계
Azure CLI에 대한 자세한 내용은 Azure CLI 설명서를 참조하세요.
추가 가상 머신 및 관리 디스크 CLI 스크립트 샘플은 Azure Linux VM 설명서에서 찾을 수 있습니다.