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

Version 10
    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.