VMware Cloud Community
SandyB
Enthusiast
Enthusiast

Automating Disaster Recovery without SRM

Hi Guys

I am trying to do something clever for our disaster recovery site, we mirror our ESX Volumes using our SAN technology and i have managed to script presenting Views of the latest mirror PIT to the remote ESX cluster, i have been toying with Powershell to automate an HBA rescan for the whole cluster, but i was wondering if anyone knows of a way of automatically discovering and adding VMs from the presented datastores to vCenter? I am running ESX 3.5 update 4 and vCenter 2.5 update 5, still evaluating vSphere but if there is a better way with vSphere4 let me know it will help my case to go live sooner

thanks in advance.

S.

Reply
0 Kudos
4 Replies
AndreTheGiant
Immortal
Immortal

I suppose that in the DR site you have a single ESX...

In this case, after you have do the SAN stuff (to see the replicated VMFS datastores) you can do something similar (is just an example...):

for VMX in /vmfs/volumes/DataStoreName/*/*.vmx
do
vmware-cmd -s register $VMX
done
echo "Registered VMs:"
vmware-cmd -l

You can also use vmware-cmd to power-on the VMs.

Andre

Andrew | http://about.me/amauro | http://vinfrastructure.it/ | @Andrea_Mauro
Reply
0 Kudos
bulletprooffool
Champion
Champion

I am busy working on a PowerShell script that should process a failover for you, if you are replicating the VMDKs using 3rd party replication - I will post it on the community when I am done - so I can use all of your production environments as my test bed . .

I'll keep updating it until I get more positive feedback than negative feedback :smileydevil:

One day I will virtualise myself . . .
Reply
0 Kudos
SandyB
Enthusiast
Enthusiast

basically my DR setup has 4 SAN attached ESX servers in a cluster, i mirror 8 luns that contain about 100 VMs.

My SAN script takes a View on the latest PIT (point in time snapshot) and presents it to these 4 hosts.

I can use the PowerCLI to issue a rescan

get-vmhost | get-vmhoststorage -rescanallhba

this should make the datastores all pop in. (vmfs1,vmfs2,vmfs3 etc)

it i use the PowerCLI

$vmxpath = get-datastorefiles (get-datastore vmfs1) |

where { $_.Path -match '.vmx$' } | select path | % { Register-VM $_.Path

-vmhost (get-vmhost dresx.company.com) }

is there a way to register a VM to a cluster rather than a host?

Reply
0 Kudos
bulletprooffool
Champion
Champion

Compliments of LucD:

http://communities.vmware.com/message/1045282

$folder = Get-View (Get-Datacenter -Name <datacenter-name> | Get-Folder -Name "vm").ID
$pool = Get-View (Get-Cluster -Name <cluster-name> | Get-ResourcePool -Name "Resources").ID
$guestname = [regex]"^([\w]+).vmx"

$esxImpl = Get-VMHost -Name <VMHost-name> 
$esx = Get-View $esxImpl.ID 
$dsBrowser = Get-View $esx.DatastoreBrowser
foreach($dsImpl in $dsBrowser.Datastore){
  $ds = Get-View $dsImpl
  $vms = @()
  foreach($vmImpl in $ds.Vm){
    $vm = Get-View $vmImpl
    $vms += $vm.Config.Files.VmPathName
  }
  $datastorepath = ""
  
  $searchspec = New-Object VMware.Vim.HostDatastoreBrowserSearchSpec
  $searchSpec.matchpattern = "*.vmx"

  $taskMoRef = $dsBrowser.SearchDatastoreSubFolders_Task($datastorePath, $searchSpec) 
  $task = Get-View $taskMoRef 
  while ($task.Info.State -eq "running"){$task = Get-View $taskMoRef}

  foreach ($file in $task.info.Result){
    $found = $FALSE
    foreach($vmx in $vms){
      if(($file.FolderPath + $file.File[0].Path) -eq $vmx){
        $found = $TRUE
      }
    }
    if (-not $found){
      $vmx = $file.FolderPath + $file.File[0].Path
      $res = $file.File[0].Path -match $guestname
      $folder.RegisterVM_Task($vmx,$matches[1],$FALSE,$pool.MoRef,$null)	
    }
  }
}

One day I will virtualise myself . . .
Reply
0 Kudos