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

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

이 샘플을 실행하려면 최신 버전의 Azure CLI를 설치합니다. 시작하려면 az login을 실행하여 Azure와 연결합니다.

Azure CLI 샘플은 bash 셸용으로 작성됩니다. Windows PowerShell 또는 명령 프롬프트에서 이 샘플을 실행하려면 스크립트의 요소를 변경해야 할 수도 있습니다.

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

샘플 스크립트

# Verified per Raman Kumar as of 2/23/2022

# <FullScript>
#Provide the subscription Id where snapshot is created
subscriptionId="<subscriptionId>"

#Provide the name of your resource group where snapshot is created
resourceGroupName=myResourceGroupName

#Provide the snapshot name 
snapshotName=mySnapshotName

#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 snapshot. 
storageAccountName=mystorageaccountname

#Name of the storage container where the downloaded snapshot will be stored
storageContainerName=mystoragecontainername

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

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

az account set --subscription $subscriptionId

sas=$(az snapshot grant-access --resource-group $resourceGroupName --name $snapshotName --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를 사용하여 스토리지 계정에 스냅샷을 복사합니다. 테이블에 있는 각 명령은 명령에 해당하는 문서에 연결됩니다.

명령 메모
az snapshot grant-access 기본 VHD 파일을 스토리지 계정으로 복사하거나 온-프레미스로 다운로드하는 데 사용되는 읽기 전용 SAS를 생성합니다.
az storage blob copy start 하나의 스토리지 계정에서 다른 스토리지 계정으로 Blob을 비동기적으로 복사

다음 단계

VHD에서 관리 디스크 만들기

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

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

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