VMware Cloud Community
alturner2
Contributor
Contributor

Which ESX Server is Hosting A Virtual Machine

Hi All

I would like to know if there is any command line that you can think of which I can use from my backup server to query our 3 ESX servers and find out which one is hosting a virtual machine.

I would like to find out which one is hosting the VM so I can send the approriate ESX server the snapshot and then vRanger backup command.

Before you ask why I don't simply do everything through the virtual center, we have a great deal of latency between our locations and the Virtual Center is in our head office... this causes our backups to error out all the time when trying to go through the Virtual Center so I would like to try moving them to the ESX level rather than the Virtual Center level.

So I would like to find out which ESX server is hosting the VMs and then send the backup command to which ever ESX server is in charge... most likely by DOS script using an IF statement.

Thanks for any help!!!

0 Kudos
8 Replies
lmonaco
Hot Shot
Hot Shot

vmware-cmd -l will give you a list of the VM's registered on a particular host.

If you looking for a VM call 123 and your config file (vmx) is has 123 in it, you can do something like vmware-cmd -l |grep 123

Cooldude09
Commander
Commander

You may need to use this command on 3 esx servers

find /vmfs/volumes -name *.vmx

If your VM lists there it means VM is on that particular host.

Regards

Anil

Save the planet, Go Green

if you found my answer to be useful, feel free to mark it as Helpful or Correct.

If U find my answer useful, feel free to give points by clicking Helpful or Correct.

Subscribe yourself at walkonblock.com

0 Kudos
puzzledtux
Hot Shot
Hot Shot

If you care to host another virtual machine (appliance) in your environment, then you can certainly try the VMware VIMA (Virtual Infrastructure Management Assistant). Using the VIMA appliance you can query via the command line to know on which host your virtual machine exist. Infact you can do much more things!

If you want a windows connection, then you can install OpenSSH on your Windows machine and then connect to the VIMA appliance.

Windows Client OpenSSH > VIMA Appliance > Virtual Center > ESX host

  1. /usr/lib/vmware-viperl/apps/vm/guestinfo.pl --server 10.20.223.251 --username administrator --password passwd --vmname "CentOS" --operation display | head -3

Guest Info for the Virtual Machine 'CentOS' under host 10.99.130.12

where, 10.20.223.251 is my VC server, 10.99.130.12 is my ESX host and virtual machine name is CentOS

Hope this helps!

0 Kudos
alturner2
Contributor
Contributor

Hi All

I want to thank you for all of the suggestions.

Imonaco - I'm going with your suggestion... I can create a TXT file using VMWARE-CMD -L and then search the TXT file for my VM Name and run the backup accordingly

Cooldude09 - Doing the search only returns the names of all my VMs because the SAN is attached to all ESX servers and if I search each one for *.VMX, they all find every VM... makes me wonder how the VMWARE-CMD -L command works!!!

Puzzledtux - Thanks for the suggestion but I think it's a little too complicated and I don't want to have to bring more appliances or software into the mix.

Thanks a lot everyone!

0 Kudos
alturner2
Contributor
Contributor

I will use plink.exe to connect to the ESX Servers and run VMWARE-CMD -L. I will pipe the results to a local text file on the VRanger backup server and search the text file for the VM name.

0 Kudos
puzzledtux
Hot Shot
Hot Shot

Hmm...does the vmx file always correspond to the correct virtual machine name? I mean what if I change the virtual machine name from the management interface?

0 Kudos
RParker
Immortal
Immortal

and if I search each one for *.VMX, they all find every VM... makes me wonder how the VMWARE-CMD -L command works!!!

The VMWARE-CMD works because you are running on the OS level of ESX. It knows which VM's are actually running on that host, it's not running the query of the files, only what VM's are currently residing in the vmkernel during run.

0 Kudos
lmonaco
Hot Shot
Hot Shot

Not always, you have to know the name of the .vmx file.

0 Kudos