Currently Being Moderated

In this blog post i would like to give you an insight on how you can start to automate and create a complete Hyper-V Disaster Recovery solution using the Data ONTAP PowerShell toolkit and Windows Server 2012 Hyper-V 3.0 cmdlets.

 

The following powershell script showcased is designed to give you a heads up, also provide with creative ideas to build your own complex scripts, feel free to use the concept from the various scriptlets described below .

 

The variables used in the below script should be substituted with your own set of values, you can also build advanced functions based on the logic used in the script.  

 

The scripting method described below is applicable for VM's residing on cluster shared volumes.

 

Let’s take an example of highly available (HA) and consistent VMs that are running on a clustered Hyper-V hosts on Site A which has its csv's hosted on storage virtual machine svm1 and are serving mission critical applications.

 

When these VMs go down (complete site failure, both host and storage), in an instant the storage administrator can fail over all resources to a storage virtual machine svm2 hosted on Site B.

 

The storage administrator initiates Hyper-V DR through these Windows PowerShell® cmdlets.   These consistent VMs can then serve the mission-critical applications from a replicated or mirrored Site B almost instantaneously, with limited and reasonable downtime.

 

Prerequisites require that SnapMirror Relationship's have been established between volumes in Storage Virtual Machines hosted in SiteA and SiteB.

 

The below figure depicts our current setup and the failover process.

 

We have two sites, SiteA and SiteB, SiteA consists of a Hyper-V host cluster A with VM's hosted on it and connected to Netapp Storage vol1 on SVM1, similarly we have a failover SiteB which consists of Hyper-V host cluster B connected to vol2 on SVM2, we also have a snapmirror relationship established between volumes vol1 and vol2 in SVM1 and SVM2.

 

1.png

So to begin with the DR process, we need to start with the VM export (Only the Configuration Files) procedure.

 

We would start by exporting the VM configuration files for the VM's hosted on Hyper-V cluster A, for the current scenario we would export the VM's to a newly created folder called as "Exported VM's" within the CSV of Hyper-V cluster A which gets created as a part of scripting process.

 

Execute the below script on any of the node on the Primary Hyper-V cluster on SiteA to complete the export process.

 

#### Extracting the Highly Available VM's present in Hyper-V Cluster and storing their configuration files in CSV ####  

# Import the Failover Cluster module  as it contains the relevant cmdlets which are needed to export the VM configuration files.
Import-Module failoverclusters  

# Get a list of all cluster shared volumes and extract their respective friendly volume names.              
$frndvol = Get-ClusterSharedVolume | select -ExpandProperty sharedvolumeinfo | select -ExpandProperty friendlyvolumename  

# Initialize an array which would be used later to hold the configuration data.
$a = @()  


# Extract list of all Highly Available VM's and copy and paste their vm configuration files into "Exported VM's" folder.  
foreach ($frnd in $frndvol)  

{  

# Extract the VMname,VMid and VM configuration location from all Hyper-V cluster nodes.  
$vmdetails = Get-ClusterNode | % {Get-VM -ComputerName $_.name} | select vmname,vmid,ConfigurationLocation  

# Force create an ExportedVM's directory to store the VM configuration files            
New-Item -Path "$frnd\ExportedVMs" -ItemType directory -Force  

# For each VM copy the VM configuration files to the ExportedVM's directory            
foreach ($vm in $vmdetails)  

{  

$location = $vm.ConfigurationLocation  
$vmname = $vm.vmname  
$vmid = $vm.vmid  
Copy-Item -Path "$location\Virtual Machines\$vmid.xml" -Destination "$frnd\ExportedVMs"  
$a += Get-ChildItem "$frnd\ExportedVMs" | select name  

}  

}  

# Extracting exact unique location of vmconfigfiles  
$vmconfigfiles = $a | select * -Unique  

 #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### ####   

 

 

Once we are done with copying over the VM configuration files, invoke a snapmirror update from vol1 on SVM1 to the destination volume vol2 on SVM2, this would result in replication of the latest set of VM configuration files to vol2 in siteB.

 

# We would start by connecting to the c-mode controller on the secondary site  
Connect-NcController $cmodesecondarysite -Credential $cred2  

 # Next we would invoke a snapmirror update from the source vserver svm1 volume vol1 to the destination vserver svm2 vol2 so that we get the latest data
 Invoke-NcSnapmirrorUpdate -DestinationVserver $cmodesecondaryvserver -DestinationVolume $destinationvolume -SourceVserver $cmodeprimaryvserver -SourceVolume $sourcevolume  

 

So now we have all the VM configuration files exported, lets imagine a case that disaster strikes and SiteA goes down, in this case i will explain you the powershell based steps which need to be run to recover your VM's on SiteB.

 

Note :- The below steps can be executed from any node on Hyper-V cluster B

 

#### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### 


# We would start by connecting to the c-mode controller on the secondary site  
Connect-NcController $cmodesecondarysite -Credential $cred2  


# As we have the latest replicated information from our earlier snapmirror update cmdlet,we would invoke a snapmirror break so that we can start using vole for our SiteB   
Invoke-NcSnapmirrorBreak -DestinationVserver $cmodesecondaryvserver -DestinationVolume $destinationvolume -SourceVserver $cmodeprimaryvserver -SourceVolume $sourcevolume  


# Next we will get the igroup information for the hyper-v servers in secondary site 
Get-NcIgroup  


# Next we will get the luns which we would map and attach to the Hyper-V clusters which would be eventually converted to a cluster shared volume.  
$lunpath = Get-NcLun | ?{$_.path -match $destinationvolume} | select -ExpandProperty path  


# Next we will map this lun to the secondary site igroup.  
Add-NcLunMap -Path $lunpath -InitiatorGroup (Get-NcIgroup | select -ExpandProperty name | ?{$_.name -match $igroup}) -VserverContext $cmodesecondaryvserver  


# Next we need to run a host disk rescan on the host side and discover the disks  


Start-NcHostDiskRescan; Wait-NcHostDisk -SettlingTime 5000  


# As the disks are in offline state, lets gets all the disks which are offline and make them online  
Get-Disk | ? IsOffline | Set-Disk -IsOffline:$false  



# Next we would add these disks to available disks and convert them to cluster shared volume  
$clusterdiskname = Get-ClusterAvailableDisk | select -ExpandProperty name  
Get-ClusterAvailableDisk | Add-ClusterDisk   
Get-ClusterResource | ?{$_.name -match $clusterdiskname} | Add-ClusterSharedVolume  




# Once we have the disk's added as csv's we will import the VM's into Hyper-V  
$vmconfigfiles = Get-ChildItem "$frndvol\ExportedVMs" | select -ExpandProperty name  


foreach ($vm in $vmconfigfiles)  


{  


Import-VM -Path "$frndvol\ExportedVMs\$vm"  


}  


# Next we will make all the Virtual Machines highly available  
Get-VM | Add-ClusterVirtualMachineRole  

# Our final step will be to turn on all the highly available VM's  
Get-ClusterNode | % {Get-VM -ComputerName $_.name} | % { Start-VM -Name $_.name -ComputerName $_.ComputerName}  


#### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### 

 

 

1.png

 

I hope that you have enjoyed reading this blogpost on how to perform a site to site disaster recovery using DataONTAP PowerShell Toolkit and Hyper-V 3.0 PowerShell cmdlets and have found this information helpful.

 

Good Luck!

 

If you are looking for an enterprise level solution check out Snap Manager for Hyper-V which provides application consistent backup and DR solutions.

 

Thanks,

Vinith

Comments

Filter Blog

By author:
By date:
By tag: