It`s simple when you know how ! Hyper-v,Virtualization HYPER-V RESUME REPLICATION SCRIPT

HYPER-V RESUME REPLICATION SCRIPT

Some time the hyper-v replication get in to suspended mode or halt on any other reason, here is a Powershell script to run from the replica server which will start the replication again :

 

$ReplicationData = Get-VMReplication 

Foreach ($VMReplica in $ReplicationData) {
    Write-Host "Starting Replication on" $VMReplica.Name
    Do{
        If ($VMReplica.Health -eq "Suspended" -Or $VMReplica.Health -eq "Critical" -or $VMReplica.Health -eq "Warning") {
            Write-Host "VM Replication is in Critical Error State and suspended, Suspend and resuming Replication that is:" $VMReplica.State
            Suspend-VMReplication -ComputerName $VMReplica.ReplicaServer -VMName $VMReplica.Name
            Suspend-VMReplication -ComputerName $VMReplica.PrimaryServer -VMName $VMReplica.Name
            Resume-VMReplication -ComputerName $VMReplica.ReplicaServer -VMName $VMReplica.Name
            Resume-VMReplication -ComputerName $VMReplica.PrimaryServer -VMName $VMReplica.Name
            start-sleep -s 20
       }
       }
   Until($VMReplicaHealth.Health -notcontains "Normal")
}

2 thoughts on “HYPER-V RESUME REPLICATION SCRIPT”

  1. I kind of used this idea and expanded to include a domain with multiple clusters and nodes.

    $Domain = “HSS”
    $Clusters = Get-Cluster -Domain $Domain

    foreach ($Cluster in $Clusters) {
    $ClusterName = $Cluster.Name

    foreach ($Nodes in Get-ClusterNode -Cluster $ClusterName) {

    if ($Nodes.State -eq “Down”) {
    Write-Host “Node $Nodes is in a Down state.”
    Write-Host “`n”
    continue
    }

    Invoke-Command -ComputerName $Nodes -ScriptBlock {
    param ($VMName, $Nodes)

    $FailedReplicas = Get-VMReplication | Where-Object { $_.Health -eq “Critical” -or $_.Health -eq “Warning” -or $_.State -eq “Suspended” }
    $HealthyReplicas = Get-VMReplication | Where-Object { $_.Health -eq “Normal” }

    foreach ($VM in $HealthyReplicas) {
    $VMName = $VM.Name
    $ReplicationState = $VM.State
    $ReplicationHealth = $VM.Health

    if ($ReplicationHealth -eq “Normal”) {
    Write-Host “Nodes: $using:Nodes – VM: $VMName – Health: $ReplicationHealth – State: $ReplicationState”
    Write-Host “`n”
    }
    }
    foreach ($VM in $FailedReplicas) {
    $VMName = $VM.Name
    $ReplicationState = $VM.State
    $ReplicationHealth = $VM.Health

    if ($ReplicationState -notin @(“Resynchronizing”, “Replicating”)) {
    Write-Host “Resuming Suspended Replication for VM: $VMName”
    Write-Host “`n”
    if ($ReplicationState -eq “Suspended”) {
    Resume-VMReplication $VMName
    } else {
    Resume-VMReplication $VMName -Resynchronize
    }
    } else {
    Write-Host “Skipping replication for Nodes: $using:Nodes – VM: $VMName – Health: $ReplicationHealth – State: $ReplicationState”
    Write-Host “`n”
    }
    }
    } -ArgumentList $VMName, $Nodes
    }
    }

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post