CLI를 사용하여 관리 디스크를 동일한 구독이나 다른 구독으로 복사

이 스크립트는 관리 디스크를 동일한 구독이나 같은 지역에 있지만 다른 구독으로 복사합니다. 이 복사는 구독이 동일한 Azure AD 테넌트의 일부일 때만 수행됩니다.

이 샘플을 실행하려면 최신 버전의 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 of the subscription where managed disk exists
sourceSubscriptionId="<subscriptionId>"

#Provide the name of your resource group where managed disk exists
sourceResourceGroupName=mySourceResourceGroupName

#Provide the name of the managed disk
managedDiskName=myDiskName

#Set the context to the subscription Id where managed disk exists
az account set --subscription $sourceSubscriptionId

#Get the managed disk Id 
managedDiskId=$(az disk show --name $managedDiskName --resource-group $sourceResourceGroupName --query [id] -o tsv)

#If managedDiskId is blank then it means that managed disk does not exist.
echo 'source managed disk Id is: ' $managedDiskId

#Provide the subscription Id of the subscription where managed disk will be copied to
targetSubscriptionId=6492b1f7-f219-446b-b509-314e17e1efb0

#Name of the resource group where managed disk will be copied to
targetResourceGroupName=mytargetResourceGroupName

#Set the context to the subscription Id where managed disk will be copied to
az account set --subscription $targetSubscriptionId

#Copy managed disk to different subscription using managed disk Id
az disk create --resource-group $targetResourceGroupName --name $managedDiskName --source $managedDiskId
# </FullScript>

스크립트 설명

이 스크립트에서는 다음 명령을 사용하여 원본 관리 디스크의 ID를 사용하여 대상 구독에 새 관리 디스크를 만듭니다. 테이블에 있는 각 명령은 명령에 해당하는 문서에 연결됩니다.

명령 메모
az disk show 관리 디스크의 이름 및 리소스 그룹 속성을 사용하여 관리 디스크의 모든 속성을 가져옵니다. Id 속성은 관리 디스크를 다른 구독으로 복사하는 데 사용됩니다.
az disk create 부모 관리 디스크의 Id 및 이름을 사용하여 다른 구독에서 새 관리 디스크를 만들어 관리 디스크를 복사합니다.

다음 단계

관리 디스크에서 가상 머신 만들기

Azure CLI에 대한 자세한 내용은 Azure CLI 설명서를 참조하세요.

추가 가상 머신 및 관리 디스크 CLI 스크립트 샘플은 Azure Linux VM 설명서에서 확인할 수 있습니다.