이 문서에서는 Azure PowerShell을 사용하여 Azure 가상 머신에 대한 재해 복구를 설정하고 테스트하는 방법을 알아보세요.
당신은 다음을 배우게 됩니다:
- Recovery Services 자격 증명 모음을 만듭니다.
- PowerShell 세션에 대한 보관소 컨텍스트를 설정합니다.
- Azure 가상 머신 복제를 시작할 수 있도록 볼트를 준비하십시오.
- 네트워크 매핑을 만듭니다.
- 가상 머신을 복제할 스토리지 계정을 만듭니다.
- 재해 복구를 위해 Azure 가상 머신을 복구 지역에 복제합니다.
- 테스트 장애 조치(failover)를 수행하고, 테스트 장애 조치(failover)의 유효성을 검사하고 정리합니다.
- 복구 지역으로 전환합니다.
비고
포털을 통해 사용할 수 있는 모든 시나리오 기능을 Azure PowerShell을 통해 사용할 수 있는 것은 아닙니다. Azure PowerShell을 통해 현재 지원되지 않는 시나리오 기능 중 일부는 다음과 같습니다.
- 가상 머신의 각 디스크를 명시적으로 지정하지 않고도 가상 머신의 모든 디스크를 복제하도록 지정하는 기능입니다.
비고
Azure Az PowerShell 모듈을 사용하여 Azure와 상호 작용하는 것이 좋습니다. 시작하려면 Azure PowerShell 설치를 참조하세요. Az PowerShell 모듈로 마이그레이션하는 방법에 대한 자세한 내용은 Azure PowerShell을 AzureRM에서 Azure로 마이그레이션을 참조하세요.
필수 조건
시작하기 전에:
- 시나리오 아키텍처 및 구성 요소를 이해해야 합니다.
- 모든 구성 요소에 대한 지원 요구 사항을 검토합니다.
- Azure PowerShell
Az
모듈이 있어야 합니다. Azure PowerShell을 설치하거나 업그레이드해야 하는 경우 이 가이드에 따라 Azure PowerShell을 설치하고 구성합니다.
Microsoft Azure 구독에 로그인
Connect-AzAccount
cmdlet을 사용하여 Azure 구독에 로그인합니다.
Connect-AzAccount
Azure 구독을 선택합니다. cmdlet을 Get-AzSubscription
사용하여 액세스할 수 있는 Azure 구독 목록을 가져옵니다.
Set-AzContext
cmdlet을 사용하여 작업할 Azure 구독을 선택하세요.
Set-AzContext -SubscriptionId "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
복제할 가상 머신의 세부 정보 가져오기
이 문서에서는 미국 동부 지역의 가상 머신이 미국 서부 2 지역에 복제되고 복구됩니다. 복제되는 가상 머신에는 OS 디스크와 단일 데이터 디스크가 있습니다. 예제에 사용된 가상 머신의 이름은 .입니다 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 보관소를 만들 리소스 그룹을 생성합니다.
중요합니다
- Recovery Services 볼트와 보호되는 가상 머신은 서로 다른 Azure 위치에 있어야 합니다.
- Recovery 서비스 볼트의 리소스 그룹과 보호 중인 가상 머신은 서로 다른 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
복구 서비스 볼트를 만듭니다. 이 예제에서는 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 간 마이그레이션의 경우, 볼트 컨텍스트를 새로 생성된 볼트로 설정할 수 있습니다.
#Set the vault context for the PowerShell session.
Set-AzRecoveryServicesAsrVaultContext -Vault $vault
Azure 가상 머신 복제를 시작하도록 보관소 준비
주(원본) 지역을 나타내는 Site Recovery 패브릭 개체 만들기
보관소의 구성 요소 개체는 Azure 지역을 나타냅니다. 주 패브릭 개체는 볼트에 보호되는 가상 머신이 속한 Azure 지역을 나타내기 위해 생성됩니다. 이 문서의 예제에서 보호되는 가상 머신은 미국 동부 지역에 있습니다.
- 지역당 하나의 패브릭 개체만 만들 수 있습니다.
- 이전에 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 원본 지역에 대해 하나의 패브릭 개체를 만듭니다.
복구 지역을 나타내는 Site Recovery 패브릭 개체 만들기
복구 패브릭 개체는 복구 Azure 위치를 나타냅니다. 장애 조치(failover)가 있는 경우 가상 머신이 복제되어 복구 패브릭으로 표시되는 복구 지역으로 복구됩니다. 이 예제에서 사용되는 복구 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"
영역 간 복제를 사용하도록 설정할 때 패브릭 및 컨테이너 만들기
영역 복제를 사용하도록 설정하는 경우 하나의 패브릭만 만들어집니다. 그러나 두 개의 컨테이너가 있을 것입니다. 지역이 서유럽이라고 가정하고 다음 명령을 사용하여 기본 및 보호 컨테이너를 가져옵니다.
$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"
기본 및 복구 보호 컨테이너 간에 보호 컨테이너 매핑 만들기
보호 컨테이너 매핑은 기본 보호 컨테이너를 복구 보호 컨테이너 및 복제 정책에 매핑합니다. 보호 컨테이너 쌍 간에 가상 머신을 복제하는 데 사용할 각 복제 정책에 대해 하나의 매핑을 만듭니다.
#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"
장애 조치(failover) 후 역방향 복제를 위한 보호 컨테이너 매핑 만들기
장애 조치(failover) 후 장애 조치된 가상 머신을 원래 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 지역의 표준 스토리지 계정입니다. 캐시 스토리지 계정은 변경 내용이 복구 Azure 지역으로 이동하기 전에 복제 변경 내용을 일시적으로 저장하는 데 사용됩니다. 높은 변동 지원을 Azure Site Recovery에서도 사용하여 더 높은 변동 한도를 얻을 수 있습니다. 이 기능을 사용하려면 Premium Block Blob 유형의 스토리지 계정을 만든 다음 캐시 스토리지 계정으로 사용합니다. 프리미엄 SSD v2 디스크용 Azure Site Recovery(미리 보기)는 고변동을 사용하여서만 지원됩니다. SkuName Premium_LRS 및 Kind BlockBlobStorage를 사용하여 높은 변동을 가능하게 합니다. 가상 머신의 다른 디스크에 대해 다른 캐시 스토리지 계정을 지정하도록 선택할 수는 있지만 필요하지는 않습니다. 다른 캐시 스토리지 계정을 사용하는 경우 동일한 형식(표준 또는 프리미엄 블록 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
관리 디스크를 사용하지 않는 가상 머신의 경우 대상 스토리지 계정은 가상 머신의 디스크가 복제되는 복구 지역의 스토리지 계정입니다. 대상 스토리지 계정은 표준 스토리지 계정 또는 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 가상 네트워크를 지정합니다. 하나의 Azure 가상 네트워크를 복구 지역의 단일 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
복제 시작 작업이 성공하면 가상 머신 데이터가 복구 지역에 복제됩니다.
복제 프로세스는 처음에 복구 영역에 있는 가상 머신의 복제 디스크의 복사본을 시드하면서 시작됩니다. 이 단계를 초기 복제 단계라고 합니다.
초기 복제가 완료되면 복제가 차등 동기화 단계로 이동합니다. 이 시점에서 가상 머신은 보호되고 테스트 장애 조치(failover) 작업을 수행할 수 있습니다. 가상 머신을 나타내는 복제된 항목의 복제 상태는 초기 복제가 완료 된 후 보호됨 상태로 이동합니다.
가상 머신에 해당하는 복제 보호 항목의 세부 정보를 가져오면 가상 머신의 복제 상태 및 복제 상태를 모니터링합니다.
Get-AzRecoveryServicesAsrReplicationProtectedItem -ProtectionContainer $PrimaryProtContainer | Select FriendlyName, ProtectionState, ReplicationHealth
FriendlyName ProtectionState ReplicationHealth
------------ --------------- -----------------
AzureDemoVM Protected Normal
테스트 장애 조치(failover) 수행, 테스트 장애 조치(failover) 유효성 검사 및 정리
가상 머신에 대한 복제가 보호된 상태에 도달하면 가상 머신(가상 머신의 복제로 보호된 항목)에서 테스트 장애 조치(failover) 작업을 수행할 수 있습니다.
#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
테스트 장애 조치(failover)를 수행합니다.
$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 : {}
테스트 장애 조치(failover) 작업이 성공적으로 완료되면 테스트 장애 조치(failover)된 가상 머신에 연결하고 테스트 장애 조치(failover)의 유효성을 검사할 수 있습니다.
테스트 장애 조치(failover)된 가상 머신에서 테스트가 완료되면 테스트 장애 조치(failover) 정리 작업을 시작하여 테스트 복사본을 정리합니다. 이 작업은 테스트 장애 조치(failover)로 만들어진 가상 머신의 테스트 복사본을 삭제합니다.
$Job_TFOCleanup = Start-AzRecoveryServicesAsrTestFailoverCleanupJob -ReplicationProtectedItem $ReplicationProtectedItem
Get-AzRecoveryServicesAsrJob -Job $Job_TFOCleanup | Select State
State
-----
Succeeded
Azure로 장애 조치(failover)
가상 머신을 특정 복구 지점으로 장애 조치합니다.
$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
장애 조치(failover) 작업이 성공하면 이를 커밋할 수 있습니다.
$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
cmdlet을 사용하여 복제 보호된 항목에 대한 역방향 복제를 시작합니다.
#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
cmdlet을 사용하여 복제를 비활성화할 수 있습니다.
Remove-AzRecoveryServicesAsrReplicationProtectedItem -ReplicationProtectedItem $ReplicationProtectedItem
다음 단계
Azure Site Recovery PowerShell 참조를 확인하여 PowerShell을 사용하여 복구 계획 만들기 및 복구 계획의 장애 조치(failover) 테스트와 같은 다른 작업을 수행하는 방법을 알아봅니다.