PowerShell을 사용하여 다른 지역의 스토리지 계정으로 관리 스냅샷을 VHD로 내보내기/복사

이 스크립트는 다른 지역의 스토리지 계정으로 관리 스냅샷을 내보냅니다. 먼저 스냅샷의 SAS URI를 생성한 다음, 이를 사용하여 다른 지역의 스토리지 계정으로 스냅샷을 복사합니다. 이 스크립트를 사용하여 재해 복구를 위해 다른 지역에서 관리 디스크의 백업을 유지 관리합니다.

필요한 경우 Azure PowerShell 가이드에 있는 지침을 사용하여 Azure PowerShell 모듈을 설치한 다음, Connect-AzAccount를 실행하여 Azure에 연결합니다. 또한 id_rsa.pub라는 이름의 SSH 공개 키가 사용자 프로필의 .ssh 디렉터리에 있어야 합니다.

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

샘플 스크립트

#Provide the subscription Id of the subscription where snapshot is created
$subscriptionId = "yourSubscriptionId"

#Provide the name of your resource group where snapshot is created
$resourceGroupName ="yourResourceGroupName"

#Provide the snapshot name 
$snapshotName = "yourSnapshotName"

#Provide Shared Access Signature (SAS) expiry duration in seconds e.g. 3600.
#Know more about SAS here: https://docs.microsoft.com/en-us/Az.Storage/storage-dotnet-shared-access-signature-part-1
$sasExpiryDuration = "3600"

#Provide storage account name where you want to copy the snapshot. 
$storageAccountName = "yourstorageaccountName"

#Name of the storage container where the downloaded snapshot will be stored
$storageContainerName = "yourstoragecontainername"

#Provide the key of the storage account where you want to copy snapshot. 
$storageAccountKey = 'yourStorageAccountKey'

#Provide the name of the VHD file to which snapshot will be copied.
$destinationVHDFileName = "yourvhdfilename"


# Set the context to the subscription Id where Snapshot is created
Select-AzSubscription -SubscriptionId $SubscriptionId

#Generate the SAS for the snapshot 
$sas = Grant-AzSnapshotAccess -ResourceGroupName $ResourceGroupName -SnapshotName $SnapshotName  -DurationInSecond $sasExpiryDuration -Access Read
#Create the context for the storage account which will be used to copy snapshot to the storage account 
$destinationContext = New-AzStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey

#Copy the snapshot to the storage account 
Start-AzStorageBlobCopy -AbsoluteUri $sas.AccessSAS -DestContainer $storageContainerName -DestContext $destinationContext -DestBlob $destinationVHDFileName

스크립트 설명

이 스크립트에서는 다음 명령을 사용하여 관리 스냅샷의 SAS URI를 생성하고 SAS URI를 사용하여 스토리지 계정에 스냅샷을 복사합니다. 테이블에 있는 각 명령은 명령에 해당하는 문서에 연결됩니다.

명령 메모
Grant-AzSnapshotAccess 스토리지 계정에 스냅샷을 복사하는 데 사용되는 스냅샷의 SAS URI를 생성합니다.
New-AzureStorageContext 계정 이름과 키를 사용하여 스토리지 계정 컨텍스트를 만듭니다. 이 컨텍스트는 스토리지 계정에 대한 읽기/쓰기 작업을 수행하는 데 사용할 수 있습니다.
Start-AzureStorageBlobCopy 스냅샷의 기본 VHD를 스토리지 계정에 복사합니다.

다음 단계

VHD에서 관리 디스크 만들기

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

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

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