Scheduling VMWare in Linux
I have built a couple of Linux based VMWare servers that are used at work for development. There are often issues with backing up VMWare virtual machines, especially when you need to shut down a VM in order to back it up.
In Linux, I have come up with a way to automate this process. For our example, let’s assume that we have a VM located at /var/VMs/Ubuntu.vmx. Let’s also assume that our backup starts at 2:00 AM and finished by 3:00 AM each morning. What I am doing is scheduling two cron jobs, one at 1:00 AM to shut down the virtual machine and one again at 4:00 AM to restart the virtual machine.
Here is what my crontab file looks like:
0 1 * * * vmware-cmd '/var/VMs/Ubuntu.vmx' stop>/dev/null 2>&1
0 4 * * * vmware-cmd ‘/var/VMs/Ubuntu.vmx’ start>/dev/null 2>&1
If you are wondering about the /dev/null 2>&1 part of the command, this disables the e-mail output that is automatically sent by crontab.
The vmware-cmd utility has a number of other uses. For your reference, here is the complete usage and options:
Usage: vmware-cmd <options> <vm-cfg-path> <vm-action> <arguments>
vmware-cmd -s <options> <server-action> <arguments>Options:
Connection Options:
-H <host> specifies an alternative host (if set, -U and -P must also be set)
-O <port> specifies an alternative port
-U <username> specifies a user
-P <password> specifies a password
General Options:
-h More detailed help.
-q Quiet. Minimal output
-v Verbose.Server Operations:
vmware-cmd -l
vmware-cmd -s register <config_file_path>
vmware-cmd -s unregister <config_file_path>
vmware-cmd -s getresource <variable>
vmware-cmd -s setresource <variable> <value>VM Operations:
vmware-cmd <cfg> getconnectedusers
vmware-cmd <cfg> getstate
vmware-cmd <cfg> start <powerop_mode>
vmware-cmd <cfg> stop <powerop_mode>
vmware-cmd <cfg> reset <powerop_mode>
vmware-cmd <cfg> suspend <powerop_mode>
vmware-cmd <cfg> setconfig <variable> <value>
vmware-cmd <cfg> getconfig <variable>
vmware-cmd <cfg> setguestinfo <variable> <value>
vmware-cmd <cfg> getguestinfo <variable>
vmware-cmd <cfg> getid
vmware-cmd <cfg> getpid
vmware-cmd <cfg> getproductinfo <prodinfo>
vmware-cmd <cfg> connectdevice <device_name>
vmware-cmd <cfg> disconnectdevice <device_name>
vmware-cmd <cfg> getconfigfile
vmware-cmd <cfg> getheartbeat
vmware-cmd <cfg> getuptime
vmware-cmd <cfg> getremoteconnections
vmware-cmd <cfg> gettoolslastactive
vmware-cmd <cfg> getresource <variable>
vmware-cmd <cfg> setresource <variable> <value>
vmware-cmd <cfg> setrunasuser <username> <password>
vmware-cmd <cfg> getrunasuser
vmware-cmd <cfg> getcapabilities
vmware-cmd <cfg> addredo <disk_device_name>
vmware-cmd <cfg> commit <disk_device_name> <level> <freeze> <wait>
vmware-cmd <cfg> answer
If you found this post useful, why don't you buy me a cup of coffee to show your gratitude?
One Response to “Scheduling VMWare in Linux”
-
chris Says:
August 22nd, 2008 at 10:53 pmHere’s a site I ran across a while back that has a pretty nice backup script for VMware server:

