If you feel this tip has saved you time or effort, please consider buying us a cuppa coffee to keep things going!
I have now started using VMware Server 2.x, and have found that the vmware-cmd program that VMware server 1.x uses doesn't exist any more! With a bit of digging around on the web I found the replacement program is vmrun. On my server (using the default installation options), it lives here: "C:\Program Files\VMWare\VMware Server\vmrun"
For a long time now I have been using VMware Server 1.x with clients. Backing up these machines using the vmware-cmd program in a simple batch script was quite easy. My usual process to backup vmware server is 3 step.
1. Suspend the virtual machine
2. Copy the directory containing all the virtual machine's files to the backup device
3. Start the virtual machine again.
I realise that this method involves a little down time for the virtual machine, but by using small hard disk split sizes when I created the virtual machine in the first place, the copy script will only copy .vmdk files that have been modified since last backup. I use a free program from Microsoft called robocopy to copy the files from the VMware server to the backup device. Robocopy is part of the Windows Server 2003 Resource Kit Tools - available here: http://www.microsoft.com/downloads/details.aspx?familyid=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en
The first step in constructing the script involves finding out what the path to the virtual machine is. VMware Server 2 uses named datastores for referencing where the actual files for a given virtual machine is. You can't just use the file path as you do with vmware-cmd. VMware Server 2 allows you to store a virtual machine on the local file system of the server, a CIFS store (Windows only), or an NFS-mounted file system (Linux only). To find out where your virtual machines are, use vmrun with the list command.
Using vmrun is a bit different from the old vmware-cmd program, the syntax to list virtual machines is:
"c:\Program Files\VMWare\VMware Server\vmrun" -T server -h https://<fully qualified name of server>:8333/sdk -u <username> -p <password> list
e.g
"c:\Program Files\VMWare\VMware Server\vmrun" -T server -h https://server1.local:8333/sdk -u administrator -p password list
The output of this command will look something like this:
Total running VMs: 1
[standard] VM1/vm1.vmx
Note: The virtual machine(s) must be running for this command to display their datastore path
Now that you have the datastore path, you can use vmrun to soft power off the virtual machine.
"c:\Program Files\VMWare\VMware Server\vmrun" -T server -h https://<fully qualified name of server>:8333/sdk -u <username> -p <password> suspend <datastore path>
For example:
"c:\Program Files\VMWare\VMware Server\vmrun" -T server -h https://server1.local:8333/sdk -u administrator -p password suspend "[standard] VM1\vm1.vmx"
The syntax to start a virtual machine is almost the same:
"c:\Program Files\VMWare\VMware Server\vmrun" -T server -h https://<fully qualified name of server>:8333/sdk -u <username> -p <password> start
Now that you can start and stop a virtual machine from the command line (or script), you can add some code to perform the backup. My completed backup script looks like this:
REM === Stop Virtual Machine ====
"c:\Program Files\VMWare\VMware Server\vmrun" -T server -h https://VMServer1.local:8333/sdk -u administrator -p password suspend "[standard] VM1/vm1.vmx"
REM ==== Copy Virtual Machine to Backup drive ===
net use r: \\BackupServer\BACKUP\VirtualMachines\VM1 /user:domain.local\administrator password
robocopy "C:\Virtual Machines\VM1" r: /mir /w:0 /r:0 > r:\VM1.log
net use r: /del
REM === Start Virtual Machine ====
"c:\Program Files\VMWare\VMware Server\vmrun" -T server -h https://VMServer1.local:8333/sdk -u administrator -p password start "[standard] VM1/vm1.vmx"
Note: This script stores the administrator username and password in a plain text file - make sure that it is stored on the server in a secure location!
|
Comments
Awesome!
In vmware server 1, you could find out the status of a vm using vmware-cmd getstate. I am searching for an equivalent command in vmware server 2, but no luck so far.
http://communities.vmware.com/thread/191565?tstart=0
RSS feed for comments to this post