Script: Create Disaster Recovery Hard Drive, with Backup-VM VCB Wrapper CMDLet

Script: Create Disaster Recovery Hard Drive, with Backup-VM VCB Wrapper CMDLet

Update 27-Aug-08: Script updated for VI Toolkit 1.0 and Powershell v2 CTP2

Create Disaster Recovery Hard Drive

Motivation

This script was created out of a motivation of laziness. Since VM's proliferate so fast, most backup and disaster recovery solutions are a pain in the ass because you have to manually add and remove virtual machines to their backup processes. What if there was a way to automatically add and remove VM's to a backup solution simply because of where they are located in Virtualcenter? What if I had an automated DR solution to removable USB hard drives for my smaller clients that was FREE?

Hence this script. This script dynamically backs up all VM's in a particular Virtualcenter folder using VCB, and drops them out to a USB hard drive for disaster recovery purposes. If I don't want a VM backed up anymore, I simply take it out of that folder.

Note that this also leverages the new networked method of VCB, so YOU DO NOT NEED A SAN AND DIRECT ACCESS TO THE LUNs.

The script is also flexible enough so that if you do have the SAN VCB configuration, you can do LAN-free backups with this method too.

Note that the query here is just an example. Any way you can return a list of VM's, you can give it to the backup-vm cmdlet.

Some examples that come to mind:

  1. Backup all virtual machines with disks under 500MB in size

  2. Backup all virtual machines created after July 1st

  3. Backup all virtual machines with "Prod" in their names

  4. Backup all virtual machines with a custom attribute defined called "BackMeUp" set to true

  5. Backup all virtual machines currently residing on a particular host, cluster, or datacenter.

This script took me about 8 hours, mostly because I was learning how to do script cmdlets and dealing with all the incompatabilities/breakage of CTP Powershell releases as well.

Script Cmdlets

The task evolved into my first foray into the new Script Cmdlets in Powershell v2. They're so easy to make I went wild and wrote a near-complete wrapper to VCB. Cut and paste the "cmdlet" section out of the code and put it in your profile, and you can now use the Backup-VM cmdlet.

Usage

  1. Install onto a server or workstation with the prerequisites defined in the script (VCB, Powershell v2 CTP2, VI Toolkit v1.0)

  2. Edit the parameters of the script to suit your environment. BE VERY CAREFUL WITH VMBackupDestination

  3. Run to test, then set up as a scheduled task on a daily interval.

Example Screenshot:

VCB Backup Script in Action

Script

Due to issues with VMWare Communities, the script is now attached to this document.

Attachments
Comments

This is a great script. I have been trying to add some notifications to this but with no success yet. Mainly a email or log entry for each machine backed up and if it was successful or not. Has anyone added anything like this to the script?

Nice script, any suggestion on a restoration script?

@brekus: I have it logging to the event viewer in the newest version written for PowerCLI, I'll get around to posting it one of these days.

@swjunke: It's the full virtual machine, so typically for restoration we just use VMWare Converter to import the virtual machine. It could be scripted for restore but Converter would be easier so I'd just say do that.

Great script...... it´s anyway to use it without VC and copying the VM in a folder inside ESX server?

Thanks

Version history
Revision #:
1 of 1
Last update:
‎07-14-2008 07:47 AM
Updated by: