Share via


Azure PowerShell kullanarak Azure sanal makinelerinde olağanüstü durum kurtarmayı ayarlama

Bu makalede, Azure PowerShell kullanarak Azure sanal makineleri için olağanüstü durum kurtarmayı ayarlamayı ve test etme işlemini göreceksiniz.

Şunları yapmayı öğreneceksiniz:

  • Kurtarma Hizmetleri kasası oluşturun.
  • PowerShell oturumu için kasa bağlamını ayarlayın.
  • Azure sanal makinelerini çoğaltmaya başlamak için kasayı hazırlayın.
  • Ağ eşlemeleri oluşturun.
  • Sanal makineleri çoğaltmak için depolama hesapları oluşturun.
  • Olağanüstü durum kurtarma için Azure sanal makinelerini bir kurtarma bölgesine çoğaltma.
  • Yük devretme testi gerçekleştirin, test yük devretmesini doğrulayın ve temizleyin.
  • Kurtarma bölgesine yük devretme.

Dekont

Portal aracılığıyla kullanılabilen tüm senaryo özellikleri Azure PowerShell aracılığıyla kullanılamayabilir. Şu anda Azure PowerShell aracılığıyla desteklenmeyen senaryo özelliklerinden bazıları şunlardır:

  • Sanal makinedeki tüm disklerin, sanal makinenin her diskini açıkça belirtmek zorunda kalmadan çoğaltılması gerektiğini belirtme özelliği.

Dekont

Azure ile etkileşim kurmak için Azure Az PowerShell modülünü kullanmanızı öneririz. Başlamak için bkz. Azure PowerShell'i yükleme. Az PowerShell modülüne nasıl geçeceğinizi öğrenmek için bkz. Azure PowerShell’i AzureRM’den Az’ye geçirme.

Önkoşullar

Başlamadan önce:

Microsoft Azure aboneliğinizde oturum açın

Cmdlet'iyle Connect-AzAccount Azure aboneliğinizde oturum açın.

Connect-AzAccount

Azure aboneliği seçin. Erişiminiz olan Get-AzSubscription Azure aboneliklerinin listesini almak için cmdlet'ini kullanın. cmdlet'ini kullanarak çalışmak için Azure aboneliğini Set-AzContext seçin.

Set-AzContext -SubscriptionId "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

Çoğaltılacak sanal makinenin ayrıntılarını alma

Bu makalede, Doğu ABD bölgesindeki bir sanal makine Batı ABD 2 bölgesinde çoğaltılır ve kurtarılır. Çoğaltılan sanal makinenin bir işletim sistemi diski ve tek bir veri diski vardır. Örnekte kullanılan sanal makinenin adıdır AzureDemoVM.

# Get details of the virtual machine
$VM = Get-AzVM -ResourceGroupName "A2AdemoRG" -Name "AzureDemoVM"

Write-Output $VM
ResourceGroupName  : A2AdemoRG
Id                 : /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/A2AdemoRG/providers/Microsoft.Compute/virtualMachines/AzureDemoVM
VmId               : 1b864902-c7ea-499a-ad0f-65da2930b81b
Name               : AzureDemoVM
Type               : Microsoft.Compute/virtualMachines
Location           : eastus
Tags               : {}
DiagnosticsProfile : {BootDiagnostics}
HardwareProfile    : {VmSize}
NetworkProfile     : {NetworkInterfaces}
OSProfile          : {ComputerName, AdminUsername, WindowsConfiguration, Secrets}
ProvisioningState  : Succeeded
StorageProfile     : {ImageReference, OsDisk, DataDisks}

Sanal makinenin diskleri için disk ayrıntılarını alın. Disk ayrıntıları daha sonra sanal makine için çoğaltma başlatılırken kullanılacaktır.

$OSDiskVhdURI = $VM.StorageProfile.OsDisk.Vhd
$DataDisk1VhdURI = $VM.StorageProfile.DataDisks[0].Vhd

Kurtarma Hizmetleri kasası oluşturma

Kurtarma Hizmetleri kasasının oluşturulacağı bir kaynak grubu oluşturun.

Önemli

  • Kurtarma hizmetleri kasası ve korunan sanal makineler farklı Azure konumlarında olmalıdır.
  • Kurtarma hizmetleri kasasının kaynak grubu ve korunan sanal makineler farklı Azure konumlarında olmalıdır.
  • Kurtarma hizmetleri kasası ve ait olduğu kaynak grubu aynı Azure konumunda olabilir.

Bu makaledeki örnekte, korunan sanal makine Doğu ABD bölgesindedir. Olağanüstü durum kurtarma için seçilen kurtarma bölgesi Batı ABD 2 bölgesidir. Kurtarma hizmetleri kasası ve kasanın kaynak grubu, batı ABD 2 kurtarma bölgesindedir.

#Create a resource group for the recovery services vault in the recovery Azure region
New-AzResourceGroup -Name "a2ademorecoveryrg" -Location "West US 2"
ResourceGroupName : a2ademorecoveryrg
Location          : westus2
ProvisioningState : Succeeded
Tags              :
ResourceId        : /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/a2ademorecoveryrg

Kurtarma hizmetleri kasası oluşturun. Bu örnekte, Batı ABD 2 bölgesinde adlı a2aDemoRecoveryVault bir Kurtarma Hizmetleri kasası oluşturulur.

#Create a new Recovery services vault in the recovery region
$vault = New-AzRecoveryServicesVault -Name "a2aDemoRecoveryVault" -ResourceGroupName "a2ademorecoveryrg" -Location "West US 2"

Write-Output $vault
Name              : a2aDemoRecoveryVault
ID                : /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/a2ademorecoveryrg/providers/Microsoft.RecoveryServices/vaults/a2aDemoRecoveryVault
Type              : Microsoft.RecoveryServices/vaults
Location          : westus2
ResourceGroupName : a2ademorecoveryrg
SubscriptionId    : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Properties        : Microsoft.Azure.Commands.RecoveryServices.ARSVaultProperties

Kasa bağlamını ayarlama

PowerShell oturumunda kullanmak üzere kasa bağlamını ayarlayın. Kasa bağlamı ayarlandıktan sonra, PowerShell oturumundaki Azure Site Recovery işlemleri seçilen kasa bağlamında gerçekleştirilir.

#Setting the vault context.
Set-AzRecoveryServicesAsrVaultContext -Vault $vault
ResourceName         ResourceGroupName ResourceNamespace          ResourceType
------------         ----------------- -----------------          -----------
a2aDemoRecoveryVault a2ademorecoveryrg Microsoft.RecoveryServices Vaults
#Delete the downloaded vault settings file
Remove-Item -Path $Vaultsettingsfile.FilePath

Azure'da Azure'a geçiş için kasa bağlamını yeni oluşturulan kasaya ayarlayabilirsiniz:

#Set the vault context for the PowerShell session.
Set-AzRecoveryServicesAsrVaultContext -Vault $vault

Azure sanal makinelerini çoğaltmaya başlamak için kasayı hazırlama

Birincil (kaynak) bölgeyi temsil eden bir Site Recovery doku nesnesi oluşturma

Kasadaki doku nesnesi bir Azure bölgesini temsil eder. Birincil doku nesnesi, kasada korunan sanal makinelerin ait olduğu Azure bölgesini temsil etmek için oluşturulur. Bu makaledeki örnekte, korunan sanal makine Doğu ABD bölgesindedir.

  • Bölge başına yalnızca bir yapı nesnesi oluşturulabilir.
  • Daha önce Azure portalında bir VM için Site Recovery çoğaltmasını etkinleştirdiyseniz, Site Recovery otomatik olarak bir doku nesnesi oluşturur. Bir bölge için doku nesnesi varsa, yeni bir tane oluşturamazsınız.

Başlamadan önce, Site Recovery işlemlerinin zaman uyumsuz olarak yürütüldüğünü anlayın. Bir işlemi başlattığınızda, bir Azure Site Recovery işi gönderilir ve bir iş izleme nesnesi döndürülür. İşin () en son durumunu almak ve işlemin durumunu izlemek için işGet-AzRecoveryServicesAsrJob izleme nesnesini kullanın.

#Create Primary ASR fabric
$TempASRJob = New-AzRecoveryServicesAsrFabric -Azure -Location 'East US'  -Name "A2Ademo-EastUS"

# Track Job status to check for completion
while (($TempASRJob.State -eq "InProgress") -or ($TempASRJob.State -eq "NotStarted")){
        #If the job hasn't completed, sleep for 10 seconds before checking the job status again
        sleep 10;
        $TempASRJob = Get-AzRecoveryServicesAsrJob -Job $TempASRJob
}

#Check if the Job completed successfully. The updated job state of a successfully completed job should be "Succeeded"
Write-Output $TempASRJob.State

$PrimaryFabric = Get-AzRecoveryServicesAsrFabric -Name "A2Ademo-EastUS"

Birden çok Azure bölgesinden sanal makineler aynı kasada korunuyorsa, her kaynak Azure bölgesi için bir doku nesnesi oluşturun.

Kurtarma bölgesini temsil eden bir Site Recovery dokusu nesnesi oluşturma

Kurtarma dokusu nesnesi, kurtarma Azure konumunu temsil eder. Yük devretme varsa, sanal makineler çoğaltılır ve kurtarma dokusu tarafından temsil edilen kurtarma bölgesine kurtarılır. Bu örnekte kullanılan kurtarma Azure bölgesi Batı ABD 2'dir.

#Create Recovery ASR fabric
$TempASRJob = New-AzRecoveryServicesAsrFabric -Azure -Location 'West US 2'  -Name "A2Ademo-WestUS"

# Track Job status to check for completion
while (($TempASRJob.State -eq "InProgress") -or ($TempASRJob.State -eq "NotStarted")){
        sleep 10;
        $TempASRJob = Get-AzRecoveryServicesAsrJob -Job $TempASRJob
}

#Check if the Job completed successfully. The updated job state of a successfully completed job should be "Succeeded"
Write-Output $TempASRJob.State

$RecoveryFabric = Get-AzRecoveryServicesAsrFabric -Name "A2Ademo-WestUS"

Birincil dokuda Site Recovery koruma kapsayıcısı oluşturma

Koruma kapsayıcısı, bir doku içinde çoğaltılan öğeleri gruplandırmak için kullanılan bir kapsayıcıdır.

#Create a Protection container in the primary Azure region (within the Primary fabric)
$TempASRJob = New-AzRecoveryServicesAsrProtectionContainer -InputObject $PrimaryFabric -Name "A2AEastUSProtectionContainer"

#Track Job status to check for completion
while (($TempASRJob.State -eq "InProgress") -or ($TempASRJob.State -eq "NotStarted")){
        sleep 10;
        $TempASRJob = Get-AzRecoveryServicesAsrJob -Job $TempASRJob
}

Write-Output $TempASRJob.State

$PrimaryProtContainer = Get-AzRecoveryServicesAsrProtectionContainer -Fabric $PrimaryFabric -Name "A2AEastUSProtectionContainer"

Kurtarma dokusunda Site Recovery koruma kapsayıcısı oluşturma

#Create a Protection container in the recovery Azure region (within the Recovery fabric)
$TempASRJob = New-AzRecoveryServicesAsrProtectionContainer -InputObject $RecoveryFabric -Name "A2AWestUSProtectionContainer"

#Track Job status to check for completion
while (($TempASRJob.State -eq "InProgress") -or ($TempASRJob.State -eq "NotStarted")){
        sleep 10;
        $TempASRJob = Get-AzRecoveryServicesAsrJob -Job $TempASRJob
}

#Check if the Job completed successfully. The updated job state of a successfully completed job should be "Succeeded"

Write-Output $TempASRJob.State

$RecoveryProtContainer = Get-AzRecoveryServicesAsrProtectionContainer -Fabric $RecoveryFabric -Name "A2AWestUSProtectionContainer"

Bölgeden bölgeye çoğaltmayı etkinleştirirken doku ve kapsayıcı oluşturma

Bölgeden bölgeye çoğaltma etkinleştirilirken, yalnızca bir yapı oluşturulur. Ama iki kapsayıcı olacak. Bölgenin Batı Avrupa olduğunu varsayarsak, birincil ve koruma kapsayıcılarını almak için aşağıdaki komutları kullanın -

$primaryProtectionContainer = Get-AzRecoveryServicesAsrProtectionContainer -Fabric $fabric -Name "asr-a2a-default-westeurope-container"
$recoveryPprotectionContainer = Get-AzRecoveryServicesAsrProtectionContainer -Fabric $fabric -Name "asr-a2a-default-westeurope-t-container"

Çoğaltma ilkesi oluşturma

#Create replication policy
$TempASRJob = New-AzRecoveryServicesAsrPolicy -AzureToAzure -Name "A2APolicy" -RecoveryPointRetentionInHours 24 -ApplicationConsistentSnapshotFrequencyInHours 4

#Track Job status to check for completion
while (($TempASRJob.State -eq "InProgress") -or ($TempASRJob.State -eq "NotStarted")){
        sleep 10;
        $TempASRJob = Get-AzRecoveryServicesAsrJob -Job $TempASRJob
}

#Check if the Job completed successfully. The updated job state of a successfully completed job should be "Succeeded"
Write-Output $TempASRJob.State

$ReplicationPolicy = Get-AzRecoveryServicesAsrPolicy -Name "A2APolicy"

Birincil ve kurtarma koruma kapsayıcısı arasında koruma kapsayıcısı eşlemesi oluşturma

Koruma kapsayıcısı eşlemesi, birincil koruma kapsayıcısını kurtarma koruma kapsayıcısı ve çoğaltma ilkesiyle eşler. Sanal makineleri bir koruma kapsayıcısı çifti arasında çoğaltmak için kullanacağınız her çoğaltma ilkesi için bir eşleme oluşturun.

#Create Protection container mapping between the Primary and Recovery Protection Containers with the Replication policy
$TempASRJob = New-AzRecoveryServicesAsrProtectionContainerMapping -Name "A2APrimaryToRecovery" -Policy $ReplicationPolicy -PrimaryProtectionContainer $PrimaryProtContainer -RecoveryProtectionContainer $RecoveryProtContainer

#Track Job status to check for completion
while (($TempASRJob.State -eq "InProgress") -or ($TempASRJob.State -eq "NotStarted")){
        sleep 10;
        $TempASRJob = Get-AzRecoveryServicesAsrJob -Job $TempASRJob
}

#Check if the Job completed successfully. The updated job state of a successfully completed job should be "Succeeded"
Write-Output $TempASRJob.State

$EusToWusPCMapping = Get-AzRecoveryServicesAsrProtectionContainerMapping -ProtectionContainer $PrimaryProtContainer -Name "A2APrimaryToRecovery"

Bölgeden bölgeye çoğaltma etkinleştirilirken koruma kapsayıcısı eşlemesi oluşturma

Bölgeden bölgeye çoğaltmayı etkinleştirirken, koruma kapsayıcısı eşlemesi oluşturmak için aşağıdaki komutu kullanın. Bölgenin Batı Avrupa olduğunu varsayarsak komut şu şekilde olacaktır:

$protContainerMapping = Get-AzRecoveryServicesAsrProtectionContainerMapping -ProtectionContainer $PrimprotectionContainer -Name "westeurope-westeurope-24-hour-retention-policy-s"

Yeniden çalışma için koruma kapsayıcısı eşlemesi oluşturma (yük devretmeden sonra çoğaltmayı tersine çevirme)

Yük devretme işleminden sonra, yük devredilen sanal makineyi özgün Azure bölgesine geri getirmeye hazır olduğunuzda yeniden çalışma yaparsınız. Yeniden çalışma için, yük devredilen sanal makine, yük devredilen bölgeden özgün bölgeye ters çoğaltılır. Tersine çoğaltma için özgün bölgenin ve kurtarma bölgesi anahtarının rolleri. Özgün bölge artık yeni kurtarma bölgesi, kurtarma bölgesi ise birincil bölge haline geldi. Ters çoğaltma için koruma kapsayıcısı eşlemesi, özgün ve kurtarma bölgelerinin değiştirilmiş rollerini temsil eder.

#Create Protection container mapping (for fail back) between the Recovery and Primary Protection Containers with the Replication policy
$TempASRJob = New-AzRecoveryServicesAsrProtectionContainerMapping -Name "A2ARecoveryToPrimary" -Policy $ReplicationPolicy -PrimaryProtectionContainer $RecoveryProtContainer -RecoveryProtectionContainer $PrimaryProtContainer

#Track Job status to check for completion
while (($TempASRJob.State -eq "InProgress") -or ($TempASRJob.State -eq "NotStarted")){
        sleep 10;
        $TempASRJob = Get-AzRecoveryServicesAsrJob -Job $TempASRJob
}

#Check if the Job completed successfully. The updated job state of a successfully completed job should be "Succeeded"
Write-Output $TempASRJob.State

$WusToEusPCMapping = Get-AzRecoveryServicesAsrProtectionContainerMapping -ProtectionContainer $RecoveryProtContainer -Name "A2ARecoveryToPrimary"

Önbellek depolama hesabı ve hedef depolama hesabı oluşturma

Önbellek depolama hesabı, çoğaltılan sanal makineyle aynı Azure bölgesinde bulunan standart bir depolama hesabıdır. Önbellek depolama hesabı, değişiklikler kurtarma Azure bölgesine taşınmadan önce çoğaltma değişikliklerini geçici olarak tutmak için kullanılır. Daha yüksek değişim sıklığı sınırları elde etmek için Azure Site Recovery'de de yüksek değişim sıklığı desteği sağlanır. Bu özelliği kullanmak için lütfen Premium Blok Blobu türünde bir depolama hesabı oluşturun ve önbellek depolama hesabı olarak kullanın. Bir sanal makinenin farklı diskleri için farklı önbellek depolama hesapları belirtmeyi seçebilirsiniz, ancak bu gerekli değildir. Farklı önbellek depolama hesapları kullanıyorsanız, bunların aynı türde olduğundan emin olun (Standart veya Premium Blok Blobları). Daha fazla bilgi için bkz . Azure VM Olağanüstü Durum Kurtarma - Yüksek Değişim Sıklığı Desteği.

#Create Cache storage account for replication logs in the primary region
$EastUSCacheStorageAccount = New-AzStorageAccount -Name "a2acachestorage" -ResourceGroupName "A2AdemoRG" -Location 'East US' -SkuName Standard_LRS -Kind Storage

Yönetilen disk kullanmayan sanal makineler için hedef depolama hesabı, sanal makinenin disklerinin çoğaltıldığı kurtarma bölgesindeki depolama hesabıdır. Hedef depolama hesabı standart bir depolama hesabı veya premium depolama hesabı olabilir. Diskler için veri değişim oranına (GÇ yazma hızı) ve depolama türü için Azure Site Recovery tarafından desteklenen değişim sıklığı sınırlarına göre gerekli depolama hesabı türünü seçin.

#Create Target storage account in the recovery region. In this case a Standard Storage account
$WestUSTargetStorageAccount = New-AzStorageAccount -Name "a2atargetstorage" -ResourceGroupName "a2ademorecoveryrg" -Location 'West US 2' -SkuName Standard_LRS -Kind Storage

Ağ eşlemeleri oluşturma

Ağ eşlemesi, birincil bölgedeki sanal ağları kurtarma bölgesindeki sanal ağlarla eşler. Ağ eşlemesi, birincil sanal ağdaki bir sanal makinenin yük devretmesi gereken kurtarma bölgesindeki Azure sanal ağını belirtir. Bir Azure sanal ağı, kurtarma bölgesindeki yalnızca tek bir Azure sanal ağına eşlenebilir.

  • Yük devretme için kurtarma bölgesinde bir Azure sanal ağı oluşturun:

      #Create a Recovery Network in the recovery region
      $WestUSRecoveryVnet = New-AzVirtualNetwork -Name "a2arecoveryvnet" -ResourceGroupName "a2ademorecoveryrg" -Location 'West US 2' -AddressPrefix "10.0.0.0/16"
    
      Add-AzVirtualNetworkSubnetConfig -Name "default" -VirtualNetwork $WestUSRecoveryVnet -AddressPrefix "10.0.0.0/20" | Set-AzVirtualNetwork
    
      $WestUSRecoveryNetwork = $WestUSRecoveryVnet.Id
    
  • Birincil sanal ağı alın. Sanal makinenin bağlı olduğu sanal ağ:

      #Retrieve the virtual network that the virtual machine is connected to
    
      #Get first network interface card(nic) of the virtual machine
      $SplitNicArmId = $VM.NetworkProfile.NetworkInterfaces[0].Id.split("/")
    
      #Extract resource group name from the ResourceId of the nic
      $NICRG = $SplitNicArmId[4]
    
      #Extract resource name from the ResourceId of the nic
      $NICname = $SplitNicArmId[-1]
    
      #Get network interface details using the extracted resource group name and resource name
      $NIC = Get-AzNetworkInterface -ResourceGroupName $NICRG -Name $NICname
    
      #Get the subnet ID of the subnet that the nic is connected to
      $PrimarySubnet = $NIC.IpConfigurations[0].Subnet
    
      # Extract the resource ID of the Azure virtual network the nic is connected to from the subnet ID
      $EastUSPrimaryNetwork = (Split-Path(Split-Path($PrimarySubnet.Id))).Replace("\","/")
    
  • Birincil sanal ağ ile kurtarma sanal ağı arasında ağ eşlemesi oluşturun:

      #Create an ASR network mapping between the primary Azure virtual network and the recovery Azure virtual network
      $TempASRJob = New-AzRecoveryServicesAsrNetworkMapping -AzureToAzure -Name "A2AEusToWusNWMapping" -PrimaryFabric $PrimaryFabric -PrimaryAzureNetworkId $EastUSPrimaryNetwork -RecoveryFabric $RecoveryFabric -RecoveryAzureNetworkId $WestUSRecoveryNetwork
    
      #Track Job status to check for completion
      while (($TempASRJob.State -eq "InProgress") -or ($TempASRJob.State -eq "NotStarted")){
              sleep 10;
              $TempASRJob = Get-AzRecoveryServicesAsrJob -Job $TempASRJob
      }
    
      #Check if the Job completed successfully. The updated job state of a successfully completed job should be "Succeeded"
      Write-Output $TempASRJob.State
    
  • Ters yönde ağ eşlemesi oluşturun (yeniden çalışma):

    #Create an ASR network mapping for fail back between the recovery Azure virtual network and the primary Azure virtual network
    $TempASRJob = New-AzRecoveryServicesAsrNetworkMapping -AzureToAzure -Name "A2AWusToEusNWMapping" -PrimaryFabric $RecoveryFabric -PrimaryAzureNetworkId $WestUSRecoveryNetwork -RecoveryFabric $PrimaryFabric -RecoveryAzureNetworkId $EastUSPrimaryNetwork
    
    #Track Job status to check for completion
    while (($TempASRJob.State -eq "InProgress") -or ($TempASRJob.State -eq "NotStarted")){
            sleep 10;
            $TempASRJob = Get-AzRecoveryServicesAsrJob -Job $TempASRJob
    }
    
    #Check if the Job completed successfully. The updated job state of a successfully completed job should be "Succeeded"
    Write-Output $TempASRJob.State
    

Azure sanal makinesini çoğaltma

Azure sanal makinesini yönetilen disklerle çoğaltma.

#Get the resource group that the virtual machine must be created in when failed over.
$RecoveryRG = Get-AzResourceGroup -Name "a2ademorecoveryrg" -Location "West US 2"

#Specify replication properties for each disk of the VM that is to be replicated (create disk replication configuration)

#OsDisk
$OSdiskId = $vm.StorageProfile.OsDisk.ManagedDisk.Id
$RecoveryOSDiskAccountType = $vm.StorageProfile.OsDisk.ManagedDisk.StorageAccountType
$RecoveryReplicaDiskAccountType = $vm.StorageProfile.OsDisk.ManagedDisk.StorageAccountType

$OSDiskReplicationConfig = New-AzRecoveryServicesAsrAzureToAzureDiskReplicationConfig -ManagedDisk -LogStorageAccountId $EastUSCacheStorageAccount.Id `
         -DiskId $OSdiskId -RecoveryResourceGroupId  $RecoveryRG.ResourceId -RecoveryReplicaDiskAccountType  $RecoveryReplicaDiskAccountType `
         -RecoveryTargetDiskAccountType $RecoveryOSDiskAccountType

# Data disk
$datadiskId1 = $vm.StorageProfile.DataDisks[0].ManagedDisk.Id
$RecoveryReplicaDiskAccountType = $vm.StorageProfile.DataDisks[0].ManagedDisk.StorageAccountType
$RecoveryTargetDiskAccountType = $vm.StorageProfile.DataDisks[0].ManagedDisk.StorageAccountType

$DataDisk1ReplicationConfig  = New-AzRecoveryServicesAsrAzureToAzureDiskReplicationConfig -ManagedDisk -LogStorageAccountId $EastUSCacheStorageAccount.Id `
         -DiskId $datadiskId1 -RecoveryResourceGroupId $RecoveryRG.ResourceId -RecoveryReplicaDiskAccountType $RecoveryReplicaDiskAccountType `
         -RecoveryTargetDiskAccountType $RecoveryTargetDiskAccountType

#Create a list of disk replication configuration objects for the disks of the virtual machine that are to be replicated.
$diskconfigs = @()
$diskconfigs += $OSDiskReplicationConfig, $DataDisk1ReplicationConfig

#Start replication by creating replication protected item. Using a GUID for the name of the replication protected item to ensure uniqueness of name.
$TempASRJob = New-AzRecoveryServicesAsrReplicationProtectedItem -AzureToAzure -AzureVmId $VM.Id -Name (New-Guid).Guid -ProtectionContainerMapping $EusToWusPCMapping -AzureToAzureDiskReplicationConfiguration $diskconfigs -RecoveryResourceGroupId $RecoveryRG.ResourceId

Azure sanal makinesini yönetilmeyen disklerle çoğaltma.

#Specify replication properties for each disk of the VM that is to be replicated (create disk replication configuration)

#Disk replication configuration for the OS disk
$OSDiskReplicationConfig = New-AzRecoveryServicesAsrAzureToAzureDiskReplicationConfig -VhdUri $OSDiskVhdURI.Uri -LogStorageAccountId $EastUSCacheStorageAccount.Id -RecoveryAzureStorageAccountId $WestUSTargetStorageAccount.Id

#Disk replication configuration for data disk
$DataDisk1ReplicationConfig = New-AzRecoveryServicesAsrAzureToAzureDiskReplicationConfig -VhdUri $DataDisk1VhdURI.Uri -LogStorageAccountId $EastUSCacheStorageAccount.Id -RecoveryAzureStorageAccountId $WestUSTargetStorageAccount.Id

#Create a list of disk replication configuration objects for the disks of the virtual machine that are to be replicated.
$diskconfigs = @()
$diskconfigs += $OSDiskReplicationConfig, $DataDisk1ReplicationConfig

#Get the resource group that the virtual machine must be created in when failed over.
$RecoveryRG = Get-AzResourceGroup -Name "a2ademorecoveryrg" -Location "West US 2"

#Start replication by creating replication protected item. Using a GUID for the name of the replication protected item to ensure uniqueness of name.
$TempASRJob = New-AzRecoveryServicesAsrReplicationProtectedItem -AzureToAzure -AzureVmId $VM.Id -Name (New-Guid).Guid -ProtectionContainerMapping $EusToWusPCMapping -AzureToAzureDiskReplicationConfiguration $diskconfigs -RecoveryResourceGroupId $RecoveryRG.ResourceId

#Track Job status to check for completion
while (($TempASRJob.State -eq "InProgress") -or ($TempASRJob.State -eq "NotStarted")){
        sleep 10;
        $TempASRJob = Get-AzRecoveryServicesAsrJob -Job $TempASRJob
}

#Check if the Job completed successfully. The updated job state of a successfully completed job should be "Succeeded"
Write-Output $TempASRJob.State

Çoğaltmayı başlatma işlemi başarılı olduktan sonra sanal makine verileri kurtarma bölgesine çoğaltılır.

Çoğaltma işlemi başlangıçta kurtarma bölgesindeki sanal makinenin çoğaltma disklerinin bir kopyasının dağıtımını yaparak başlar. Bu aşama, ilk çoğaltma aşaması olarak adlandırılır.

İlk çoğaltma tamamlandıktan sonra, çoğaltma değişiklik eşitleme aşamasına geçer. Bu noktada sanal makine korunur ve üzerinde bir yük devretme testi işlemi gerçekleştirilebilir. Sanal makineyi temsil eden çoğaltılan öğenin çoğaltma durumu, ilk çoğaltma tamamlandıktan sonra Korumalı duruma geçer.

Sanal makineye karşılık gelen çoğaltma korumalı öğenin ayrıntılarını alarak sanal makine için çoğaltma durumunu ve çoğaltma durumunu izleyin.

Get-AzRecoveryServicesAsrReplicationProtectedItem -ProtectionContainer $PrimaryProtContainer | Select FriendlyName, ProtectionState, ReplicationHealth
FriendlyName ProtectionState ReplicationHealth
------------ --------------- -----------------
AzureDemoVM  Protected       Normal

Yük devretme testi yapma, test yük devretmesini doğrulama ve temizleme

Sanal makine için çoğaltma korumalı duruma ulaştıktan sonra, sanal makinede (sanal makinenin çoğaltma korumalı öğesinde) bir yük devretme testi işlemi gerçekleştirilebilir.

#Create a separate network for test failover (not connected to my DR network)
$TFOVnet = New-AzVirtualNetwork -Name "a2aTFOvnet" -ResourceGroupName "a2ademorecoveryrg" -Location 'West US 2' -AddressPrefix "10.3.0.0/16"

Add-AzVirtualNetworkSubnetConfig -Name "default" -VirtualNetwork $TFOVnet -AddressPrefix "10.3.0.0/20" | Set-AzVirtualNetwork

$TFONetwork= $TFOVnet.Id

Yük devretme testi yapın.

$ReplicationProtectedItem = Get-AzRecoveryServicesAsrReplicationProtectedItem -FriendlyName "AzureDemoVM" -ProtectionContainer $PrimaryProtContainer

$TFOJob = Start-AzRecoveryServicesAsrTestFailoverJob -ReplicationProtectedItem $ReplicationProtectedItem -AzureVMNetworkId $TFONetwork -Direction PrimaryToRecovery

Yük devretme testi işleminin tamamlanmasını bekleyin.

Get-AzRecoveryServicesAsrJob -Job $TFOJob
Name             : 3dcb043e-3c6d-4e0e-a42e-8d4245668547
ID               : /Subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/a2ademorecoveryrg/providers/Microsoft.RecoveryServices/vaults/a2aDemoR
                   ecoveryVault/replicationJobs/3dcb043e-3c6d-4e0e-a42e-8d4245668547
Type             : Microsoft.RecoveryServices/vaults/replicationJobs
JobType          : TestFailover
DisplayName      : Test failover
ClientRequestId  : 1ef8515b-b130-4452-a44d-91aaf071931c ActivityId: 907bb2bc-ebe6-4732-8b66-77d0546eaba8
State            : Succeeded
StateDescription : Completed
StartTime        : 4/25/2018 4:29:43 AM
EndTime          : 4/25/2018 4:33:06 AM
TargetObjectId   : ce86206c-bd78-53b4-b004-39b722c1ac3a
TargetObjectType : ProtectionEntity
TargetObjectName : azuredemovm
AllowedActions   :
Tasks            : {Prerequisites check for test failover, Create test virtual machine, Preparing the virtual machine, Start the virtual machine}
Errors           : {}

Yük devretme testi işi başarıyla tamamlandıktan sonra sanal makine üzerinden başarısız olan teste bağlanabilir ve yük devretme testini doğrulayabilirsiniz.

Sanal makinede yük devretme testi tamamlandıktan sonra, test yük devretme işlemini temizleyerek test kopyasını temizleyin. Bu işlem, yük devretme testi tarafından oluşturulan sanal makinenin test kopyasını siler.

$Job_TFOCleanup = Start-AzRecoveryServicesAsrTestFailoverCleanupJob -ReplicationProtectedItem $ReplicationProtectedItem

Get-AzRecoveryServicesAsrJob -Job $Job_TFOCleanup | Select State
State
-----
Succeeded

Azure'a yük devretme

Sanal makinenin yükünü belirli bir kurtarma noktasına devredin.

$RecoveryPoints = Get-AzRecoveryServicesAsrRecoveryPoint -ReplicationProtectedItem $ReplicationProtectedItem

#The list of recovery points returned may not be sorted chronologically and will need to be sorted first, in order to be able to find the oldest or the latest recovery points for the virtual machine.
"{0} {1}" -f $RecoveryPoints[0].RecoveryPointType, $RecoveryPoints[-1].RecoveryPointTime
CrashConsistent 4/24/2018 11:10:25 PM
#Start the fail over job
$Job_Failover = Start-AzRecoveryServicesAsrUnplannedFailoverJob -ReplicationProtectedItem $ReplicationProtectedItem -Direction PrimaryToRecovery -RecoveryPoint $RecoveryPoints[-1]

do {
        $Job_Failover = Get-AzRecoveryServicesAsrJob -Job $Job_Failover;
        sleep 30;
} while (($Job_Failover.State -eq "InProgress") -or ($JobFailover.State -eq "NotStarted"))

$Job_Failover.State
Succeeded

Yük devretme işi başarılı olduğunda, yük devretme işlemini işleyebilirsiniz.

$CommitFailoverJOb = Start-AzRecoveryServicesAsrCommitFailoverJob -ReplicationProtectedItem $ReplicationProtectedItem

Get-AzRecoveryServicesAsrJob -Job $CommitFailoverJOb
Name             : 58afc2b7-5cfe-4da9-83b2-6df358c6e4ff
ID               : /Subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/a2ademorecoveryrg/providers/Microsoft.RecoveryServices/vaults/a2aDemoR
                   ecoveryVault/replicationJobs/58afc2b7-5cfe-4da9-83b2-6df358c6e4ff
Type             : Microsoft.RecoveryServices/vaults/replicationJobs
JobType          : CommitFailover
DisplayName      : Commit
ClientRequestId  : 10a95d6c-359e-4603-b7d9-b7ee3317ce94 ActivityId: 8751ada4-fc42-4238-8de6-a82618408fcf
State            : Succeeded
StateDescription : Completed
StartTime        : 4/25/2018 4:50:58 AM
EndTime          : 4/25/2018 4:51:01 AM
TargetObjectId   : ce86206c-bd78-53b4-b004-39b722c1ac3a
TargetObjectType : ProtectionEntity
TargetObjectName : azuredemovm
AllowedActions   :
Tasks            : {Prerequisite check, Commit}
Errors           : {}

Kaynak bölgeyi yeniden koruma ve yeniden çalışma

Yük devretme işleminden sonra, özgün bölgeye geri dönmeye hazır olduğunuzda, cmdlet'ini kullanarak çoğaltma korumalı öğe için ters çoğaltmayı Update-AzRecoveryServicesAsrProtectionDirection başlatın.

#Create Cache storage account for replication logs in the primary region
$WestUSCacheStorageAccount = New-AzStorageAccount -Name "a2acachestoragewestus" -ResourceGroupName "A2AdemoRG" -Location 'West US' -SkuName Standard_LRS -Kind Storage
#Use the recovery protection container, new cache storage account in West US and the source region VM resource group
Update-AzRecoveryServicesAsrProtectionDirection -ReplicationProtectedItem $ReplicationProtectedItem -AzureToAzure
-ProtectionContainerMapping $WusToEusPCMapping -LogStorageAccountId $WestUSCacheStorageAccount.Id -RecoveryResourceGroupID $sourceVMResourcegroup.ResourceId

Yeniden koruma tamamlandıktan sonra ters yönde, Batı ABD'den Doğu ABD'ye yük devredebilir ve kaynak bölgeye geri dönebilirsiniz.

Çoğaltmayı devre dışı bırakma

Cmdlet ile çoğaltmayı Remove-AzRecoveryServicesAsrReplicationProtectedItem devre dışı bırakabilirsiniz.

Remove-AzRecoveryServicesAsrReplicationProtectedItem -ReplicationProtectedItem $ReplicationProtectedItem

Sonraki adımlar

Kurtarma planları oluşturma ve PowerShell ile kurtarma planlarının yük devretmesini test etme gibi diğer görevleri nasıl yapabileceğinizi öğrenmek için Azure Site Recovery PowerShell başvurusunu görüntüleyin.