Felügyelt lemez pillanatképének másolása ugyanabban az előfizetésben vagy más előfizetésben a PowerShell használatával (Windows)

Ez a szkript átmásolja egy felügyelt lemez pillanatképét az előfizetésen belül vagy előfizetések között. Használja ezt a szkriptet a következő forgatókönyvekhez:

  1. A költségek csökkentése érdekében migráljon egy pillanatképet a Premium Storage -ban (Premium_LRS) standard tárolóba (Standard_LRS vagy Standard_ZRS).
  2. Pillanatkép áttelepítése helyileg redundáns tárolóból (Premium_LRS, Standard_LRS) zónaredundáns tárolóba (Standard_ZRS) a ZRS-tároló nagyobb megbízhatóságának kihasználása érdekében.
  3. Pillanatkép áthelyezése ugyanabban a régióban lévő különböző előfizetésbe a hosszabb megőrzés érdekében.

Ha szükséges, telepítse az Azure PowerShell-modult az Azure PowerShell útmutatójának utasításait követve, majd futtassa a Connect-AzAccount parancsot az Azure-hoz való csatlakozáshoz. Emellett szüksége lesz egy id_rsa.pub nevű nyilvános SSH-kulcsra a felhasználói profilja .ssh könyvtárában.

If you don't have an Azure subscription, create an Azure free account before you begin.

Példaszkript

#Provide the subscription Id of the subscription where snapshot exists
$sourceSubscriptionId='yourSourceSubscriptionId'

#Provide the name of your resource group where snapshot exists
$sourceResourceGroupName='yourResourceGroupName'

#Provide the name of the snapshot
$snapshotName='yourSnapshotName'

#Set the context to the subscription Id where snapshot exists
Select-AzSubscription -SubscriptionId $sourceSubscriptionId

#Get the source snapshot
$snapshot= Get-AzSnapshot -ResourceGroupName $sourceResourceGroupName -Name $snapshotName

#Provide the subscription Id of the subscription where snapshot will be copied to
#If snapshot is copied to the same subscription then you can skip this step
$targetSubscriptionId='yourTargetSubscriptionId'

#Name of the resource group where snapshot will be copied to
$targetResourceGroupName='yourTargetResourceGroupName'

#Set the context to the subscription Id where snapshot will be copied to
#If snapshot is copied to the same subscription then you can skip this step
Select-AzSubscription -SubscriptionId $targetSubscriptionId

#We recommend you to store your snapshots in Standard storage to reduce cost. Please use Standard_ZRS in regions where zone redundant storage (ZRS) is available, otherwise use Standard_LRS
#Please check out the availability of ZRS here: https://docs.microsoft.com/en-us/Az.Storage/common/storage-redundancy-zrs#support-coverage-and-regional-availability
$snapshotConfig = New-AzSnapshotConfig -SourceResourceId $snapshot.Id -Location $snapshot.Location -CreateOption Copy -SkuName Standard_LRS

#Create a new snapshot in the target subscription and resource group
New-AzSnapshot -Snapshot $snapshotConfig -SnapshotName $snapshotName -ResourceGroupName $targetResourceGroupName 

Szkript ismertetése

A szkript a következő parancsokat használja egy, a forráspillanatkép azonosítóját használó pillanatkép a célelőfizetésben történő létrehozásához. A táblázatban lévő összes parancs a hozzá tartozó dokumentációra hivatkozik.

Parancs Jegyzetek
New-AzSnapshotConfig Egy, a pillanatképek létrehozásához használt pillanatkép-konfigurációt hoz létre. Tartalmazza a szülőpillanatkép erőforrás-azonosítóját, valamint a helyet, amely azonos a szülőpillanatkép helyével.
New-AzSnapshot Létrehoz egy pillanatképet a pillanatkép-konfiguráció, a pillanatkép neve és az erőforráscsoport neve alapján, amelyek paraméterként vannak megadva.

Következő lépések

Virtuális gép létrehozása pillanatképből

Az Azure PowerShell modullal kapcsolatos további információért lásd az Azure PowerShell dokumentációját.

A virtuális gépekhez kapcsolódó további PowerShell-példaszkripteket az Azure Windows rendszerű virtuális gépekre vonatkozó dokumentációjában találhat.