VMware VCB Backup Script March 8, 2011
Posted by General Zod in Backup, Tech, VMware.trackback
Back in October 2009, my crew at work had implemented VMware Consolidated Backup [VCB] as our solution for backing up virtual machines. Since it was a command line driven solution, I’d accepted the challenge of scripting a solution to automate the backups. Now, the solution that was developed may not be the most efficient method out there, but we still leverage the solution today because the more recent VMware Data Recovery [vDR] appliance just is not as reliable as we would like it to be.
I’m going to tell you about the VCB solution that we currently have in-place, and you’re more than welcome to adapt the following for use in your own environment. However, please keep in mind the following two blurbs…
I do not write my solutions for the non-technical individuals. I’m going to assume that you have a working knowledge of the products discussed, or at least have the ability to do a little skull-sweat to figure out the necessary details. It would be impossible to design full-proof instructions that would accommodate everyone, so I do not attempt to do so. However, I am always willing to take a stab at answering any questions that someone might pose.
and
WARNING: If anything goes wrong with your implementation of the following example, then I will not accept responsibility for any data loss that you may incur. Use the following details at your own risk.
With that out of the way, let’s get started…
The Hardware
Before we get started, I’m going to assume that you already have a tape backup solution in-place, and that you can easily add another piece of hardware into that mix. You’re going to need a destination to dump the VCB backups to, so build a new server and add it into your tape backup solution.
My opted for a physical server to dedicate to my VCB backups because I’m running shy on SAN space, and I do not wish to waste the SAN space on backups. Unfortunately, this does mean that I’ll be performing my VCB dumps across the network… however, as I do them one-at-a-time, it won’t generate too much traffic.
For my environment, we have a HP ProLiant DL380 G6 with two disk arrays. The first array is a mirrored pair of 72 GB drives for the storage of the system partition. The second is a series of six 146 GB drives in a RAID 5 array, which is partitioned into a single volume to server as the destination for our VCB backups. It is on this server that VMware VCB is actually installed as well (not on the vCenter server).
The Scripts
There are technically 2 scripts used in this solution. The first that I will talk about is a VCB.VBS file that launches the VCB backups. The other script is a LAUNCH.CMD file which calls the VBS script each day. You’ll need to store both of these script files into the same folder on the server where you have VCB installed.
Before you begin editing the scripts to suit your environment, you’re going to need to gather the following information.
- The folder path to where the VCB executables were installed.
- The folder path to where your scripts are stored.
- The folder path to the target destination for the backup dumps.
- The Username and Password of a Service account that has access to both your vCenter server and the backup destination.
- The number of days you wish to store the VCB backups in the destination.
- If you desire to use email alerts to inform you of when your backups are completed, then you’ll also need a TO and FROM address to use… and the hostname to your local SMTP relay server.
You’ll be updating this information into the “Global Constants” section of the VBS script. For your convenience, I’ve highlighted these points in BOLD GREEN in the script below.
The VCB.VBS script
In summary, this script acquires the vCenter and VM hostnames from command line arguments, purges any old backups from your destination server, references the vCenter, backups up the VM, and sends an email report. (Additionally, if the “testing” Boolean variable is set to TRUE, then it will display various messages on the screen for testing / demo purposes.)
|
‘ VCB.VBS by Zod — 10/26/09 ‘ ************************************************** const testing = false ‘ Set to True for Alerts while Testing if testing then wscript.echo "Initializing Constants and Variables" const svcusername=”<service account username>" const purge_days = -2 ‘ Number of Days to Store VCB backups ‘ Local folder paths on vCenter Server ‘ Setup File management object ‘ Setup Command Run object ‘ Constants for Email Reporting ‘ Variables for Documenting Disk Usage ‘ ************************************************** Set args = WScript.Arguments if args.count < 1 then ‘ Confirm Hostname argument is present vcenter = args.Item(0) ‘ Get vCenter Hostname if testing then wscript.echo "VCENTER = " & vcenter ‘ ************************************************** Set f = fso.GetFolder(path_backup) ‘ ************************************************** If fso.FolderExists(path_backup & vm_hostname) Then ‘ ************************************************** Set MoRef_Code = NOTHING ‘ Blank out the MoRef_Code variable ‘Run the VCBVMNAME command to extract the MoRef code from the Output. if testing then wscript.echo "Run the VCBVMNAME command to extract the MoRef code" WshShell.CurrentDirectory = path_vcb While Not ExecCommand.StdOut.AtEndOfStream ‘ While – End of Output ‘ ************************************************** if testing then wscript.echo "Listing Variables:" call log_file("Backup of " & vm_hostname & " initiated.") WshShell.CurrentDirectory = path_vcb ‘Run VCBMOUNTER to backup the VM to the PATH_BACKUP path. ‘While Not ExecCommand.StdOut.AtEndOfStream ‘ While – End of Output ‘Wend ‘ End While – End of Output call log_file("Backup of " & vm_hostname & " completed.") ‘ ************************************************** disk_letter=left(path_backup,1) ‘ Get the Drive Letter in <path_backup> ‘ Get Total and Free Disk Space, and convert to GBs. email_subject="VCB: " & vm_hostname ‘ Populate the text that will make up the Body of the Email ‘ Write entry to Email Body for each subfolder in the <path_backup> folder. if testing then wscript.echo "Send the Email Report" if testing then wscript.echo "Exit Script" ‘ ************************************************** ‘ ************************************************** Sub Log_File(entry_text) ‘ Write entry into VCB log file ‘ ************************************************** Sub Exit_Script ‘ Write entry into VCB log file |
PHEW!!! Well, that’s the first script. Don’t worry though, the 2nd script isn’t quite that involved.
The LAUNCH.CMD Script
This is the script that you’ll be launching daily via your Scheduled Task Manager on your Windows server. All this script does is… check to see what day of the month it is, and then call the VCB.VBS script as needed depending upon which day it is.
Note that the calling of the VCB.VBS requires that you append the vCenter server hostname and the VM name to be backed up to the end of the line. This is to allow you to perform backups against multiple vCenter servers should you require to do so. (Most folks will only have 1 vCenter server. My environment has 4 separate vCenter servers… don’t ask.)
As this is going to be the biggest manual part of the solution, it will require some occasional updating on your part. I recommend that you review which VMs you desire to backup at least once a month, and update the LAUNCH.CMD script accordingly.
Please note that backups are only performed on days 1 thru 28 of each month. As days 29, 30, and 31 are NOT necessarily going to occur each month.
|
@echo off :: LAUNCH.CMD by Zod – 10/26/09 C: :: Get Day of the Month :: Case to Appropriate VCB Backup launches :: Usage: cscript C:\Script_Path\vcb.vbs <vcenter server> <vm name> :: **************************************** :: **************************************** cscript C:\Script_Path\vcb.vbs vcenter_hostname vm_name_#4 :: **************************************** cscript C:\Script_Path\vcb.vbs vcenter_hostname vm_name_#7 ETC, ETC, ETC, Until… :: **************************************** :: **************************************** :: **************************************** |
This is just what I was looking for. I have a bat script that does this but it’s not as robust. However…
I can’t get the vcbmounter part working correctly. It starts creating the log files, etc, but doesn’t start writing the vmdk 2gb chunck files. It just sits there.
I see that the output from vcbmounter is not displayed to the screen so I can’t check it. I tried adding >>[logfile] to the end but that didn’t work.
Also, I noticed you commented out the while/wend arround the vcbmounter statement, why?
I’m not that great at vbscript yet, I’m a UNIX guy, so any help you could provide would be appreciated. If I can get this to work it will be great!
Thanks!
I don’t know why the exec command stalled out but I was able to get this to work with the following:
dim cmdstr
cmdstr = “vcbmounter -h ” & vcenter & ” -u ” & svcusername & ” -p ” & svcpassword & ” -a ipaddr:” & vm_hostname & ” -r ” & path_backup & vm_hostname & “_vmdk -t fullvm”
return = WshShell.Run(cmdstr, 1, True)
if return >0 then
end if
This will open vcbmounter in a new shell where I can monitor the output. Or, if I want, I can use 0 instead of 1, to make it run in the background.
The “, True” makes the calling vbs script wait until vcbmounter has run, thus allowing me to trap errors in “return”.
Note also that I don’t need to get moref first if I use ipaddr.