Delen via


Beheerde momentopnamen exporteren/kopiëren als VHD naar een opslagaccount in een andere regio met PowerShell

Met dit script wordt een beheerde momentopname geëxporteerd naar een opslagaccount in een andere regio. Eerst wordt de SAS-URI van de momentopname gegenereerd en vervolgens gebruikt om deze te kopiëren naar een opslagaccount in een andere regio. Gebruik dit script om back-ups van uw beheerde schijven in verschillende regio's te onderhouden voor herstel na noodgevallen.

Installeer indien nodig de Azure PowerShell-module met behulp van de instructies in de Azure PowerShell-handleidingen voer vervolgens Connect-AzAccount uit om een verbinding met Azure te maken. Er moet zich ook een openbare SSH-sleutel met de naam id_rsa.pub in de map .ssh van uw gebruikersprofiel bevinden.

Als u geen Azure-abonnement hebt, kunt u een gratis Azure-account maken voordat u begint.

Voorbeeldscript

#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

Uitleg van script

In dit script worden de volgende opdrachten gebruikt om sas-URI te genereren voor een beheerde momentopname en de momentopname te kopiëren naar een opslagaccount met behulp van sas-URI. Elke opdracht in de tabel bevat koppelingen naar opdrachtspecifieke documentatie.

Opdracht Opmerkingen
Grant-AzSnapshotAccess Hiermee genereert u een SAS-URI voor een momentopname die wordt gebruikt om deze naar een opslagaccount te kopiëren.
New-AzureStorageContext Hiermee maakt u een opslagaccountcontext met behulp van de accountnaam en -sleutel. Deze context kan worden gebruikt om lees-/schrijfbewerkingen uit te voeren op het opslagaccount.
Start-AzureStorageBlobCopy De onderliggende VHD van een momentopname naar een opslagaccount kopiëren

Volgende stappen

een beheerde schijf maken op basis van een VHD-

Een virtuele machine maken op basis van een beheerde schijf

Zie voor meer informatie over de Azure PowerShell-module de documentatie van Azure PowerShell.

Aanvullende PowerShell-scriptvoorbeelden voor virtuele machines vindt u in de documentatie Azure Linux VM.