VCB Backup Script, vcbMounter

VCB Backup Script, vcbMounter

Although the VMware Consolidated Backup (VCB) software receives considerable flack for lacking features or functionality, the fact that it provides you with access to the raw VMDK files is enough to alleviate all the missing functionality. As a side note, with Windows VMs, you can also use the vcbMounter program to mount the VM at a file level — which eliminates the need for backup client software on the VMs.

Full VMDK Backups

The first thing I’d like to point out is that the vcbMounter does not “mount” the datastore of the VM as one might imagine. When using the vcbMounter program to access the VMDK files, vcbMounter only copies the files to your VCB server. For smaller VMs, 30GB or so, this really isn’t much of an issue; however, for the larger VMs, say 300GB, this could pose a problem.

At first, you may be frustrated as the vcbMounter program is a quirky program. Unless you are lucky or brilliant, give yourself some time to play with the command options.

For my purposes, I use the following vcbMounter statement:

vcbmounter -h [VC or HOST] -u [USERNAME] -p [PASSWORD] -M 1 -a name:[VM NAME] -r [LOCATION]\%1_vmdk

vmdkbkp.bat

As expected, I am backing up many VMs; who would have an ESX(i) host with only one VM? (that is an entirely different subject I may address another day). Instead of scheduling the full vcbMounter command with each backup script or scheduled task, I created a batch file I use to extract the VMDK files. If you are interested in my script, download here.

@ECHO OFF
rem ----------------------------------------------------------------
rem Batch file to create a "mount" dump of a VM, as specified in %1.
rem Created, 11/23/2009, Aaron Gilbert, www.devtrends.com
rem
rem Usage: vmdkbkp.bat [server name]
remĀ  e.g.: vmdkbkp MYSERVERNAMEINESX
rem
rem ----------------------------------------------------------------

rem check to make sure the user supplied an argument
if "%1"=="" goto error

rem format date in yyyy-mm-dd to apply to a directory, use is %today%
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set today=%%c-%%a-%%b)

rem update the path statement so we can use vcbmounter
PATH=%PATH%;"C:\Program Files\VMware\VMware Consolidated Backup Framework\"

rem begin vcbmounter to copy the VMDK files down in file size (no 2GB split)
vcbmounter -h [VC or HOST] -u [USERNAME] -p [PASSWORD] -M 1 -a name:%1 -r [LOCATION]\%1_vmdk_%today%

rem lets finish up without error!
goto done

rem fail...
:error
echo.
echo Please provide one argument in the form of a VM server name, such as MYSERVERNAMEINESX
echo.

rem clean complete
:done

The batch file requires only one argument, the name of the VM server you wish to backup. I use the batch file in conjunction with a non-traditional vcbMounter “mounting” approach. I “mount” with the intent of keeping that “mount” for an extended period of time. In addition to the vmdkbkp.bat file, I use another batch file to clean out the backup directory of all “mounted” directories older than a specific date. This allows me to keep the VMDK files on my backup-to-disk server for multiple weeks, while rotating out the older files.

@ECHO OFF
rem -------------------------------------------------------------
rem Batch file to remove all directories that are older than %1.
rem Created, 11/24/2009, Aaron Gilbert, www.devtrends.com
rem
rem Usage: clndir.bat [negative days]
remĀ  e.g.: clndir -3
rem
rem -------------------------------------------------------------

rem check to make sure the user supplied an argument
if "%1"=="" goto error

rem clean up the directory from all directories older than 3 days
forfiles.exe /p c:\backup\ /m *.* /d %1 /c "cmd /c if @isdir==TRUE rmdir /s /q @path"

rem lets finish up without error!
goto done

rem fail...
:error
echo.
echo Please provide one argument in the form of a negative number, such as -3
echo.

rem clean complete
:done

Aaron Gilbert

About the Author

IT is not just a job but also a passion. Everything I have accomplished, both personally and professionally, has been generally entertaining, bordering on fun. Some of my projects, such as working with SharePoint Services workflow actions in Visual Studio or building a custom iSCSI SAN using the OpenSolaris, ZFS and COMSTAR, has been quite rewarding. You may think nerd...I think developing a new trend!