Tech Line

VM Backup Burden

Here's a script to assist in backing up virtual machines.

Chris: I can’t seem to get a clear answer from anyone on this and hoped that you could give a non-marketing answer: One of our customers wants to back up some VMware-based virtual servers via a Linux file system back-up agent on the ESX server (and not put agents onto the virtual machines). They accept that this is a whole-or-nothing backup with no granular restore to the Virtual Servers data. However, they want to be able to take this virtual server image backup while the virtual servers are running.

Is it possible to back up the ESX hosted VMs by running a Linux file system backup? Is it possible by using scripts to call a VMware snapshot and back up the snapshot while the virtual server continues to run?
— Brett

Tech Help—Just An
E-Mail Away

Got a Windows, Exchange or virtualization question or need troubleshooting help? Or maybe you want a better explanation than provided in the manuals? Describe your dilemma in an e-mail to the MCPmag.com editors at mailto:[email protected]; the best questions get answered in this column and garner the questioner with a nifty MCPmag.com baseball-style cap.

When you send your questions, please include your full first and last name, location, certifications (if any) with your message. (If you prefer to remain anonymous, specify this in your message, but submit the requested information for verification purposes.)

Brett, I must admit that I wish you were asking for a “marketing answer” instead of a “non-marketing answer.” This way, I could spew off lines like “Sure, in a future release!” or “Anything’s possible with our ubiquitous product!” I don’t know about you, but whenever I hear the word ubiquitous, I automatically switch to head-nodding mode and start thinking about something else. As long as I do a nod every 30 seconds or so and smile every other minute, I can be completely lost in thought about my last round of golf while appearing to be fully entranced in some marketing guy’s pitch.

Since you want a non-marketing answer, I can tell you that solutions exist for your problem. Of course, the best way to protect virtual machines is by installing a back-up agent in each VM, thus achieving granular file-level restore capability for each VM. However, I have run into a few organizations that simply wish to back up all VMs on a host server, such as an ESX server, using a single back-up job.

Currently, there is no VMware back-up API for backing up running virtual machines on an ESX server host. However, solutions have been developed using the VMware scripting API. In my opinion, the best back-up script available today is VMBK, which was written by Massimiliano Daneri. This script allows you to create snapshots of hot virtual disks and save the back-up virtual disks locally, or to SMB or NFS mounts. There is plenty of documentation and examples on the VMTS Web site, and this should offer the back-up flexibility you’re looking for. With the script, you can back up all VMs on an ESX host, or just a select group of VMs.

For those of you running Virtual Server 2005, there is no way to back up a hot VM without running a back-up agent inside the VM. However, one alternative that you may consider would be to suspend the VM, back up its related files, and then resume the VM following the completion of the backup. Here’s a VBscript that gets the job done:

Option Explicit
'Declare variables
Dim strVMName, strVMFolder, strToday
Dim strBackupFolder, strBackupFile
Dim strJobName, strDescription, strNTBackupCommand
Dim objVirtualServer, objVirtualMachine, objShell, errBackup

'Load current date (formatted as mm-dd-yyyy)
'into variable strToday
strToday = Month(Date) & "-" & Day(Date) & "-" & Year(Date)

'Define Script Variables
strVMName = "W2K3-DC1"
strVMFolder = """E:\VMs\W2K3-DC1"""
strBackupFolder = "F:\Backup\VMs"
strBackupFile = Chr(34) & strBackupFolder _
   & "\" & strVMName & "_" & strToday _
   & ".bkf" & Chr(34) 'Chr(34) is used to
                      'include a quote in the string
strJobName = Chr(34) & strToday & " Full Backup" & Chr(34)
strDescription = Chr(34) & "Starting " & strToday &Chr(34)
strNTBackupCommand = "ntbackup backup " & _
   strVMFolder & " /J " strJobName & " /D " & _
   strDescription & " /F " & strBackupFile

'Instantiate Virtual Server Object
Set objVirtualServer = _
   CreateObject("VirtualServer.Application")

'Instantiate Virtual Machine Object
Set objVirtualMachine = _
   objVirtualServer.FindVirtualMachine(strVMName)

'Save VM State
objVirtualMachine.Save()

'Instantiate command shell object
Set objShell = WScript.CreateObject("Wscript.shell")

'Use ntbackup.exe to back up saved VM
errBackup = objShell.Run(strNTBackupCommand,1,True)

'Restart VM
objVirtualMachine.Startup()

Note that the script backs up the VM’s files using NTbackup.exe; however, you could modify the script to work with your existing back-up product.

While I’ve covered a couple of VM backup methods here, I’m sure that some of you have your own personal tips and tricks when it comes to virtual machine backups. Since it’s Valentine’s Day, please show some love for your fellow readers by posting your favorite back-up trick as a comment to this article.

About the Author

Chris Wolf is a Microsoft MVP for Windows --Virtual Machine and is a MCSE, MCT, and CCNA. He's a Senior Analyst for Burton Group who specializes in the areas of virtualization solutions, high availability, storage and enterprise management. Chris is the author of Virtualization: From the Desktop to the Enterprise (Apress), Troubleshooting Microsoft Technologies (Addison Wesley), and a contributor to the Windows Server 2003 Deployment Kit (Microsoft Press).learningstore-20/">Troubleshooting Microsoft Technologies (Addison Wesley) and a contributor to the Windows Server 2003 Deployment Kit (Microsoft Press).

comments powered by Disqus
Most   Popular