Felügyelt lemez pillanatképének másolása előfizetésen belül vagy előfizetések között a CLI használatával

Ez a cikk két szkriptet tartalmaz. Az első szkript egy olyan felügyelt lemez pillanatképét másolja, amely platform által felügyelt kulcsokat használt ugyanahhoz vagy egy másik előfizetéshez. A második szkript egy olyan felügyelt lemez pillanatképét másolja, amely ügyfél által felügyelt kulcsokat használt ugyanahhoz vagy egy másik előfizetéshez. Ezek a szkriptek a következő forgatókönyvekhez használhatók:

  • 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).
  • 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.
  • 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.

Megjegyzés:

Mindkét előfizetésnek ugyanabban a bérlőben kell lennie

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

Előfeltételek

Példaszkript

Az Azure Cloud Shell elindítása

Az Azure Cloud Shell egy olyan ingyenes interaktív kezelőfelület, amelyet a jelen cikkben található lépések futtatására használhat. A fiókjával való használat érdekében a gyakran használt Azure-eszközök már előre telepítve és konfigurálva vannak rajta.

A Cloud Shell megnyitásához válassza a Kipróbálás lehetőséget egy kódblokk jobb felső sarkában. A Cloud Shellt egy külön böngészőlapon is elindíthatja a https://shell.azure.com cím megnyitásával.

Amikor megnyílik a Cloud Shell, ellenőrizze, hogy a Bash ki van-e jelölve a környezetében. A következő munkamenetek az Azure CLI-t használják Bash-környezetben, a Másolás lehetőséget választva másolja ki a kódblokkokat, illessze be a Cloud Shellbe, és nyomja le az Enter billentyűt a futtatáshoz.

Bejelentkezés az Azure-ba

A Cloud Shell automatikusan hitelesítve lesz a kezdeti fiókkal, amellyel bejelentkezett. A következő szkripttel egy másik előfizetéssel jelentkezhet be, lecserélve <Subscription ID> az Azure-előfizetés azonosítóját. If you don't have an Azure subscription, create an Azure free account before you begin.

subscription="<subscriptionId>" # add subscription here

az account set -s $subscription # ...or use 'az login'

További információ: Aktív előfizetés beállítása vagy interaktív bejelentkezés

Platform által felügyelt kulcsokkal rendelkező lemezek

#Provide the subscription Id of the subscription where snapshot exists
sourceSubscriptionId="<subscriptionId>"

#Provide the name of your resource group where snapshot exists
sourceResourceGroupName=mySourceResourceGroupName

#Provide the name of the snapshot
snapshotName=mySnapshotName

#Set the context to the subscription Id where snapshot exists
az account set --subscription $sourceSubscriptionId

#Get the snapshot Id 
snapshotId=$(az snapshot show --name $snapshotName --resource-group $sourceResourceGroupName --query [id] -o tsv)

#If snapshotId is blank then it means that snapshot does not exist.
echo 'source snapshot Id is: ' $snapshotId

#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=6492b1f7-f219-446b-b509-314e17e1efb0

#Name of the resource group where snapshot will be copied to
targetResourceGroupName=mytargetResourceGroupName

#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
az account set --subscription $targetSubscriptionId

#Copy snapshot to different subscription using the snapshot Id
#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/azure/storage/common/storage-redundancy-zrs#support-coverage-and-regional-availability
az snapshot create --resource-group $targetResourceGroupName --name $snapshotName --source $snapshotId --sku Standard_LRS

Ügyfelek által felügyelt kulcsokkal rendelkező lemezek

#Provide the subscription Id of the subscription where snapshot exists
sourceSubscriptionId="<subscriptionId>"

#Provide the name of your resource group where snapshot exists
sourceResourceGroupName=mySourceResourceGroupName

#Provide the name of the target disk encryption set
diskEncryptionSetName=myName

#Provide the target disk encryption set resource group
diskEncryptionResourceGroup=myGroup

#Provide the name of the snapshot
snapshotName=mySnapshotName

#Set the context to the subscription Id where snapshot exists
az account set --subscription $sourceSubscriptionId

#Get the snapshot Id 
snapshotId=$(az snapshot show --name $snapshotName --resource-group $sourceResourceGroupName --query [id] -o tsv)

#If snapshotId is blank then it means that snapshot does not exist.
echo 'source snapshot Id is: ' $snapshotId

#Get the disk encryption set ID
diskEncryptionSetId=$(az disk-encryption-set show --name $diskEncryptionSetName --resource-group $diskEncryptionResourceGroup)

#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=6492b1f7-f219-446b-b509-314e17e1efb0

#Name of the resource group where snapshot will be copied to
targetResourceGroupName=mytargetResourceGroupName

#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
az account set --subscription $targetSubscriptionId

#Copy snapshot to different subscription using the snapshot Id
#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/azure/storage/common/storage-redundancy-zrs#support-coverage-and-regional-availability
#To change the region, use the --location parameter
az snapshot create -g $targetResourceGroupName -n $snapshotName --source $snapshotId --disk-encryption-set $diskEncryptionSetID --sku Standard_LRS --encryption-type EncryptionAtRestWithCustomerKey

Clean up resources

Az alábbi paranccsal eltávolítható az erőforráscsoport, a virtuális gép és az összes kapcsolódó erőforrás.

az group delete --name mySourceResourceGroupName

Mintahivatkozás

Ez a szkript a következő parancsokkal hoz létre pillanatképet a cél-előfizetésben a Id forrás-pillanatkép használatával. A táblázatban lévő összes parancs a hozzá tartozó dokumentációra hivatkozik.

Parancs Jegyzetek
az snapshot show Lekérdezi egy pillanatkép összes tulajdonságát a pillanatkép neve és erőforráscsoport-tulajdonságai alapján. A Id tulajdonság a pillanatkép más előfizetésbe való másolására szolgál.
az snapshot create A pillanatképet úgy másolja át, hogy egy pillanatképet hoz létre egy másik előfizetésben a Id szülő pillanatkép neve és neve alapján.

Következő lépések

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

Az Azure CLI-vel kapcsolatos további információért lásd az Azure CLI dokumentációját.

További virtuális gépek és felügyelt lemezek parancssori felületének szkriptmintái az Azure Linux rendszerű virtuális gépek dokumentációjában találhatók.