Update: 01-11-2018 - This bug seems to be fixed! When creating a new replication policy, the time is correct.


At work we use Azure Site Recovery (ASR) for a while now. We use it primarily to synchronize the VM’s between datacenters and use ASR for the orchestration.

arch-onprem-onprem
Image source

Not that long ago I rebuild our test ASR environment after some updates and came across a weird issue.

After creating a new replication policy, nothing worked anymore. At first I figured it was due to the update of the agents on the System Center Virtual Machine Manager (SCVMM) servers.

In comes Powershell to the rescue :)

TL;DR

  • This issue is as of this date still unresolved by Microsoft.
  • When a new Replication Policy is created (through the portal), the Initial replication start time is created wrong.
  • As far as I know the only way to fix this, is to create the replication policy through Powershell.
  • The impact is that the Replication Policy breaks everything if the initial time to synchronize isn’t correct.
    • It won’t synchronize and it will give errors that don’t point towards the replication policy.
    • VM’s will not replicate, ASR will not work.

The Setup

I’ll go into the details and show you the screenshots on how to create a replication policy.

Note: You don’t need to have anything connected to the recovery vault. Create a new Azure subscription and a Recovery Vault and click along with the instructions below.

asr-recovery-services asr-vault

Find the Recovery Services Vault, and click on it.

asr-vault-manage asr-vault-manage-replication-policy

Go down to Manage and select Site Recovery Infrastructure scroll down to For System Center VMM and select the Replication Policies

asr-vault-manage-replication-policy-add asr-vault-manage-replication-policy-create-1

Create a new Replication Policy and select Hyper-V as a source and target.

asr-vault-manage-replication-policy-create-2.png

Choose for the Initial replication start time something else then Immediately or 07:45PM.
Keep the rest default values (or not, doesn’t really matter).

Result

Once the replication policy has been created, and you click back into the newly created policy, it shows 07:45 PM. Even though in this example we put in 10:00PM.
asr-vault-manage-replication-policy-init-time.png

Looking at it with Powershell we see the following:

# Get all the policies
Get-AzureRmRecoveryServicesAsrPolicy  | Select-Object Name -ExpandProperty ReplicationProviderSettings

asr-powershell-policy-initialtime

The time is set to something, except the time what we want.

I tested these replication policies and when in use the VM do not replicate from one Hyper-V Host to the other Hyper-V Host.

The Solution

The only way I found on how to fix this, is to create a Replication Policy through Powershell. At the bottom of the blog you can see the script I used.

The thing that took me a little bit was to find out how to use the ReplicationStartTime. When you check out the docs page it will tell you this:

-ReplicationStartTime

Specifies the replication start time. It must be no later than 24-hours from the start of the job.

Type: [System.TimeSpan]
Parameter Sets: HyperVToAzure, EnterpriseToEnterprise
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

Some searching around I found the New-TimeSpan with an Output of System.TimeSpan

This resulted in the following splat:

$NamePolicy = Read-Host -Prompt 'Give the name of the new policy'

$Time = New-TimeSpan -Hour 22 -Minute 00
$PolicySplat = @{
    VmmToVmm                        = $true
    ReplicationProvider             = 'HyperVReplica2012R2'
    Name                            = $NamePolicy
    ReplicationFrequencyInSeconds   = '900'
    NumberOfRecoveryPointsToRetain  = '1'
    ApplicationConsistentSnapshotFrequencyInHours = '1'
    Authentication                  = 'Certificate'
    ReplicationPort                 = '8083'
    Compression                     = 'Enable'
    ReplicaDeletion                 = 'Required'
    ReplicationMethod               = 'Online'
    ReplicationStartTime            = $Time
}

New-AzureRmRecoveryServicesAsrPolicy @PolicySplat

Looking at both of the created Replication Policies, you can see clearly the differences.

asr-powershell-policy-result

The Script

Note: Don’t forget to update the Azure.RM modules, this bit me in the beginning, my old scripts did not work anymore because of some changes.

Hopefully this helps someone or creates enough awareness that Microsoft will fix it.