PowerShell을 사용하여 스냅샷에서 관리 디스크 만들기

이 스크립트는 스냅샷에서 관리 디스크를 만듭니다. 이를 사용하여 OS 및 데이터 디스크의 스냅샷에서 가상 머신을 복원합니다. 각 스냅샷에서 OS 및 데이터 관리 디스크를 만든 다음, 관리 디스크를 연결하여 새 가상 머신을 만듭니다. 스냅샷에서 만든 데이터 디스크를 연결하여 기존 VM의 데이터 디스크를 복원할 수도 있습니다.

Azure를 구독하고 있지 않다면 시작하기 전에 Azure 체험 계정을 만듭니다.

샘플 스크립트

#Provide the subscription Id
$subscriptionId = 'yourSubscriptionId'

#Provide the name of your resource group
$resourceGroupName ='yourResourceGroupName'

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

#Provide the name of the Managed Disk
$diskName = 'yourManagedDiskName'

#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

#Provide the Azure region (e.g. westus) where Managed Disks will be located.
#This location should be same as the snapshot location
#Get all the Azure location using command below:
#Get-AzLocation
$location = 'westus'

#Set the context to the subscription Id where Managed Disk will be created
Select-AzSubscription -SubscriptionId $SubscriptionId

$snapshot = Get-AzSnapshot -ResourceGroupName $resourceGroupName -SnapshotName $snapshotName 

#If you're creating a Premium SSD v2 or an Ultra Disk, add "-Zone $zone" to the end of the command
$diskConfig = New-AzDiskConfig -SkuName $storageType -Location $location -CreateOption Copy -SourceResourceId $snapshot.Id -DiskSizeGB $diskSize
 
New-AzDisk -Disk $diskConfig -ResourceGroupName $resourceGroupName -DiskName $diskName

성능 영향 - 백그라운드 복사 프로세스

스냅샷에서 관리 디스크를 만들면 백그라운드 복사 프로세스가 시작됩니다. 이 프로세스가 실행되는 동안 VM에 디스크를 연결할 수 있지만 성능에 영향을 미치게 됩니다(4k 디스크는 읽기 영향을 받고 512e는 읽기 및 쓰기 영향 둘 다 받게됨). Ultra Disks 및 Premium SSD v2의 경우 Azure CLI를 사용하여 백그라운드 복사 프로세스의 상태를 확인할 수 있습니다. 현재 Azure PowerShell 모듈에서는 지원되지 않습니다.

Important

Ultra Disk 또는 프리미엄 SSD v2 이외의 디스크 유형에 대한 백그라운드 복사 프로세스의 상태를 가져오기 위해 다음 섹션을 사용할 수 없습니다. 다른 디스크 유형은 항상 100%를 보고합니다.

스크립트 설명

이 스크립트에서는 다음 명령을 사용하여 스냅샷에서 관리 디스크를 만듭니다. 테이블에 있는 각 명령은 명령에 해당하는 문서에 연결됩니다.

명령 주의
Get-AzSnapshot 스냅샷 속성을 가져옵니다.
New-AzDiskConfig 디스크 만들기에 사용되는 디스크 구성을 만듭니다. 부모 스냅샷의 리소스 ID, 부모 스냅샷의 위치와 같은 위치 및 스토리지 형식을 포함합니다.
New-AzDisk 매개 변수로 전달된 디스크 구성, 디스크 이름 및 리소스 그룹 이름을 사용하여 디스크를 만듭니다.

다음 단계

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

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

추가 가상 머신 PowerShell 스크립트 샘플은 Azure Windows VM 설명서에서 확인할 수 있습니다.