SHIFT

--- Sjoerd Hooft's InFormation Technology ---

User Tools

Site Tools


Sidebar

Recently Changed Pages:

View All Pages


View All Tags


LinkedIn




WIKI Disclaimer: As with most other things on the Internet, the content on this wiki is not supported. It was contributed by me and is published “as is”. It has worked for me, and might work for you.
Also note that any view or statement expressed anywhere on this site are strictly mine and not the opinions or views of my employer.


Pages with comments

View All Comments

srmrdms

SRM Script: SRM And RDMs

While Site Recovery Manager 5.l fully supports the usage of RDMs and this also works just fine there are a few things that will work against you that need to be solved in case you ever have to do a failover recovery. And even while doing a failover test, considering these issues will help you to make your tests faster and more reliable.

The two issues in case:

These issues will mean that after recovering VMs with RDMs you'll have to set the path policy to MRU (preferred because it supports ALUA for ESXi 5.1 and NetApp Storage) and the IsPerenniallyReserved setting to true for each RDM.

Luckily I wrote a script.

The Script

This script can be run directly from the recovery plan as described here.

Note that this is a rewrite of the original script Configure RDMs On ESXi Hosts.

# Script Details
# Author: Sjoerd Hooft
# Creation Date: 2013-03-22
 
# Variables
# Setting scriptname
if (!$args[0]){
   Write-Host "First parameter (scriptname) is not provided"
   $scriptname = $myinvocation.mycommand.name}
else{
   $scriptname = $args[0]}
Write-Host "Scriptname = $scriptname"
# Setting scriptlocation
if (!$args[1]){
   Write-Host "Second parameter (scriptlocation) is not provided"
   $scriptlocation = Split-Path $myinvocation.mycommand.path}
else{
   $scriptlocation = $args[1]}
Write-Host "Scriptlocation = $scriptlocation"
# Setting vCenter
if (!$args[2]){
   Write-Host "Third parameter (vCenter) is not provided"
   $vcenter = "vcenter.getshifting.com"}
else{
   $vcenter = $args[2]}
Write-Host "vCenter = $vcenter"
# Setting Recovery Mode
if (!$args[3]){
   Write-Host "Fourth parameter (recoverymode) is not provided"
   $recoverymode = "unknown"}
else{
   $recoverymode = $args[3]}
Write-Host "Recovery Mode = $recoverymode"
# Setting Recovery Plan
if (!$args[4]){
   Write-Host "Fifth parameter (recoveryplan) is not provided"
   $recoveryplan = "unknown"}
else{
   $recoveryplan = $args[4]}
Write-Host "Recovery Plan = $recoveryplan"
 
$MailServer = "10.10.10.25"
$toemail = "ids@getshifting.com"
$fromemail = "vcenter@getshifting.com"
$timestamp = Get-Date -format "yyyyMMdd-HH.mm"
$csvfile = "$scriptlocation\$scriptname-$timestamp.csv"
$cluster = "HQ SRM"
 
# Add VMware snapin
if(-not (Get-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue)){
   Add-PSSnapin VMware.VimAutomation.Core}
 
# Email functions
Function Send-Email ($subject, $info){
   Send-MailMessage -To $toemail -From $fromemail -SmtpServer $mailserver -Subject $subject -Body $info -Attachments "$csvfile"}
 
# Connect to vCenter
Connect-VIServer $vcenter
 
# Define csv table
$myTable = @()
 
# Search for RDM files and define required information 
foreach ($vm in (Get-Cluster $cluster | Get-VM | Get-HardDisk -DiskType "RawPhysical","RawVirtual")){
 
   $RDMInfo = "" |select-Object VMName,DiskType,ScsiCanonicalName
 
   $RDMInfo.VMName = $vm.Parent
   $RDMInfo.DiskType = $vm.DiskType
   $RDMInfo.ScsiCanonicalName = $vm.ScsiCanonicalName
 
$myTable += $RDMInfo
}
 
$myTable |Export-csv -NoTypeInformation $csvfile
 
# Finished creating csv file. Now filtering out RDMs that are not part of MSCS by removing RDMs that do not have duplicates.
 
$duprdms = Import-Csv $csvfile | Group-Object ScsiCanonicalName -noElement | where {$_.count -gt 1}
 
# Now setting MPP and the Perennially Reserved option on RDMs where this has not been done yet. 
# This is an extra check because this script is run multiple times during a disaster recovery test.
 
ForEach ($esxihost in (Get-Cluster $cluster | Get-VMHost)){
   $myesxcli = get-esxcli -VMHost $esxihost
   ForEach ($rdm in $duprdms){
      $rdmdisk = $rdm.Name
      $scsilun = Get-ScsiLun -CanonicalName $rdmdisk -VMHost $esxihost
	 Write-Host "Evaluating $rdmdisk on $esxihost"
         $mpp = $scsilun.multipathpolicy
         Write-Host "MPP is $mpp"
         if ("$mpp" -ne "MostRecentlyUsed"){
         # Set Perennially Reserved flag to true
         $myesxcli.storage.core.device.setconfig($false, "$rdmdisk", $true)
         # Set multipathpolicy to MRU
         $scsilun | Set-ScsiLun -multipathpolicy "MostRecentlyUsed"
      }
   }
}
 
# Disconnect from vCenter
Disconnect-VIServer * -Confirm:$false
 
# Send last 10 errors to logfile
$allerrors = $error[0..9]
 
# Preparing info for email
$subject = "Result: $scriptname : Recoveryplan: $recoveryplan in $recoverymode mode"
$info = "These are the last 10 errors: $allerrors"
Send-Email $subject $info
 
# Remove logfile after it has been sent by email
Remove-Item $csvfile
You could leave a comment if you were logged in.
srmrdms.txt · Last modified: 2021/09/24 00:25 (external edit)