Ghetto Tech Preview - ghettoVCB-restore.sh - Restoring VM's backed up from ghettoVCB to ESX(i) 3.5, 4.x & 5.x

    Table of Contents:

      • Description
      • Requirements
      • Setup
      • Usage
      • Sample Execution
      • Change Log
      • Known Issues

     

    Description:

     

    This script performs a restore of virtual machines backed up using ghettoVCB .  Tasks are performed directly within the service console of the ESX(i)  server involved in the restore process. This is currently a Ghetto Tech  Preview that includes basic restore functionality. Two main use cases  are supported in this release:

     

     

    1) Restore a VM that contains ALL VMDKs on one datastore

     

    2) Restore a VM that has VMDKs located on multiple datastores

     

     

    In all cases, restored VMs will have VMDKs that reside on the SAME  datastore chosen for the restore process. Please ensure that there is  sufficient space on the target datastore before attempting a restore  operation. In the near future, restoration of VMs backed up using the  compression feature of ghettoVCB will be implemented.

     

     

    Features

     

    • Support for logging output
    • Support for various debugging output
    • Allow spaces in VM(s) backup list (not recommended and not a best practice)
    • Support for restore in the following formats: ZEROEDTHICK (default behavior), 2GB SPARSE, THIN or EAGERZEROEDTHICK
    • Support for ESXi 5.1 NEW!
    • Support changing custom VM name during restore NEW! 

    If you have found this script to be useful and would like to contribute back, please click here to donate.

     

    If you have any questions, you may post in the dedicated ghettoVCB VMTN community group.

     


     

    Requirements:

    VMs backed up using ghettoVCB.sh on ESX(i) 3.5, 4.x or 5.x

    SSH console access to ESX(i) host

     


     

    Setup:

    1) Download ghettoVCB from github (which includes ghettoVCB-restore) by clicking on the ZIP button at the top and upload to either your ESX or ESXi system (use scp or WinSCP to transfer the file)

     

    2) Extract the contents of the zip file (filename will vary):

    # unzip ghettoVCB-master.zip

    Archive:  ghettoVCB-master.zip
       creating: ghettoVCB-master/
      inflating: ghettoVCB-master/README
      inflating: ghettoVCB-master/ghettoVCB-restore.sh
      inflating: ghettoVCB-master/ghettoVCB-restore_vm_restore_configuration_template
      inflating: ghettoVCB-master/ghettoVCB-vm_backup_configuration_template
      inflating: ghettoVCB-master/ghettoVCB.conf
      inflating: ghettoVCB-master/ghettoVCB.sh

     

    3) The script is now ready to be used and is located in a directory named ghettoVCB-master

     

    # ls -l

    -rw-r--r--    1 root     root           281 Jan  6 03:58 README
    -rw-r--r--    1 root     root         16024 Jan  6 03:58 ghettoVCB-restore.sh
    -rw-r--r--    1 root     root           309 Jan  6 03:58 ghettoVCB-restore_vm_restore_configuration_template
    -rw-r--r--    1 root     root           356 Jan  6 03:58 ghettoVCB-vm_backup_configuration_template
    -rw-r--r--    1 root     root           631 Jan  6 03:58 ghettoVCB.conf
    -rw-r--r--    1 root     root         49375 Jan  6 03:58 ghettoVCB.sh

     


     

    Usage:

    [root@himalaya ~]# ./ghettoVCB-restore.sh
    ###############################################################################
    #
    # ghettoVCB-restore for ESX/ESXi 3.5, 4.x and 5.x
    # Author: William Lam
    # http://www.virtuallyghetto.com/
    # Created: 08/18/2009
    # Last modified: 2011_11_19_1
    #
    ###############################################################################

    Usage: ./ghettoVCB-restore.sh -c [VM_BACKUP_UP_LIST] -l [LOG_FILE] -d [DRYRUN_DEBUG_INFO]

    OPTIONS:
       -c     VM backup list
       -l     File ot output logging
       -d     Dryrun/Debug Info [1|2]

    (e.g.)

    Output will go to stdout
            ./ghettoVCB-restore.sh -c vms_to_restore

    Output will log to /tmp/ghettoVCB-restore.log
            ./ghettoVCB-restore.sh -c vms_to_restore -l /tmp/ghettoVCB-restore.log

    Dryrun/Debug Info (dryrun only)
            ./ghettoVCB-restore.sh -c vms_to_restore -d 1
            ./ghettoVCB-restore.sh -c vms_to_restore -d 2

     

     

    Standard input for script is a file that contains:

     

    1) Full path to the backed up VM

     

    2) Full restore path

     

    3) Restoration disk format

     

    4) Restored VM Display Name (NEW!)

     

    Reminder: When creating this file on a non-Linux/UNIX system, one may  introduce ^M characters that will cause the script to misbehave. To  ensure that this does not occur, please create the file on the ESX/ESXi  host.

     

     

    Here is a sample of what the file should look like:

     

     

    [root@himalaya ~]# cat vms_to_restore
    #"<DIRECTORY or .TGZ>;<DATASTORE_TO_RESTORE_TO>;<DISK_FORMAT_TO_RESTORE>;<OPTIONAL_RESTORED_VM_DISPLAY_NAME>"
    # DISK_FORMATS
    # 1 = zeroedthick
    # 2 = 2gbsparse
    # 3 = thin
    # 4 = eagerzeroedthick
    # e.g.
    # "/vmfs/volumes/dlgCore-NFS-bigboi.VM-Backups/WILLIAM_BACKUPS/VCAP/VCAP-2009-08-18--1;/vmfs/volumes/himalaya-local-SATA.RE4-GP:Storage;1"
    "/vmfs/volumes/mini-local-datastore-2/backups/VCSA-5.1/VCSA-5.1-2012-12-25_01-30-36;/vmfs/volumes/mini-local-datastore-1;3"
    "/vmfs/volumes/mini-local-datastore-2/backups/VCSA-5.1/VCSA-5.1-2012-12-25_01-30-36;/vmfs/volumes/mini-local-datastore-1;1;VCSA-RESTORE"

     

     

    Comments in the input file is acceptable so long as the intended line is preceded by a #. The above sample VM restore file,

    vms_to_restore, describes the following backup:

     

     

     

    VM to restoreDatastore to restore toVMDK formatRestore VM Name
    /vmfs/volumes/mini-local-datastore-2/backups/VCSA-5.1/VCSA-5.1-2012-12-25_01-30-36/vmfs/volumes/mini-local-datastore-1thinVCSA-5.1
    /vmfs/volumes/mini-local-datastore-2/backups/VCSA-5.1/VCSA-5.1-2012-12-25_01-30-36/vmfs/volumes/mini-local-datastore-zeroedthickVCSA-RESTORE


     

     


     

    Sample Execution:

     

    Perform a dryrun by displaying debug information ( restore will not take place)

     

    Display debug information level 1:

     

    # ./ghettoVCB-restore.sh -c vms_to_restore -d 1

    ################ DEBUG MODE ##############
    Virtual Machine: "VCSA-5.1"
    VM_ORIG_VMX: "VCSA-5.1.vmx"
    VM_ORG_FOLDER: "VCSA-5.1-2012-12-25_01-30-36"
    VM_RESTORE_VMX: "VCSA-5.1.vmx"
    VM_RESTORE_FOLDER: "VCSA-5.1"
    VMDK_LIST_TO_MODIFY:
    scsi0:0.fileName = "VCSA-5.1.vmdk"
    scsi0:0.fileName  = "VCSA-5.1-0.vmdk"
    scsi0:1.fileName = "VCSA-5.1_1.vmdk"
    scsi0:1.fileName  = "VCSA-5.1-1.vmdk"
    ##########################################


    ################ DEBUG MODE ##############
    Virtual Machine: "VCSA-RESTORE"
    VM_ORIG_VMX: "VCSA-5.1.vmx"
    VM_ORG_FOLDER: "VCSA-5.1-2012-12-25_01-30-36"
    VM_RESTORE_VMX: "VCSA-RESTORE.vmx"
    VM_RESTORE_FOLDER: "VCSA-RESTORE"
    VMDK_LIST_TO_MODIFY:
    scsi0:0.fileName = "VCSA-5.1.vmdk"
    scsi0:0.fileName  = "VCSA-RESTORE-0.vmdk"
    scsi0:1.fileName = "VCSA-5.1_1.vmdk"
    scsi0:1.fileName  = "VCSA-RESTORE-1.vmdk"
    ##########################################


    Start time: Sun Jan 13 16:45:12 UTC 2013
    End   time: Sun Jan 13 16:45:14 UTC 2013
    Duration  : 2 Seconds

    ---------------------------------------------------------------------------------------------------------------

     

     

    Display debug information level 2:

     

    [root@himalaya ~]# ./ghettoVCB-restore.sh -c vms_to_restore -d 2


    ################## Restoring VM: VCSA-5.1  #####################
    ==========> DEBUG MODE LEVEL 2 ENABLED <==========
    Start time: Sun Jan 13 16:45:35 UTC 2013
    Restoring VM from: "/vmfs/volumes/mini-local-datastore-2/backups/VCSA-5.1/VCSA-5.1-2012-12-25_01-30-36"
    Restoring VM to Datastore: "/vmfs/volumes/mini-local-datastore-1" using Disk Format: "thin"
    Creating VM directory: "/vmfs/volumes/mini-local-datastore-1/VCSA-5.1" ...
    Copying "VCSA-5.1.vmx" file ...
    Restoring VM's VMDK(s) ...
    Updating VMDK entry in "VCSA-5.1.vmx" file ...

    SOURCE: "/vmfs/volumes/mini-local-datastore-2/backups/VCSA-5.1/VCSA-5.1-2012-12-25_01-30-36/VCSA-5.1.vmdk"
        ORIGINAL_VMX_LINE: -->scsi0:0.fileName = "VCSA-5.1.vmdk"<--
    DESTINATION: "/vmfs/volumes/mini-local-datastore-1/VCSA-5.1/VCSA-5.1-0.vmdk"
        MODIFIED_VMX_LINE: -->scsi0:0.fileName  = "VCSA-5.1-0.vmdk"<--
    Updating VMDK entry in "VCSA-5.1.vmx" file ...

    SOURCE: "/vmfs/volumes/mini-local-datastore-2/backups/VCSA-5.1/VCSA-5.1-2012-12-25_01-30-36/VCSA-5.1_1.vmdk"
        ORIGINAL_VMX_LINE: -->scsi0:1.fileName = "VCSA-5.1_1.vmdk"<--
    DESTINATION: "/vmfs/volumes/mini-local-datastore-1/VCSA-5.1/VCSA-5.1-1.vmdk"
        MODIFIED_VMX_LINE: -->scsi0:1.fileName  = "VCSA-5.1-1.vmdk"<--
    Registering VCSA-5.1 ...
    End time: Sun Jan 13 16:45:35 UTC 2013
    ################## Completed restore for VCSA-5.1! #####################

    ################## Restoring VM: VCSA-RESTORE  #####################
    ==========> DEBUG MODE LEVEL 2 ENABLED <==========
    Start time: Sun Jan 13 16:45:35 UTC 2013
    Restoring VM from: "/vmfs/volumes/mini-local-datastore-2/backups/VCSA-5.1/VCSA-5.1-2012-12-25_01-30-36"
    Restoring VM to Datastore: "/vmfs/volumes/mini-local-datastore-1" using Disk Format: "zeroedthick"
    Creating VM directory: "/vmfs/volumes/mini-local-datastore-1/VCSA-RESTORE" ...
    Copying "VCSA-5.1.vmx" file ...
    Restoring VM's VMDK(s) ...
    Updating VMDK entry in "VCSA-RESTORE.vmx" file ...

    SOURCE: "/vmfs/volumes/mini-local-datastore-2/backups/VCSA-5.1/VCSA-5.1-2012-12-25_01-30-36/VCSA-5.1.vmdk"
        ORIGINAL_VMX_LINE: -->scsi0:0.fileName = "VCSA-5.1.vmdk"<--
    DESTINATION: "/vmfs/volumes/mini-local-datastore-1/VCSA-RESTORE/VCSA-RESTORE-0.vmdk"
        MODIFIED_VMX_LINE: -->scsi0:0.fileName  = "VCSA-RESTORE-0.vmdk"<--
    Updating VMDK entry in "VCSA-RESTORE.vmx" file ...

    SOURCE: "/vmfs/volumes/mini-local-datastore-2/backups/VCSA-5.1/VCSA-5.1-2012-12-25_01-30-36/VCSA-5.1_1.vmdk"
        ORIGINAL_VMX_LINE: -->scsi0:1.fileName = "VCSA-5.1_1.vmdk"<--
    DESTINATION: "/vmfs/volumes/mini-local-datastore-1/VCSA-RESTORE/VCSA-RESTORE-1.vmdk"
        MODIFIED_VMX_LINE: -->scsi0:1.fileName  = "VCSA-RESTORE-1.vmdk"<--
    Registering VCSA-RESTORE ...
    End time: Sun Jan 13 16:45:35 UTC 2013
    ################## Completed restore for VCSA-RESTORE! #####################


    Start time: Sun Jan 13 16:45:34 UTC 2013
    End   time: Sun Jan 13 16:45:35 UTC 2013
    Duration  : 1 Seconds

    ---------------------------------------------------------------------------------------------------------------

     

    Execute restore with output going to stdout (restore the first two VMs listed from above):

     

    Input file:

     

    # cat vms_to_restore

    "/vmfs/volumes/mini-local-datastore-2/backups/VCSA-5.1/VCSA-5.1-2012-12-25_01-30-36;/vmfs/volumes/mini-local-datastore-1;3"
    "/vmfs/volumes/mini-local-datastore-2/backups/VCSA-5.1/VCSA-5.1-2012-12-25_01-30-36;/vmfs/volumes/mini-local-datastore-1;1;VCSA-RESTORE"

     

     

    ./ghettoVCB-restore.sh -c vms_to_restore


    ################## Restoring VM: VCSA-5.1  #####################
    Start time: Sun Jan 13 16:46:41 UTC 2013
    Restoring VM from: "/vmfs/volumes/mini-local-datastore-2/backups/VCSA-5.1/VCSA-5.1-2012-12-25_01-30-36"
    Restoring VM to Datastore: "/vmfs/volumes/mini-local-datastore-1" using Disk Format: "thin"
    Creating VM directory: "/vmfs/volumes/mini-local-datastore-1/VCSA-5.1" ...
    Copying "VCSA-5.1.vmx" file ...
    Restoring VM's VMDK(s) ...
    Updating VMDK entry in "VCSA-5.1.vmx" file ...
    Destination disk format: VMFS thin-provisioned
    Cloning disk '/vmfs/volumes/mini-local-datastore-2/backups/VCSA-5.1/VCSA-5.1-2012-12-25_01-30-36/VCSA-5.1.vmdk'...
    Clone: 100% done.
    Updating VMDK entry in "VCSA-5.1.vmx" file ...
    Destination disk format: VMFS thin-provisioned
    Cloning disk '/vmfs/volumes/mini-local-datastore-2/backups/VCSA-5.1/VCSA-5.1-2012-12-25_01-30-36/VCSA-5.1_1.vmdk'...
    Clone: 100% done.
    Registering VCSA-5.1 ...
    34
    End time: Sun Jan 13 16:48:51 UTC 2013
    ################## Completed restore for VCSA-5.1! #####################

    ################## Restoring VM: VCSA-RESTORE  #####################
    Start time: Sun Jan 13 16:48:52 UTC 2013
    Restoring VM from: "/vmfs/volumes/mini-local-datastore-2/backups/VCSA-5.1/VCSA-5.1-2012-12-25_01-30-36"
    Restoring VM to Datastore: "/vmfs/volumes/mini-local-datastore-1" using Disk Format: "zeroedthick"
    Creating VM directory: "/vmfs/volumes/mini-local-datastore-1/VCSA-RESTORE" ...
    Copying "VCSA-5.1.vmx" file ...
    Restoring VM's VMDK(s) ...
    Updating VMDK entry in "VCSA-RESTORE.vmx" file ...
    Destination disk format: VMFS zeroedthick
    Cloning disk '/vmfs/volumes/mini-local-datastore-2/backups/VCSA-5.1/VCSA-5.1-2012-12-25_01-30-36/VCSA-5.1.vmdk'...
    Clone: 100% done.
    Updating VMDK entry in "VCSA-RESTORE.vmx" file ...
    Failed to clone disk: There is not enough space on the file system for the selected operation (13).
    Destination disk format: VMFS zeroedthick
    Cloning disk '/vmfs/volumes/mini-local-datastore-2/backups/VCSA-5.1/VCSA-5.1-2012-12-25_01-30-36/VCSA-5.1_1.vmdk'...
    Registering VCSA-RESTORE ...
    35
    End time: Sun Jan 13 16:50:19 UTC 2013
    ################## Completed restore for VCSA-RESTORE! #####################


    Start time: Sun Jan 13 16:46:40 UTC 2013
    End   time: Sun Jan 13 16:50:19 UTC 2013
    Duration  : 3.65 Minutes


    ---------------------------------------------------------------------------------------------------------------

     

     

    Execute restore with output going to log file

    /tmp/ghettoVCB-restore.log (restore the last two VMs listed from above):

     

    [root@himalaya ~]# ./ghettoVCB-restore.sh -c vms_to_restore -l /tmp/ghettoVCB-restore.log
    Logging output to "/tmp/ghettoVCB-restore.log" ...