この記事では、Azure PowerShell を使用して Azure 仮想マシンのディザスター リカバリーを設定してテストする方法について説明します。
次の方法を学びます:
- Recovery Services コンテナーを作成します。
- PowerShell セッションのボールト コンテキストを設定します。
- Azure 仮想マシンのレプリケートを開始するようにコンテナーを準備します。
- ネットワーク マッピングを作成します。
- 仮想マシンをレプリケートするストレージ アカウントを作成します。
- ディザスター リカバリーのために Azure 仮想マシンを復旧リージョンにレプリケートします。
- テスト フェールオーバーを実行し、テスト フェールオーバーを検証し、クリーンアップします。
- 復旧リージョンにフェールオーバーします。
注
ポータルから利用できるシナリオ機能の一部が Azure PowerShell で利用できるわけではありません。 Azure PowerShell で現在サポートされていないシナリオ機能の一部を次に示します。
- 仮想マシンの各ディスクを明示的に指定しなくても、仮想マシン内のすべてのディスクをレプリケートするように指定する機能。
注
Azure Az PowerShell モジュールを使用して Azure と対話することをお勧めします。 作業を始めるには、「Azure PowerShell をインストールする」を参照してください。 Az PowerShell モジュールに移行する方法については、「 Azure PowerShell を AzureRM から Az に移行する」を参照してください。
[前提条件]
開始する前に次の操作を実行してください。
- シナリオのアーキテクチャとコンポーネントを理解していることを確認します。
- すべてのコンポーネントの サポート要件 を確認します。
- Azure PowerShell
Az
モジュールがあります。 Azure PowerShell をインストールまたはアップグレードする必要がある場合は、この ガイドに従って Azure PowerShell をインストールして構成します。
Microsoft Azure サブスクリプションにサインインする
Connect-AzAccount
コマンドレットを使用して Azure サブスクリプションにサインインします。
Connect-AzAccount
Azure のサブスクリプションを選択します。
Get-AzSubscription
コマンドレットを使用して、アクセス権を持つ Azure サブスクリプションの一覧を取得します。
Set-AzContext
コマンドレットを使用して操作する Azure サブスクリプションを選択します。
Set-AzContext -SubscriptionId "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
レプリケートする仮想マシンの詳細を取得する
この記事では、米国東部リージョンの仮想マシンを米国西部 2 リージョンにレプリケートして復旧します。 レプリケートされる仮想マシンには、OS ディスクと 1 つのデータ ディスクがあります。 この例で使用されている仮想マシンの名前は 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}
仮想マシンのディスク詳細を取得します。 ディスクの詳細は、後で仮想マシンのレプリケーションを開始するときに使用されます。
$OSDiskVhdURI = $VM.StorageProfile.OsDisk.Vhd
$DataDisk1VhdURI = $VM.StorageProfile.DataDisks[0].Vhd
Recovery Services ボールトを作成する
Recovery Services コンテナーを作成するリソース グループを作成します。
Von Bedeutung
- Recovery Services コンテナーと保護されている仮想マシンは、異なる Azure の場所にある必要があります。
- Recovery Services コンテナーのリソース グループと保護対象の仮想マシンは、異なる Azure の場所に存在する必要があります。
- Recovery Services コンテナーと、それが属するリソース グループは、同じ Azure の場所に配置できます。
この記事の例では、保護されている仮想マシンは米国東部リージョンにあります。 ディザスター リカバリー用に選択された復旧リージョンは、米国西部 2 リージョンです。 Recovery Services コンテナーと、コンテナーのリソース グループは、いずれも復旧リージョン (米国西部 2) 内にあります。
#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
Recovery Services コンテナーを作成します。 この例では、a2aDemoRecoveryVault
という名前の Recovery Services コンテナーが米国西部 2 リージョン内に作成されます。
#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
コンテナーのコンテキストを設定する
PowerShell セッションで使用するボールト コンテキストを設定します。 コンテナー コンテキストが設定されると、PowerShell セッションでの Azure Site Recovery 操作が、選択したコンテナーのコンテキストで実行されます。
#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 から Azure への移行では、コンテナー コンテキストを新しく作成されたコンテナーに設定できます。
#Set the vault context for the PowerShell session.
Set-AzRecoveryServicesAsrVaultContext -Vault $vault
Azure 仮想マシンのレプリケーションを開始するためにボールトを準備する
プライマリ (ソース) リージョンを表す Site Recovery ファブリック オブジェクトを作成する
コンテナー内のファブリック オブジェクトは、Azure リージョンを表します。 プライマリ ファブリック オブジェクトは、コンテナーで保護されている仮想マシンが属する Azure リージョンを表すために作成されます。 この記事の例では、保護されている仮想マシンは米国東部リージョンにあります。
- リージョンごとに作成できるファブリック オブジェクトは 1 つだけです。
- Azure portal で VM の Site Recovery レプリケーションを以前に有効にしている場合、Site Recovery によってファブリック オブジェクトが自動的に作成されます。 リージョンにファブリック オブジェクトが存在する場合、新しいオブジェクトを作成することはできません。
開始する前に、Site Recovery 操作が非同期的に実行されることを理解してください。 操作を開始すると、Azure Site Recovery ジョブが送信されて、ジョブ追跡オブジェクトが返されます。 ジョブ追跡オブジェクトを使用して、ジョブの最新の状態 (Get-AzRecoveryServicesAsrJob
) を取得し、操作の状態を監視します。
#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"
複数の Azure リージョンの仮想マシンが同じコンテナーに保護されている場合は、ソース Azure リージョンごとに 1 つのファブリック オブジェクトを作成します。
復旧リージョンを表す Site Recovery ファブリック オブジェクトを作成する
復旧ファブリック オブジェクトは、復旧 Azure の場所を表します。 フェールオーバーがある場合、仮想マシンはレプリケートされ、復旧ファブリックによって表される復旧リージョンに復旧されます。 この例で使用される復旧 Azure リージョンは米国西部 2 です。
#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"
プライマリ ファブリックで Site Recovery 保護コンテナーを作成する
保護コンテナーは、ファブリック内のレプリケートされた項目をグループ化するために使用されるコンテナーです。
#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"
回復ファブリックで Site Recovery 保護コンテナーを作成する
#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"
ゾーン間レプリケーションを有効にするときのファブリックとコンテナーの作成
ゾーン間レプリケーションを有効にすると、1 つのファブリックのみが作成されます。 ただし、2 つのコンテナーがあります。 リージョンが西ヨーロッパであると仮定すると、次のコマンドを使用してプライマリ コンテナーと保護コンテナーを取得します。
$primaryProtectionContainer = Get-AzRecoveryServicesAsrProtectionContainer -Fabric $fabric -Name "asr-a2a-default-westeurope-container"
$recoveryProtectionContainer = Get-AzRecoveryServicesAsrProtectionContainer -Fabric $fabric -Name "asr-a2a-default-westeurope-t-container"
レプリケーション ポリシーを作成する
#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"
プライマリ保護コンテナーと回復保護コンテナーの間の保護コンテナー マッピングを作成する
保護コンテナー マッピングは、プライマリ保護コンテナーを復旧保護コンテナーとレプリケーション ポリシーにマップします。 保護コンテナー ペア間で仮想マシンをレプリケートするために使用するレプリケーション ポリシーごとに 1 つのマッピングを作成します。
#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"
ゾーン間レプリケーションを有効にするときの保護コンテナー マッピングの作成
ゾーン間レプリケーションを有効にする場合は、次のコマンドを使用して保護コンテナー マッピングを作成します。 リージョンが西ヨーロッパであると仮定すると、コマンドは次のコマンドになります。
$protContainerMapping = Get-AzRecoveryServicesAsrProtectionContainerMapping -ProtectionContainer $PrimprotectionContainer -Name "westeurope-westeurope-24-hour-retention-policy-s"
フェールバック用の保護コンテナー マッピングを作成する (フェールオーバー後のレプリケーションの反転)
フェールオーバー後、フェールオーバーされた仮想マシンを元の Azure リージョンに戻す準備ができたら、フェールバックを実行します。 フェールバックするには、フェールオーバーされた仮想マシンがフェールオーバーされたリージョンから元のリージョンに逆レプリケートされます。 レプリケーションの反転の際には、元のリージョンと復旧リージョンの役割が入れ替わります。 元のリージョンが新しい復旧リージョンになり、元の復旧リージョンであったものがプライマリ リージョンになります。 逆レプリケーションの保護コンテナー マッピングは、元のリージョンと復旧リージョンの切り替え済みロールを表します。
#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"
キャッシュ ストレージ アカウントとターゲット ストレージ アカウントを作成する
キャッシュ ストレージ アカウントは、レプリケートされる仮想マシンと同じ Azure リージョンの Standard ストレージ アカウントです。 キャッシュ ストレージ アカウントは、変更が復旧 Azure リージョンに移動される前に、レプリケーションの変更を一時的に保持するために使用されます。 高チャーンのサポートは、より高いチャーン制限を得るために Azure Site Recovery でも利用できます。 この機能を使用するには、Premium ブロック BLOB タイプのストレージ アカウントを作成し、キャッシュ ストレージ アカウントとして使用します。 Azure Site Recovery for Premium SSD v2 ディスク (プレビュー) は、高いデータ更新頻度にのみ対応しています。 高チャーンを有効にするには、 SkuName Premium_LRS と Kind BlockBlobStorage を使用します。 仮想マシンのディスクごとに異なるキャッシュ ストレージ アカウントを指定する必要はありません。 異なるキャッシュ ストレージ アカウントを使用する場合は、それらが同じ種類 (Standard または Premium ブロック BLOB) であることを確認します。 詳細については、「Azure VM ディザスター リカバリー - 高チャーンのサポート」を参照してください。
#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
マネージド ディスクを使用していない仮想マシンの場合、ターゲット ストレージ アカウントは、仮想マシンのディスクがレプリケートされる復旧リージョンのストレージ アカウントです。 ターゲット ストレージ アカウントには、Standard ストレージ アカウントまたは Premium Storage アカウントのいずれかを指定できます。 ディスクのデータ変更率 (IO 書き込み速度) と、ストレージの種類に対して Azure Site Recovery でサポートされているチャーン制限に基づいて、必要なストレージ アカウントの種類を選択します。
#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
ネットワーク マッピングを作成する
ネットワーク マッピングは、プライマリ リージョンの仮想ネットワークを復旧リージョンの仮想ネットワークにマップします。 ネットワーク マッピングでは、プライマリ仮想ネットワーク内の仮想マシンがフェールオーバーする必要がある復旧リージョン内の Azure 仮想ネットワークを指定します。 1 つの Azure 仮想ネットワークは、復旧リージョン内の 1 つの Azure 仮想ネットワークにのみマップできます。
Azure 仮想ネットワークを復旧リージョンにフェールオーバー先として作成します。
#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
プライマリ仮想ネットワークを取得します。 仮想マシンが接続されている VNet:
#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("\","/")
プライマリ仮想ネットワークと復旧仮想ネットワークの間にネットワーク マッピングを作成します。
#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
逆方向 (フェールバック) のネットワーク マッピングを作成します。
#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 仮想マシンをレプリケートする
マネージド ディスクを使用して Azure 仮想マシンをレプリケートします。
#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
if ($RecoveryReplicaDiskAccountType -in @("PremiumV2_LRS", "Ultra_LRS")) {
$RecoveryReplicaDiskAccountType = "Premium_LRS"
}
$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 仮想マシンをレプリケートします。
#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
レプリケーションの開始操作が成功すると、仮想マシン のデータが復旧リージョンにレプリケートされます。
レプリケーション プロセスは、最初に、復旧リージョン内で仮想マシンのレプリケートする側のディスクのコピーをシード処理することによって始まります。 このフェーズは、初期レプリケーション フェーズと呼ばれます。
初期レプリケーションが完了すると、レプリケーションは差分同期フェーズに移動します。 この時点で、仮想マシンが保護され、それに対してテスト フェールオーバー操作を実行できます。 仮想マシンを表すレプリケートされた項目のレプリケーション状態は、初期レプリケーションの完了後 に保護された 状態になります。
仮想マシンに対応するレプリケーションで保護された項目の詳細を取得して、仮想マシンのレプリケーションの状態とレプリケーションの正常性を監視します。
Get-AzRecoveryServicesAsrReplicationProtectedItem -ProtectionContainer $PrimaryProtContainer | Select FriendlyName, ProtectionState, ReplicationHealth
FriendlyName ProtectionState ReplicationHealth
------------ --------------- -----------------
AzureDemoVM Protected Normal
テスト フェールオーバーを行い、検証して、テスト フェールオーバーをクリーンアップする
仮想マシンのレプリケーションが保護された状態に達すると、仮想マシン (仮想マシンのレプリケーションで保護された項目) でテスト フェールオーバー操作を実行できます。
#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
テスト フェールオーバーを実行します。
$ReplicationProtectedItem = Get-AzRecoveryServicesAsrReplicationProtectedItem -FriendlyName "AzureDemoVM" -ProtectionContainer $PrimaryProtContainer
$TFOJob = Start-AzRecoveryServicesAsrTestFailoverJob -ReplicationProtectedItem $ReplicationProtectedItem -AzureVMNetworkId $TFONetwork -Direction PrimaryToRecovery
テスト フェールオーバー操作が完了するまで待ちます。
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 : aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb
TargetObjectType : ProtectionEntity
TargetObjectName : azuredemovm
AllowedActions :
Tasks : {Prerequisites check for test failover, Create test virtual machine, Preparing the virtual machine, Start the virtual machine}
Errors : {}
テスト フェールオーバー ジョブが正常に完了したら、フェールオーバーされたテスト仮想マシンに接続し、テスト フェールオーバーを検証できます。
テスト フェールオーバーを行った仮想マシンでテストが完了したら、テスト フェールオーバー操作のクリーンアップを開始して、テスト コピーをクリーンアップします。 この操作により、テスト フェールオーバーによって作成された仮想マシンのテスト コピーが削除されます。
$Job_TFOCleanup = Start-AzRecoveryServicesAsrTestFailoverCleanupJob -ReplicationProtectedItem $ReplicationProtectedItem
Get-AzRecoveryServicesAsrJob -Job $Job_TFOCleanup | Select State
State
-----
Succeeded
Azure にフェールオーバーする
仮想マシンを特定の復旧ポイントにフェールオーバーします。
$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
フェールオーバー ジョブが成功したら、フェールオーバー操作をコミットできます。
$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 : aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb
TargetObjectType : ProtectionEntity
TargetObjectName : azuredemovm
AllowedActions :
Tasks : {Prerequisite check, Commit}
Errors : {}
再保護してソース リージョンにフェールバックする
フェールオーバー後、元のリージョンに戻る準備ができたら、Update-AzRecoveryServicesAsrProtectionDirection
コマンドレットを使用して、レプリケーションの保護された項目のレプリケーションの反転を開始します。
#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
再保護が完了したら、逆方向、米国西部から米国東部にフェールオーバーし、ソース リージョンにフェールバックできます。
レプリケーションを無効にする
Remove-AzRecoveryServicesAsrReplicationProtectedItem
コマンドレットを使用してレプリケーションを無効にすることができます。
Remove-AzRecoveryServicesAsrReplicationProtectedItem -ReplicationProtectedItem $ReplicationProtectedItem
次のステップ
Azure Site Recovery PowerShell リファレンスを参照して、復旧計画の作成や、PowerShell を使用した復旧計画のフェールオーバーのテストなどの他のタスクを実行する方法について説明します。