blog

Automate VMware Converter 5 For Backups Or Disaster Recovery

Perhaps a daft move, but VMware Converter (sometimes called P2V or vCenter Converter) no longer allows you to script the creation of a machine image by way of the command line. This used to be possible in earlier versions of Converter but was unceremoniously removed from version 5.0 and up. This has many confused, who used the tool as something of a “poor man’s disaster recovery tool”. In this article, I’m going to go over a means of automating Converter so you can again use it for a backup.

The key thing to understand is that VMware is doing a number of things to try and stop you from automating this process. One of the bigger ways is not allowing you to overwrite an existing VM (that you might have created previously). This will either fill your disk space fast creating new copies, or it will stop the process. For our purposes, we’ll have to take the lesser of two evils and modify the VM name on the fly. This will automate the process, but force you to manage space in the location you store the output.

Even worse, the lack of a command-line option forces the use of an SDK that may (or may not) provide the required utility. Discussions about this online appear to follow the “Can I automate?” question with a familiar and unuseful “Use the SDK” answer. Examples of use appear to only be the source code variety, and not exactly what’s needed. It would be great if someone made a simple precompiled way to submit a job, until that time, here’s what I’ve come up with.

The first thing you’ll need to do is get VMware Converter and install it on the computer that will be imaged. Then, line up a storage location away from that computer. This could be a NAS or even a USB disk. Before you’re ready to automate, create a job in Converter and run it until completion once. You’ll be setting up the defaults and testing to ensure Converter works.

Enter the great free tool Autoit. This scripting environment allows me to load and control the interface of VMware Converter as if I was sitting in front of the computer. Autoit works by simply creating a script file that will either launch (with the program installed) or be pre-compiled into an executable from source to run on computers. You’ll also find the executable is also better suited for scheduling in Windows. You may do either of these things, as long as the script runs.

The script I put together is based on VMware Converter 5.5.1 specifically, and would probably break on other versions. This took some time to figure out the process, timing, and interface elements, but it wasn’t super difficult. Most importantly, this is not the final word. Take it and enhance it if you’d like and consider returning here to share what you’ve learned.

Here’s the script:

#include <Constants.au3>

;
; AutoIt Version: 3.0
; Language: English
; Platform: Win9x/NT
; Author: Kevin Costain
;
; Script Function:
; Opens VMware Converter 5.5.1, and submits a job
;

; Run VMware Converter with a basic 64bit check
If FileExists(“c:Program Files (x86)VMwareVMware vCenter Converter Standaloneconverter.exe”) Then
Run(“c:Program Files (x86)VMwareVMware vCenter Converter Standaloneconverter.exe”)
Else
Run(“c:Program FilesVMwareVMware vCenter Converter Standaloneconverter.exe”)
EndIf

; Wait for VMware Converter to become active, this should activate the window if already running
Sleep(3000)
;WinWait(“VMware vCenter Converter Standalone”, “”, 40)
WinActivate(“VMware vCenter Converter Standalone”, “”)
WinWaitActive(“VMware vCenter Converter Standalone”)

; Now start job creation process
Send(“^m”)
Sleep(1500)
Send(“!n”) ;Will retrieve source info (might take a while)
Sleep(5000)
Send(“{TAB}”)
Send(“{TAB}”)
Send(“{TAB}”)
Send(“{TAB}”)
Send(“{TAB}”)
Send(“{TAB}”)
Send(“{TAB}”)
Send(“{TAB}”)
Send(“{TAB}”)
Send(“{END}”) ;Get us to the “Name” field and the final character of it
Send(Random(1, 50000, 1)) ;Add random number to end of name
Send(“!n”) ;Get to options screen
Sleep(800)
Send(“!n”) ;Get to summary screen
Sleep(800)
Send(“!f”) ;Submits the job to run

; Finished!

To use the above, download and install Autoit on a Windows computer. Copy the above text and paste it into a file with an .au3 extension and double-click to run it. Right-clicking will give you other menu options. One of those options is a compilation. Take this executable (or compile the script yourself) and place it in a scheduled task. Have it run at the interval you deem most useful; I settled on once a week, but your mileage may vary based on the space available and the role our protected machine plays.

As you might imagine, there is a boatload of limitations with a hack like this. Chief among them is a failure based on even a minute Converter application change. When I can test and modify this for other versions, I will swing back and update the script for you. Contribution to the base script in this article is welcome if you see fit to take on newer (or older) available Converter iterations. With your help, we may be able to cover all versions of Converter.

Some other thoughts and ideas:

1. This requires the Windows shell and application interactivity. So, don’t expect it to work if your server is running Core or if the screen locks automatically. On Windows Server 2012 (and newer) machines, that may mean a regedit or the use of the powercfg utility. The screen on your machine has to stay unlocked.
2. Since this doesn’t manage disk space, and the process will always create new copies, you’re going to need to manually keep your drive space in check. Ideally, you’ll do this process at intervals that let you manage existing space in easier time intervals for you. Writing some means of removing older copies into this script would be useful.
3. You’ll need to have run a job once before automating this process. Converter tends to save the options you’ve chosen after your first run, so use this tool after that and most settings will carry forward. Also, this program assumes you’ve installed Converter in the default location.
4. The random string generator creates a number from 1 to 50,000. This is likely not sufficient enough to keep from some form of duplication. This process might be enhanced by using a date-time algorithm in some manner for better results.
5. The process leaves VMware Converter running when completed. This could be further tidied up by closing the app.

It’s not perfect, but it may give you some ideas or just a basic and useful way of automating this tool for your own use. I’m not looking to discuss the merits of VMware Converter as a disaster recovery option here (that might be a great topic for another post), but if you do use it, you should be able to automate that use. Give it a shot, and let me know.

VMware Converter is a free tool provided to convert an operating system running on a physical computer to an operating system that will run in a virtual machine. The download is currently available at VMware’s site. Autoit is a scripting tool for Windows that can be freely downloaded. If you find it useful, consider making a much-deserved donation to the authors.