VMware

ghettoVCB.sh - Free alternative for backing up VM's for ESX(i) 3.5 and 4.0+

VERSION 46 Published

Created on: Nov 17, 2008 7:04 PM by lamw - Last Modified:  Nov 17, 2009 12:03 AM by lamw

Table of Contents:

    • Description
    • Features
    • Requirements
    • Setup
    • Configurations
    • Usage
    • Sample Execution
      • Backup VMs stored in a list
      • Backup VMs using individual backup policies
      • Debug backup Mode
      • Dry run Mode
    • Enable compression for backups
    • Restore backups (ghettoVCB-restore.sh)
    • Cronjob FAQ
    • FAQ
    • Useful Links
    • Change Log

Description:


This script performs backups of virtual machines residing on ESX(i) 3.5/4.0+ servers using methodology similar to VMware's VCB tool. The script takes snapshots of live virtual machines, backs up the master VMDK(s) and then upon completion, deletes the snapshot until the next backup. The only caveat is that it utilizes resources available to the Service Console of the ESX server running the backups as opposed to following the traditional method of offloading virtual machine backups through a VCB proxy.

This script has been tested on ESX 3.5/4.0 and ESXi 3.5/4.0 and supports the following backup mediums: LOCAL STORAGE, SAN and NFS. The script is non-interactive and can be setup to run via crontab. Currently, this script accepts a text file that lists the display names of virtual machine(s) that are to be backed up. Additionally, one can specify a folder containing configuration files on a per VM basis for granular control over backup policies.

Additionally, for ESX environments that don't have persistent NFS datastores designated for backups, the script offers the ability to automatically connect the ESX server to a NFS exported folder and then upon backup completion, disconnect it from the ESX server. The connection is established by creating an NFS datastore link which enables monolithic (or thick) VMDK backups as opposed to using the usual *nix mount command which necessitates breaking VMDK files into the 2gbsparse format for backup. Enabling this mode is self-explanatory and will evidently be so when editing the script (Note: VM_BACKUP_VOLUME variable is ignored if ENABLE_NON_PERSISTENT_NFS=1 ).

In its current configuration, the script will allow up to 3 unique backups of the Virtual Machine before it will overwrite the previous backups; this however, can be modified to fit procedures if need be. Please be diligent in running the script in a test or staging environment before using it on production live Virtual Machines; this script functions well within our environment but there is a chance that it may not fit well into other environments.

Features

  • Support for multiple VMDK disk(s) backup per VM
  • Only valid VMDK(s) presented to the VM will be backed up
  • Online back up of VM(s)
  • Ability to shutdown guestOS and initiate backup process and power on VM afterwards with the option of hardpower timeout
  • Allow spaces in VM(s) backup list (not recommended and not a best practice)
  • Ensure that snapshot removal process completes prior to to continuing onto the next VM backup
  • VM(s) that intially contain snapshots will not be backed up and will be ignored
  • Ability to specify the number of backup rotations for VM
  • Output back up VMDK(s) in either ZEROEDTHICK (default behavior) or 2GB SPARSE or THIN or EAGERZEROEDTHICK format
  • Support for both SCSI and IDE disks
  • Non-persistent NFS backup
  • Fully support VMDK(s) stored across multiple datastores
  • Ability to compress backups (Experimental Support)
  • Ability to configure individual VM backup policies NEW!
  • Ability to include/exclude specific VMDK(s) per VM (requires individual VM backup policy setup) NEW!
  • Ability to configure logging output to file NEW!
  • Independent disk awareness (will ignore VMDK) NEW!
  • New timeout variables for shutdown and snapshot creations NEW!
  • Ability to configure snapshots with both memory and/or quiesce options NEW!
  • Ability to configure disk adapter format NEW!
  • Additional debugging information including dry run execution NEW!
  • Support for VMs with both virtual/physical RDM (pRDM will be ignored and not backed up) NEW!



Requirements:

  • VMs running on ESX(i) 3.5/4.0+
  • SSH console access to ESX/ESXi host



Setup:


1) Download ghettoVCB.sh to either your ESX or ESXi system

2) Change the permissions on the script to ensure it can be executed:

[root@himalaya ~]# chmod +x ghettoVCB.sh




Configurations:


The following variables need to be defined within the script or in VM backup policy prior to execution.

Defining the backup datastore and folder in which the backups are stored (if folder does not exist, it will automatically be created):
VM_BACKUP_VOLUME=/vmfs/volumes/dlgCore-NFS-bigboi.VM-Backups/WILLIAM_BACKUPS


Defining the backup disk format (zeroedthick, eagerzeroedthick, thin, and 2gbsparse are available):
DISK_BACKUP_FORMAT=thin


Defining the backup rotation per VM:
VM_BACKUP_ROTATION_COUNT=3


Defining whether the VM is powered down or not prior to backup (1 = enable, 0 = disable):

Note: VM(s) that are powered off will not require snapshoting
POWER_VM_DOWN_BEFORE_BACKUP=0


Defining whether the VM can be hard powered off when "POWER_VM_DOWN_BEFORE_BACKUP" is enabled and VM does not have VMware Tools installed
ENABLE_HARD_POWER_OFF=0


If "ENABLE_HARD_POWER_OFF" is enabled, then this defines the number of (60sec) iterations the script will before executing a hard power off when:
ITER_TO_WAIT_SHUTDOWN=3


The number (60sec) iterations the script will wait when powering off the VM and will give up and ignore the particular VM for backup:
POWER_DOWN_TIMEOUT=5


The number (60sec) iterations the script will wait when taking a snapshot of a VM and will give up and ignore the particular VM for backup:

Default value should suffice
SNAPSHOT_TIMEOUT=15


Defining whether or not to enable compression (1 = enable, 0 = disable):
ENABLE_COMPRESSION=0


Defining the adapter type for backed up VMDK (buslogic and lsilogic are available):
ADAPTER_FORMAT=buslogic


Defining whether virtual machine memory is snapped and if quiescing is enabled (1 = enable, 0 = disable):

Note: By default both are disabled
VM_SNAPSHOT_MEMORY=0
VM_SNAPSHOT_QUIESCE=0


*Defining VMDK(s) to backup from a particular VM either a list of vmdks or "all"
VMDK_FILES_TO_BACKUP="myvmdk.vmdk"


Ensure that you do not edit past this section:
########################## DO NOT MODIFY PAST THIS LINE ##########################




Usage:


[root@himalaya ~]# ./ghettoVCB.sh
###############################################################################
#
# ghettoVCB for ESX/ESXi 3.5 & 4.x+
# Author: William Lam
# http://www.engineering.ucsb.edu/~duonglt/vmware/
# Created: 11/17/2008
# Last modified: 11/14/2009
#
###############################################################################

Usage: ./ghettoVCB.sh -f [VM_BACKUP_UP_LIST] -c [VM_CONFIG_DIR] -l [LOG_FILE]

OPTIONS:
   -f     List of VMs to backup
   -c     Configuration directory for VM backups
   -l     File to output logging
   -d     Debug level [info|debug|dryrun] (default: info)

(e.g.)

Backup VMs stored in a list
        ./ghettoVCB.sh -f vms_to_backup

Backup VMs based on specific configuration located in directory
        ./ghettoVCB.sh -f vms_to_backup -c vm_backup_configs

Output will log to /tmp/ghettoVCB.log
        ./ghettoVCB.sh -f vms_to_backup -l /tmp/ghettoVCB.log

Dry run (no backup will take place)
        ./ghettoVCB.sh -f vms_to_backup -d dryrun



The input to this script is a file that contains the display name of the virtual machine(s) separated by a newline. When creating this file on a non-Linux/UNIX system, you may introduce ^M character which can cause the script to miss-behave. To ensure this does not occur, plesae create the file on the ESX/ESXi host.

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

[root@himalaya ~]# cat vms_to_backup
VCAP
VIMA
vMA-2




Sample Execution:

  • Backup VMs stored in a list
  • Backup VMs based on individual VM backup policies
  • Debug Mode
  • Dry run Mode

Backup VMs stored in a list

  • Log verbosity: info (default)
  • Log output: stdout (default)

[root@himalaya ~]# ./ghettoVCB.sh -f vms_to_backup

2009-11-12 06:14:10 -- info: ============================== ghettoVCB LOG START ==============================

2009-11-12 06:14:10 -- info: CONFIG - VM_BACKUP_VOLUME = /vmfs/volumes/dlgCore-NFS-bigboi.VM-Backups/WILLIAM_BACKUPS
2009-11-12 06:14:10 -- info: CONFIG - VM_BACKUP_ROTATION_COUNT = 3
2009-11-12 06:14:10 -- info: CONFIG - DISK_BACKUP_FORMAT = thin
2009-11-12 06:14:10 -- info: CONFIG - ADAPTER_FORMAT = buslogic
2009-11-12 06:14:10 -- info: CONFIG - POWER_VM_DOWN_BEFORE_BACKUP = 0
2009-11-12 06:14:10 -- info: CONFIG - ENABLE_HARD_POWER_OFF = 0
2009-11-12 06:14:10 -- info: CONFIG - ITER_TO_WAIT_SHUTDOWN = 3
2009-11-12 06:14:10 -- info: CONFIG - POWER_DOWN_TIMEOUT = 5
2009-11-12 06:14:10 -- info: CONFIG - SNAPSHOT_TIMEOUT = 15
2009-11-12 06:14:10 -- info: CONFIG - LOG_LEVEL = info
2009-11-12 06:14:10 -- info: CONFIG - BACKUP_LOG_OUTPUT = stdout
2009-11-12 06:14:10 -- info: CONFIG - VM_SNAPSHOT_MEMORY = 0
2009-11-12 06:14:10 -- info: CONFIG - VM_SNAPSHOT_QUIESCE = 0
2009-11-12 06:14:10 -- info: CONFIG - VMDK_FILES_TO_BACKUP = all

2009-11-12 06:14:15 -- info: Initiate backup for VCAP
Destination disk format: VMFS thin-provisioned
Cloning disk '/vmfs/volumes/himalaya-local-SATA.RE4-GP:Storage/VCAP/VCAP_2.vmdk'...
Clone: 100% done.
Destination disk format: VMFS thin-provisioned
Cloning disk '/vmfs/volumes/himalaya-local-SATA.RE4-GP:Storage/VCAP/VCAP_1.vmdk'...
Clone: 100% done.
Destination disk format: VMFS thin-provisioned
Cloning disk '/vmfs/volumes/himalaya-local-SATA.RE4-GP:Storage/VCAP/VCAP.vmdk'...
Clone: 100% done.
Destination disk format: VMFS thin-provisioned
Cloning disk '/vmfs/volumes/himalaya-local-SATA.RE4-GP:Storage/VCAP/VCAP-0.vmdk'...
Clone: 100% done.
2009-11-12 06:15:15 -- info: Backup Duration: 60 Seconds
2009-11-12 06:15:15 -- info: Successfully completed backup for VCAP!

2009-11-12 06:15:17 -- info: Initiate backup for VIMA
2009-11-12 06:15:17 -- info: Creating Snapshot "ghettoVCB-snapshot-2009-11-12" for VIMA
Destination disk format: VMFS thin-provisioned
Cloning disk '/vmfs/volumes/himalaya-local-SAS.Savvio/VIMA/VIMA.vmdk'...
Clone: 100% done.
2009-11-12 06:16:40 -- info: Removing snapshot from VIMA ...
2009-11-12 06:16:43 -- info: Backup Duration: 1.43 Minutes
2009-11-12 06:16:43 -- info: Successfully completed backup for VIMA!

2009-11-12 06:16:47 -- info: Initiate backup for vMA-2
Destination disk format: VMFS thin-provisioned
Cloning disk '/vmfs/volumes/himalaya-local-SAS.Constellation/vMA-2/vMA-2.vmdk'...
Clone: 100% done.
2009-11-12 06:18:14 -- info: Backup Duration: 1.45 Minutes
2009-11-12 06:18:14 -- info: Successfully completed backup for vMA-2!

2009-11-12 06:18:14 -- info: ============================== ghettoVCB LOG END ================================



Backup VMs based on individual VM backup policies and log output to /tmp/ghettoVCB.log

  • Log verbosity: info (default)
  • Log output: /tmp/ghettoVCB.log (default)

1. Create folder to hold individual VM backup policies (can be named anything):
[root@himalaya ~]# mkdir backup_config


2. Create individual VM backup policies for each VM that ensure each file is named exactly as the display name of the VM being backed up (use provided template to create duplicates):
[root@himalaya backup_config]# cp ghettoVCB-vm_backup_configuration_template VCAP
[root@himalaya backup_config]# cp ghettoVCB-vm_backup_configuration_template VIMA


Listing of VM backup policy within backup configuration directory
[root@himalaya backup_config]# ls
ghettoVCB-vm_backup_configuration_template  VCAP  VIMA


Backup policy for "VCAP" (backup only 2 specific VMDKs)
[root@himalaya backup_config]# cat VCAP
VM_BACKUP_VOLUME=/vmfs/volumes/dlgCore-NFS-bigboi.VM-Backups/WILLIAM_BACKUPS
DISK_BACKUP_FORMAT=thin
VM_BACKUP_ROTATION_COUNT=3
POWER_VM_DOWN_BEFORE_BACKUP=0
ENABLE_HARD_POWER_OFF=0
ITER_TO_WAIT_SHUTDOWN=4
POWER_DOWN_TIMEOUT=5
SNAPSHOT_TIMEOUT=15
ENABLE_COMPRESSION=0
ADAPTER_FORMAT=buslogic
VM_SNAPSHOT_MEMORY=0
VM_SNAPSHOT_QUIESCE=0
VMDK_FILES_TO_BACKUP="VCAP.vmdk,VCAP_2.vmdk"


Backup policy for VM "VIMA" (backup all VMDKs found)
[root@himalaya backup_config]# cat VIMA
VM_BACKUP_VOLUME=/vmfs/volumes/dlgCore-NFS-bigboi.VM-Backups/WILLIAM_BACKUPS
DISK_BACKUP_FORMAT=thin
VM_BACKUP_ROTATION_COUNT=3
POWER_VM_DOWN_BEFORE_BACKUP=0
ENABLE_HARD_POWER_OFF=0
ITER_TO_WAIT_SHUTDOWN=4
POWER_DOWN_TIMEOUT=5
SNAPSHOT_TIMEOUT=15
ENABLE_COMPRESSION=0
ADAPTER_FORMAT=buslogic
VM_SNAPSHOT_MEMORY=1
VM_SNAPSHOT_QUIESCE=0
VMDK_FILES_TO_BACKUP="all"



Note: When specifying -c option (individual VM backup policy mode) if a VM is listed in the backup list but DOES NOT have a corresponding backup policy, the VM will be backed up using the default configuration found within the ghettoVCB.sh script.

Execution of backup
[root@himalaya ~]# ./ghettoVCB.sh -f vms_to_backup -c backup_config -l /tmp/ghettoVCB.log

Logging output to "/tmp/ghettoVCB.log" ...
Destination disk format: VMFS thin-provisioned
Cloning disk '/vmfs/volumes/himalaya-local-SATA.RE4-GP:Storage/VCAP/VCAP_2.vmdk'...
Clone: 100% done.
Destination disk format: VMFS thin-provisioned
Cloning disk '/vmfs/volumes/himalaya-local-SATA.RE4-GP:Storage/VCAP/VCAP.vmdk'...
Clone: 100% done.
Destination disk format: VMFS thin-provisioned
Cloning disk '/vmfs/volumes/himalaya-local-SAS.Savvio/VIMA/VIMA.vmdk'...
Clone: 100% done.
Destination disk format: VMFS thin-provisioned
Cloning disk '/vmfs/volumes/himalaya-local-SAS.Constellation/vMA-2/vMA-2.vmdk'...
Clone: 100% done.



Note: When specifying the -l option (log output to file), vmkfstools copy is also logged to stdout. This is done primarily for debugging purposes.

Log output from backup
[root@himalaya ~]# cat /tmp/ghettoVCB.log

2009-11-12 06:26:53 -- info: ============================== ghettoVCB LOG START ==============================

2009-11-12 06:26:56 -- info: CONFIG - USING CONFIGURATION FILE = backup_config/VCAP
2009-11-12 06:26:56 -- info: CONFIG - VM_BACKUP_VOLUME = /vmfs/volumes/dlgCore-NFS-bigboi.VM-Backups/WILLIAM_BACKUPS
2009-11-12 06:26:56 -- info: CONFIG - VM_BACKUP_ROTATION_COUNT = 3
2009-11-12 06:26:56 -- info: CONFIG - DISK_BACKUP_FORMAT = thin
2009-11-12 06:26:56 -- info: CONFIG - ADAPTER_FORMAT = buslogic
2009-11-12 06:26:56 -- info: CONFIG - POWER_VM_DOWN_BEFORE_BACKUP = 0
2009-11-12 06:26:56 -- info: CONFIG - ENABLE_HARD_POWER_OFF = 0
2009-11-12 06:26:56 -- info: CONFIG - ITER_TO_WAIT_SHUTDOWN = 4
2009-11-12 06:26:56 -- info: CONFIG - POWER_DOWN_TIMEOUT = 5
2009-11-12 06:26:56 -- info: CONFIG - SNAPSHOT_TIMEOUT = 15
2009-11-12 06:26:56 -- info: CONFIG - LOG_LEVEL = info
2009-11-12 06:26:56 -- info: CONFIG - BACKUP_LOG_OUTPUT = /tmp/ghettoVCB.log
2009-11-12 06:26:56 -- info: CONFIG - VM_SNAPSHOT_MEMORY = 0
2009-11-12 06:26:56 -- info: CONFIG - VM_SNAPSHOT_QUIESCE = 0
2009-11-12 06:26:56 -- info: CONFIG - VMDK_FILES_TO_BACKUP = VCAP.vmdk,VCAP_2.vmdk

2009-11-12 06:26:58 -- info: Initiate backup for VCAP
Destination disk format: VMFS thin-provisioned
Cloning disk '/vmfs/volumes/himalaya-local-SATA.RE4-GP:Storage/VCAP/VCAP_2.vmdk'...
Clone: 100% done.
Destination disk format: VMFS thin-provisioned
Cloning disk '/vmfs/volumes/himalaya-local-SATA.RE4-GP:Storage/VCAP/VCAP.vmdk'...
Clone: 100% done.
2009-11-12 06:26:59 -- info: Backup Duration: 1 Seconds
2009-11-12 06:26:59 -- info: Successfully completed backup for VCAP!

2009-11-12 06:26:59 -- info: CONFIG - USING CONFIGURATION FILE = backup_config/VIMA
2009-11-12 06:26:59 -- info: CONFIG - VM_BACKUP_VOLUME = /vmfs/volumes/dlgCore-NFS-bigboi.VM-Backups/WILLIAM_BACKUPS
2009-11-12 06:26:59 -- info: CONFIG - VM_BACKUP_ROTATION_COUNT = 3
2009-11-12 06:26:59 -- info: CONFIG - DISK_BACKUP_FORMAT = thin
2009-11-12 06:26:59 -- info: CONFIG - ADAPTER_FORMAT = buslogic
2009-11-12 06:26:59 -- info: CONFIG - POWER_VM_DOWN_BEFORE_BACKUP = 0
2009-11-12 06:26:59 -- info: CONFIG - ENABLE_HARD_POWER_OFF = 0
2009-11-12 06:26:59 -- info: CONFIG - ITER_TO_WAIT_SHUTDOWN = 4
2009-11-12 06:26:59 -- info: CONFIG - POWER_DOWN_TIMEOUT = 5
2009-11-12 06:26:59 -- info: CONFIG - SNAPSHOT_TIMEOUT = 15
2009-11-12 06:26:59 -- info: CONFIG - LOG_LEVEL = info
2009-11-12 06:26:59 -- info: CONFIG - BACKUP_LOG_OUTPUT = /tmp/ghettoVCB.log
2009-11-12 06:26:59 -- info: CONFIG - VM_SNAPSHOT_MEMORY = 1
2009-11-12 06:26:59 -- info: CONFIG - VM_SNAPSHOT_QUIESCE = 0
2009-11-12 06:26:59 -- info: CONFIG - VMDK_FILES_TO_BACKUP = all

2009-11-12 06:27:02 -- info: Initiate backup for VIMA
2009-11-12 06:27:02 -- info: Creating Snapshot "ghettoVCB-snapshot-2009-11-12" for VIMA
Destination disk format: VMFS thin-provisioned
Cloning disk '/vmfs/volumes/himalaya-local-SAS.Savvio/VIMA/VIMA.vmdk'...
Clone: 100% done.
2009-11-12 06:29:28 -- info: Removing snapshot from VIMA ...
2009-11-12 06:29:31 -- info: Backup Duration: 2.48 Minutes
2009-11-12 06:29:31 -- info: Successfully completed backup for VIMA!

2009-11-12 06:29:31 -- info: CONFIG - VM_BACKUP_VOLUME = /vmfs/volumes/dlgCore-NFS-bigboi.VM-Backups/WILLIAM_BACKUPS
2009-11-12 06:29:31 -- info: CONFIG - VM_BACKUP_ROTATION_COUNT = 3
2009-11-12 06:29:31 -- info: CONFIG - DISK_BACKUP_FORMAT = thin
2009-11-12 06:29:31 -- info: CONFIG - ADAPTER_FORMAT = buslogic
2009-11-12 06:29:31 -- info: CONFIG - POWER_VM_DOWN_BEFORE_BACKUP = 0
2009-11-12 06:29:31 -- info: CONFIG - ENABLE_HARD_POWER_OFF = 0
2009-11-12 06:29:31 -- info: CONFIG - ITER_TO_WAIT_SHUTDOWN = 3
2009-11-12 06:29:31 -- info: CONFIG - POWER_DOWN_TIMEOUT = 5
2009-11-12 06:29:31 -- info: CONFIG - SNAPSHOT_TIMEOUT = 15
2009-11-12 06:29:31 -- info: CONFIG - LOG_LEVEL = info
2009-11-12 06:29:31 -- info: CONFIG - BACKUP_LOG_OUTPUT = /tmp/ghettoVCB.log
2009-11-12 06:29:31 -- info: CONFIG - VM_SNAPSHOT_MEMORY = 0
2009-11-12 06:29:31 -- info: CONFIG - VM_SNAPSHOT_QUIESCE = 0
2009-11-12 06:29:31 -- info: CONFIG - VMDK_FILES_TO_BACKUP = all

2009-11-12 06:29:35 -- info: Initiate backup for vMA-2
Destination disk format: VMFS thin-provisioned
Cloning disk '/vmfs/volumes/himalaya-local-SAS.Constellation/vMA-2/vMA-2.vmdk'...
Clone: 100% done.
2009-11-12 06:31:05 -- info: Backup Duration: 1.50 Minutes
2009-11-12 06:31:05 -- info: Successfully completed backup for vMA-2!

2009-11-12 06:31:05 -- info: ============================== ghettoVCB LOG END ================================



Debug backup mode

  • Log verbosity: debug
  • Log output: stdout

[root@himalaya ~]# ./ghettoVCB.sh -f vms_to_backup -c backup_config -d debug
2009-11-13 19:51:47 -- info: ============================== ghettoVCB LOG START ==============================

2009-11-13 19:51:47 -- debug: HOST BUILD: VMware ESX 4.0.0 build-164009
2009-11-13 19:51:47 -- debug: HOSTNAME: himalaya.primp-industries.com

2009-11-13 19:51:51 -- info: CONFIG - USING CONFIGURATION FILE = backup_config/VCAP
2009-11-13 19:51:51 -- info: CONFIG - VM_BACKUP_VOLUME = /vmfs/volumes/dlgCore-NFS-bigboi.VM-Backups/WILLIAM_BACKUPS
2009-11-13 19:51:51 -- info: CONFIG - VM_BACKUP_ROTATION_COUNT = 3
2009-11-13 19:51:51 -- info: CONFIG - DISK_BACKUP_FORMAT = thin
2009-11-13 19:51:51 -- info: CONFIG - ADAPTER_FORMAT = buslogic
2009-11-13 19:51:51 -- info: CONFIG - POWER_VM_DOWN_BEFORE_BACKUP = 0
2009-11-13 19:51:51 -- info: CONFIG - ENABLE_HARD_POWER_OFF = 0
2009-11-13 19:51:51 -- info: CONFIG - ITER_TO_WAIT_SHUTDOWN = 4
2009-11-13 19:51:51 -- info: CONFIG - POWER_DOWN_TIMEOUT = 5
2009-11-13 19:51:51 -- info: CONFIG - SNAPSHOT_TIMEOUT = 15
2009-11-13 19:51:51 -- info: CONFIG - LOG_LEVEL = debug
2009-11-13 19:51:51 -- info: CONFIG - BACKUP_LOG_OUTPUT = stdout
2009-11-13 19:51:51 -- info: CONFIG - VM_SNAPSHOT_MEMORY = 0
2009-11-13 19:51:51 -- info: CONFIG - VM_SNAPSHOT_QUIESCE = 0
2009-11-13 19:51:51 -- info: CONFIG - VMDK_FILES_TO_BACKUP = VCAP.vmdk,VCAP_2.vmdk

2009-11-13 19:51:52 -- info: Initiate backup for VCAP
2009-11-13 19:51:52 -- debug: findVMDK() - Searching for VMDK: "VCAP_2.vmdk" to backup
2009-11-13 19:51:52 -- debug: findVMDK() - Found VMDK! - "VCAP_2.vmdk" to backup
Destination disk format: VMFS thin-provisioned
Cloning disk '/vmfs/volumes/himalaya-local-SATA.RE4-GP:Storage/VCAP/VCAP_2.vmdk'...
Clone: 100% done.
2009-11-13 19:51:53 -- debug: findVMDK() - Searching for VMDK: "VCAP_1.vmdk" to backup
2009-11-13 19:51:53 -- debug: findVMDK() - Searching for VMDK: "VCAP.vmdk" to backup
2009-11-13 19:51:53 -- debug: findVMDK() - Found VMDK! - "VCAP.vmdk" to backup
Destination disk format: VMFS thin-provisioned
Cloning disk '/vmfs/volumes/himalaya-local-SATA.RE4-GP:Storage/VCAP/VCAP.vmdk'...
Clone: 100% done.
2009-11-13 19:51:53 -- debug: findVMDK() - Searching for VMDK: "VCAP-0.vmdk" to backup
2009-11-13 19:51:54 -- info: Backup Duration: 2 Seconds
2009-11-13 19:51:54 -- info: Successfully completed backup for VCAP!

2009-11-13 19:51:54 -- info: CONFIG - USING CONFIGURATION FILE = backup_config/VIMA
2009-11-13 19:51:54 -- info: CONFIG - VM_BACKUP_VOLUME = /vmfs/volumes/dlgCore-NFS-bigboi.VM-Backups/WILLIAM_BACKUPS
2009-11-13 19:51:54 -- info: CONFIG - VM_BACKUP_ROTATION_COUNT = 3
2009-11-13 19:51:54 -- info: CONFIG - DISK_BACKUP_FORMAT = thin
2009-11-13 19:51:54 -- info: CONFIG - ADAPTER_FORMAT = buslogic
2009-11-13 19:51:54 -- info: CONFIG - POWER_VM_DOWN_BEFORE_BACKUP = 0
2009-11-13 19:51:54 -- info: CONFIG - ENABLE_HARD_POWER_OFF = 0
2009-11-13 19:51:54 -- info: CONFIG - ITER_TO_WAIT_SHUTDOWN = 4
2009-11-13 19:51:54 -- info: CONFIG - POWER_DOWN_TIMEOUT = 5
2009-11-13 19:51:54 -- info: CONFIG - SNAPSHOT_TIMEOUT = 15
2009-11-13 19:51:54 -- info: CONFIG - LOG_LEVEL = debug
2009-11-13 19:51:54 -- info: CONFIG - BACKUP_LOG_OUTPUT = stdout
2009-11-13 19:51:54 -- info: CONFIG - VM_SNAPSHOT_MEMORY = 1
2009-11-13 19:51:54 -- info: CONFIG - VM_SNAPSHOT_QUIESCE = 0
2009-11-13 19:51:54 -- info: CONFIG - VMDK_FILES_TO_BACKUP = all

2009-11-13 19:51:56 -- info: Initiate backup for VIMA
2009-11-13 19:51:56 -- info: Creating Snapshot "ghettoVCB-snapshot-2009-11-13" for VIMA
2009-11-13 19:51:58 -- debug: Waiting for snapshot "ghettoVCB-snapshot-2009-11-13" to be created
2009-11-13 19:51:58 -- debug: Snapshot timeout set to: 900 seconds
2009-11-13 19:52:01 -- debug: Waiting for snapshot creation to be completed - Iteration: 0 - sleeping for 60secs (Duration: 0 seconds)
2009-11-13 19:53:03 -- debug: findVMDK() - Searching for VMDK: "VIMA.vmdk" to backup
Destination disk format: VMFS thin-provisioned
Cloning disk '/vmfs/volumes/himalaya-local-SAS.Savvio/VIMA/VIMA.vmdk'...
Clone: 100% done.
2009-11-13 19:54:27 -- info: Removing snapshot from VIMA ...
2009-11-13 19:54:32 -- info: Backup Duration: 2.60 Minutes
2009-11-13 19:54:32 -- info: Successfully completed backup for VIMA!

2009-11-13 19:54:32 -- info: CONFIG - VM_BACKUP_VOLUME = /vmfs/volumes/dlgCore-NFS-bigboi.VM-Backups/WILLIAM_BACKUPS
2009-11-13 19:54:32 -- info: CONFIG - VM_BACKUP_ROTATION_COUNT = 3
2009-11-13 19:54:32 -- info: CONFIG - DISK_BACKUP_FORMAT = thin
2009-11-13 19:54:32 -- info: CONFIG - ADAPTER_FORMAT = buslogic
2009-11-13 19:54:32 -- info: CONFIG - POWER_VM_DOWN_BEFORE_BACKUP = 0
2009-11-13 19:54:32 -- info: CONFIG - ENABLE_HARD_POWER_OFF = 0
2009-11-13 19:54:32 -- info: CONFIG - ITER_TO_WAIT_SHUTDOWN = 3
2009-11-13 19:54:32 -- info: CONFIG - POWER_DOWN_TIMEOUT = 5
2009-11-13 19:54:32 -- info: CONFIG - SNAPSHOT_TIMEOUT = 15
2009-11-13 19:54:32 -- info: CONFIG - LOG_LEVEL = debug
2009-11-13 19:54:32 -- info: CONFIG - BACKUP_LOG_OUTPUT = stdout
2009-11-13 19:54:32 -- info: CONFIG - VM_SNAPSHOT_MEMORY = 0
2009-11-13 19:54:32 -- info: CONFIG - VM_SNAPSHOT_QUIESCE = 0
2009-11-13 19:54:32 -- info: CONFIG - VMDK_FILES_TO_BACKUP = all

2009-11-13 19:54:35 -- info: Initiate backup for vMA-2
2009-11-13 19:54:35 -- debug: findVMDK() - Searching for VMDK: "vMA-2.vmdk" to backup
Destination disk format: VMFS thin-provisioned
Cloning disk '/vmfs/volumes/himalaya-local-SAS.Constellation/vMA-2/vMA-2.vmdk'...
Clone: 100% done.
2009-11-13 19:56:10 -- info: Backup Duration: 1.58 Minutes
2009-11-13 19:56:10 -- info: Successfully completed backup for vMA-2!

2009-11-13 19:56:10 -- info: ============================== ghettoVCB LOG END ================================


Dry run Mode (no backup will take place)

  • Log verbosity: drymode
  • Log output: stdout

[root@himalaya ~]# ./ghettoVCB.sh -f vms_to_backup -c backup_config -d dryrun

2009-11-12 06:32:57 -- info: ============================== ghettoVCB LOG START ==============================

2009-11-12 06:33:01 -- info: CONFIG - USING CONFIGURATION FILE = backup_config/VCAP
2009-11-12 06:33:01 -- info: CONFIG - VM_BACKUP_VOLUME = /vmfs/volumes/dlgCore-NFS-bigboi.VM-Backups/WILLIAM_BACKUPS
2009-11-12 06:33:01 -- info: CONFIG - VM_BACKUP_ROTATION_COUNT = 3
2009-11-12 06:33:01 -- info: CONFIG - DISK_BACKUP_FORMAT = thin
2009-11-12 06:33:01 -- info: CONFIG - ADAPTER_FORMAT = buslogic
2009-11-12 06:33:01 -- info: CONFIG - POWER_VM_DOWN_BEFORE_BACKUP = 0
2009-11-12 06:33:01 -- info: CONFIG - ENABLE_HARD_POWER_OFF = 0
2009-11-12 06:33:01 -- info: CONFIG - ITER_TO_WAIT_SHUTDOWN = 4
2009-11-12 06:33:01 -- info: CONFIG - POWER_DOWN_TIMEOUT = 5
2009-11-12 06:33:01 -- info: CONFIG - SNAPSHOT_TIMEOUT = 15
2009-11-12 06:33:01 -- info: CONFIG - LOG_LEVEL = dryrun
2009-11-12 06:33:01 -- info: CONFIG - BACKUP_LOG_OUTPUT = stdout
2009-11-12 06:33:01 -- info: CONFIG - VM_SNAPSHOT_MEMORY = 0
2009-11-12 06:33:01 -- info: CONFIG - VM_SNAPSHOT_QUIESCE = 0
2009-11-12 06:33:01 -- info: CONFIG - VMDK_FILES_TO_BACKUP = VCAP.vmdk,VCAP_2.vmdk

2009-11-12 06:33:01 -- dryrun: ###############################################
2009-11-12 06:33:01 -- dryrun: Virtual Machine: VCAP
2009-11-12 06:33:01 -- dryrun: VM_ID: 2784
2009-11-12 06:33:01 -- dryrun: VMX_PATH: /vmfs/volumes/himalaya-local-SATA.RE4-GP:Storage/VCAP/VCAP.vmx
2009-11-12 06:33:01 -- dryrun: VMX_DIR: /vmfs/volumes/himalaya-local-SATA.RE4-GP:Storage/VCAP
2009-11-12 06:33:01 -- dryrun: VMX_CONF: VCAP/VCAP.vmx
2009-11-12 06:33:01 -- dryrun: VMFS_VOLUME: himalaya-local-SATA.RE4-GP:Storage
2009-11-12 06:33:01 -- dryrun: VMDK(s):
2009-11-12 06:33:01 -- dryrun:  VCAP_2.vmdk
2009-11-12 06:33:01 -- dryrun:  VCAP_1.vmdk
2009-11-12 06:33:01 -- dryrun:  VCAP.vmdk
2009-11-12 06:33:01 -- dryrun:  VCAP-0.vmdk
2009-11-12 06:33:01 -- dryrun: ###############################################

2009-11-12 06:33:01 -- info: CONFIG - USING CONFIGURATION FILE = backup_config/VIMA
2009-11-12 06:33:01 -- info: CONFIG - VM_BACKUP_VOLUME = /vmfs/volumes/dlgCore-NFS-bigboi.VM-Backups/WILLIAM_BACKUPS
2009-11-12 06:33:01 -- info: CONFIG - VM_BACKUP_ROTATION_COUNT = 3
2009-11-12 06:33:01 -- info: CONFIG - DISK_BACKUP_FORMAT = thin
2009-11-12 06:33:01 -- info: CONFIG - ADAPTER_FORMAT = buslogic
2009-11-12 06:33:01 -- info: CONFIG - POWER_VM_DOWN_BEFORE_BACKUP = 0
2009-11-12 06:33:01 -- info: CONFIG - ENABLE_HARD_POWER_OFF = 0
2009-11-12 06:33:01 -- info: CONFIG - ITER_TO_WAIT_SHUTDOWN = 4
2009-11-12 06:33:01 -- info: CONFIG - POWER_DOWN_TIMEOUT = 5
2009-11-12 06:33:01 -- info: CONFIG - SNAPSHOT_TIMEOUT = 15
2009-11-12 06:33:01 -- info: CONFIG - LOG_LEVEL = dryrun
2009-11-12 06:33:01 -- info: CONFIG - BACKUP_LOG_OUTPUT = stdout
2009-11-12 06:33:01 -- info: CONFIG - VM_SNAPSHOT_MEMORY = 1
2009-11-12 06:33:01 -- info: CONFIG - VM_SNAPSHOT_QUIESCE = 0
2009-11-12 06:33:01 -- info: CONFIG - VMDK_FILES_TO_BACKUP = all

2009-11-12 06:33:01 -- dryrun: ###############################################
2009-11-12 06:33:01 -- dryrun: Virtual Machine: VIMA
2009-11-12 06:33:01 -- dryrun: VM_ID: 4064
2009-11-12 06:33:01 -- dryrun: VMX_PATH: /vmfs/volumes/himalaya-local-SAS.Savvio/VIMA/VIMA.vmx
2009-11-12 06:33:01 -- dryrun: VMX_DIR: /vmfs/volumes/himalaya-local-SAS.Savvio/VIMA
2009-11-12 06:33:01 -- dryrun: VMX_CONF: VIMA/VIMA.vmx
2009-11-12 06:33:01 -- dryrun: VMFS_VOLUME: himalaya-local-SAS.Savvio
2009-11-12 06:33:01 -- dryrun: VMDK(s):
2009-11-12 06:33:01 -- dryrun:  VIMA.vmdk
2009-11-12 06:33:01 -- dryrun: ###############################################

2009-11-12 06:33:01 -- info: CONFIG - VM_BACKUP_VOLUME = /vmfs/volumes/dlgCore-NFS-bigboi.VM-Backups/WILLIAM_BACKUPS
2009-11-12 06:33:01 -- info: CONFIG - VM_BACKUP_ROTATION_COUNT = 3
2009-11-12 06:33:01 -- info: CONFIG - DISK_BACKUP_FORMAT = thin
2009-11-12 06:33:01 -- info: CONFIG - ADAPTER_FORMAT = buslogic
2009-11-12 06:33:01 -- info: CONFIG - POWER_VM_DOWN_BEFORE_BACKUP = 0
2009-11-12 06:33:01 -- info: CONFIG - ENABLE_HARD_POWER_OFF = 0
2009-11-12 06:33:01 -- info: CONFIG - ITER_TO_WAIT_SHUTDOWN = 3
2009-11-12 06:33:01 -- info: CONFIG - POWER_DOWN_TIMEOUT = 5
2009-11-12 06:33:01 -- info: CONFIG - SNAPSHOT_TIMEOUT = 15
2009-11-12 06:33:01 -- info: CONFIG - LOG_LEVEL = dryrun
2009-11-12 06:33:01 -- info: CONFIG - BACKUP_LOG_OUTPUT = stdout
2009-11-12 06:33:01 -- info: CONFIG - VM_SNAPSHOT_MEMORY = 0
2009-11-12 06:33:01 -- info: CONFIG - VM_SNAPSHOT_QUIESCE = 0
2009-11-12 06:33:01 -- info: CONFIG - VMDK_FILES_TO_BACKUP = all

2009-11-12 06:33:01 -- dryrun: ###############################################
2009-11-12 06:33:01 -- dryrun: Virtual Machine: vMA-2
2009-11-12 06:33:01 -- dryrun: VM_ID: 4960
2009-11-12 06:33:01 -- dryrun: VMX_PATH: /vmfs/volumes/himalaya-local-SAS.Constellation/vMA-2/vMA-2.vmx
2009-11-12 06:33:01 -- dryrun: VMX_DIR: /vmfs/volumes/himalaya-local-SAS.Constellation/vMA-2
2009-11-12 06:33:01 -- dryrun: VMX_CONF: vMA-2/vMA-2.vmx
2009-11-12 06:33:01 -- dryrun: VMFS_VOLUME: himalaya-local-SAS.Constellation
2009-11-12 06:33:01 -- dryrun: VMDK(s):
2009-11-12 06:33:02 -- dryrun:  vMA-2.vmdk
2009-11-12 06:33:02 -- dryrun: ###############################################

2009-11-12 06:33:02 -- info: ============================== ghettoVCB LOG END ================================





Enable compression for backups:


To make use of this feature, modify the variable ENABLE_COMPRESSION from 0 to 1. Please note, do not mix uncompressed backups with compressed backups. Ensure that directories selected for backups do not contain any backups with previous versions of ghettoVCB before enabling and implementing the compressed backups feature.

Restore backups (ghettoVCB-restore.sh):


To recover a VM that has been processed by ghettoVCB, please take a look at this document: Ghetto Tech Preview - ghettoVCB-restore.sh - Restoring VM's backed up from ghettoVCB to ESX(i) 3.5 and 4.0+



Cronjob FAQ:


Please take a moment to read over what is a cronjob and how to set one up, before continuing

The task of configuring cronjobs on classic ESX servers (with Service Console) is no different than traditional cronjobs on *nix operating systems (this procedure is outlined in the link above). With ESXi on the other hand, additional factors need to be taken into account when setting up cronjobs in the limited shell console called Busybox because changes made do not persist through a system reboot. The following document will outline steps to ensure that cronjob configurations are saved and present upon a reboot.

Task: Configure ghettoVCB.sh to execute a backup five days a week (M-F) at 12AM (midnight) everyday and send output to a unique log file

Configure on ESX:

1. As root, you'll install your cronjob by issuing:
[root@himalaya ~]# crontab -e


2. Append the following entry:
0 0 * * 1-5 /vmfs/volumes/dlgCore-NFS-bigboi.VM-Backups/ghettoVCB.sh /vmfs/volumes/dlgCore-NFS-bigboi.VM-Backups/backuplist > /vmfs/volumes/dlgCore-NFS-bigboi.VM-Backups/ghettoVCB-backup-$(date +\%s).log


3. Save and exit
[root@himalaya dlgCore-NFS-bigboi.VM-Backups]# crontab -e
no crontab for root - using an empty one
crontab: installing new crontab


4. List out and verify the cronjob that was just created:
[root@himalaya dlgCore-NFS-bigboi.VM-Backups]# crontab -l
0 0 * * 1-5 /vmfs/volumes/dlgCore-NFS-bigboi.VM-Backups/ghettoVCB.sh /vmfs/volumes/dlgCore-NFS-bigboi.VM-Backups/backuplist > /vmfs/volumes/dlgCore-NFS-bigboi.VM-Backups/ghettoVCB-backup-$(date +\%s).log


You're ready to go!

Configure on ESXi:

1. Setup the cronjob by appending the following line to /var/spool/cron/crontabs/root:

0 0 * * 1-5 /vmfs/volumes/simplejack-local-storage/ghettoVCB.sh /vmfs/volumes/simplejack-local-storage/backuplist > /vmfs/volumes/simplejack-local-storage/ghettoVCB-backup-$(date +\%s).log


2. Kill the current crond (cron daemon) and then restart the crond for the changes to take affect:

On ESXi < 3.5u3
/bin/kill `ps | grep crond | cut -f 1 -d ' '`


On ESXi 3.5u3+
~ # kill $(pidof crond)
~ # crond


On ESXi 4.0
~ # kill $(cat /var/run/crond.pid)
~ # busybox crond


3. Now that the cronjob is ready to go, you need to ensure that this cronjob will persist through a reboot. You'll need to add the following two lines to /etc/rc.local (ensure that the cron entry matches what was defined above)

On ESXi 3.5
/bin/kill $(pidof crond)
/bin/echo "0 0 * * 1-5 /vmfs/volumes/simplejack-local-storage/ghettoVCB.sh /vmfs/volumes/simplejack-local-storage/backuplist > /vmfs/volumes/simplejack-local-storage/ghettoVCB-backup-\$(date +\\%s).log" >> /var/spool/cron/crontabs/root
crond


On ESXi 4.0
/bin/kill $(cat /var/run/crond.pid)
/bin/echo "0 0 * * 1-5 /vmfs/volumes/simplejack-local-storage/ghettoVCB.sh /vmfs/volumes/simplejack-local-storage/backuplist > /vmfs/volumes/simplejack-local-storage/ghettoVCB-backup-\$(date +\\%s).log" >> /var/spool/cron/crontabs/root
/bin/busybox crond


Afterwards the file should look like the following:

~ # cat /etc/rc.local
#! /bin/ash
export PATH=/sbin:/bin

log() {
   echo "$1"
   logger init "$1"
}

#execute all service retgistered in /etc/rc.local.d
if [http:// -d /etc/rc.local.d |http:// -d /etc/rc.local.d ]; then
   for filename in `find /etc/rc.local.d/ | sort`
      do
         if [ -f $filename ] && [ -x $filename ]; then
            log "running $filename"
            $filename
         fi
      done
fi

/bin/kill $(cat /var/run/crond.pid)
/bin/echo "0 0 * * 1-5 /vmfs/volumes/simplejack-local-storage/ghettoVCB.sh /vmfs/volumes/simplejack-local-storage/backuplist > /vmfs/volumes/simplejack-local-storage/ghettoVCB-backup-\$(date +\\%s).log" >> /var/spool/cron/crontabs/root
/bin/busybox crond



This will ensure that the cronjob is re-created upon a reboot of the system through a startup script

2. To ensure that this is saved in the ESXi configuration, we need to manually initiate an ESXi backup by running:
~ # /sbin/auto-backup.sh
config implicitly loaded
local.tgz
etc/vmware/vmkiscsid/vmkiscsid.db
etc/dropbear/dropbear_dss_host_key
etc/dropbear/dropbear_rsa_host_key
etc/opt/vmware/vpxa/vpxa.cfg
etc/opt/vmware/vpxa/dasConfig.xml
etc/sysconfig/network
etc/vmware/hostd/authorization.xml
etc/vmware/hostd/hostsvc.xml
etc/vmware/hostd/pools.xml
etc/vmware/hostd/vmAutoStart.xml
etc/vmware/hostd/vmInventory.xml
etc/vmware/hostd/proxy.xml
etc/vmware/ssl/rui.crt
etc/vmware/ssl/rui.key
etc/vmware/vmkiscsid/initiatorname.iscsi
etc/vmware/vmkiscsid/iscsid.conf
etc/vmware/vmware.lic
etc/vmware/config
etc/vmware/dvsdata.db
etc/vmware/esx.conf
etc/vmware/license.cfg
etc/vmware/locker.conf
etc/vmware/snmp.xml
etc/group
etc/hosts
etc/inetd.conf
etc/rc.local
etc/chkconfig.db
etc/ntp.conf
etc/passwd
etc/random-seed
etc/resolv.conf
etc/shadow
etc/sfcb/repository/root/interop/cim_indicationfilter.idx
etc/sfcb/repository/root/interop/cim_indicationhandlercimxml.idx
etc/sfcb/repository/root/interop/cim_listenerdestinationcimxml.idx
etc/sfcb/repository/root/interop/cim_indicationsubscription.idx
Binary files /etc/vmware/dvsdata.db and /tmp/auto-backup.31345.dir/etc/vmware/dvsdata.db differ
config implicitly loaded
Saving current state in /bootbank
Clock updated.
Time: 20:40:36   Date: 08/14/2009   UTC



Now you're really done!

If you're still having trouble getting the cronjob to work, ensure that you've specified the correct parameters and there aren’t any typos in any part of the syntax.

Ensure crond (cron daemon) is running:

ESX:

[root@himalaya dlgCore-NFS-bigboi.VM-Backups]# ps -ef | grep crond | grep -v grep
root      2625     1  0 Aug13 ?        00:00:00 crond


ESXi:
~ # ps | grep crond | grep -v grep
5196 5196 busybox              crond


Ensure that the date/time on your ESX(i) host is setup correctly:

ESX(i):
[root@himalaya dlgCore-NFS-bigboi.VM-Backups]# date
Fri Aug 14 23:44:47 PDT 2009

Note: Careful attention must be noted if more than one backup is performed per day. Backup windows should be staggered to avoid contention or saturation of resources during these periods.



FAQ:


1Q: I'm getting error X when using the script or I'm not getting any errors, the backup didn’t even take place. Oh what could be wrong?
1A: Please provide the entire output of a manual execution (debug & dryrun mode) or if you're logging the output withing \{code\} tags, a short description of your environment and the type of VM(s) you're trying to backup—I will try to provide some assistance.

2Q: I've sent you private message or email but I haven't received a response? What gives?
2A: I do not accept issues/bugs reported via PM or email, I will reply back, directing you to post on the appropriate VMTN forum (that's what it's for). If the data/results you're providing is truely senstive to your environment I will hear you out, but 99.99% it is not, so please do not messsage/email me directly. I do monitor all forums that contain my script including the normal VMTN forums and will try to get back to your question as soon as I can and as time permits. Please do be patient as you're not the only person using the script (100,000+ views), thank you.

3Q: Can I schedule backups to take place hourly, daily, monthly, yearly?
3A: Yes, do a search online for crontab.

4Q: I would like to setup cronjob for ESX(i) 3.5 or 4.0?
4A: Take a look at the Cronjob FAQ section in this document.

5Q: I want to schedule my backup on Windows, how do I do this?
5A: Do a search for plink. Make sure you have paired SSH keys setup between your Windows system and ESX/ESXi host.

6Q: I only have a single ESXi host. I want to take backups and store them somewhere else. The problem is: I don't have NFS, iSCSI nor FC SAN. What can I do?
6A: You can use local storage to store your backups assuming that you have enough space on the destination datastore. Afterwards, you can use scp (WinSCP/FastSCP) to transfer the backups from the ESXi host to your local desktop.

7Q: I’m pissed; the backup is taking too long. My datastore is of type X?
7A: YMMV, take a look at your storage configuration and make sure it is optimized.

8Q: I noticed that the backup rotation is occurring after a backup. I don't have enough local storage space, can the process be changed?
8A: This is primarily done to ensure that you have at least one good backup in case the new backup fails. If you would like to modify the script, you're more than welcome to do so.

9Q: What is the best storage configuration for datastore type X?
9A: Search the VMTN forums; there are various configurations for the different type of storage/etc.

10Q: I want to setup an NFS server to run my backups. Which is the best and should it be virtual or physical?
10A: Please refer to answer 7A. From experience, we’ve seen physical instances of NFS servers to be faster than their virtual counterparts. As always, YMMV.

11Q: I have VMs that have snapshots. I want to back these things up but the script doesn’t let me do it. How do I fix that?
11A: VM snapshots are not meant to be kept for long durations. When backing up a VM that contains a snapshot, you should ensure all snapshots have been committed prior to running a backup. No exceptions will be made…ever.

12Q: I would like to restore from backup, what is the best method?
12A: The restore process will be unique for each environment and should be determined by your backup/recovery plans. At a high level you have the option of mounting the backup datastore and registering the VM in question or copy the VM from the backup datastore to the ESX/ESXi host. The latter is recommended so that you're not running a VM living on the backup datastore or inadvertently modifying your backup VM(s).

13Q: When I try to run the script I get: "-bash: ./ghettoVCB.sh: Permission denied", what is wrong?
13A: You need to change the permission on the script to be executable, chmod +x ghettoVCB.sh

14Q: Where can I download the latest version of the script?
14A: The latest version is available on this page at the bottom.

15Q: I would like to suggest/recommend feature X, can I get it? When can I get it? Why isn't it here, what gives?
15A: The general purpose of this script is to provide a backup solution around VMware VMs. Any additional features outside of that process will be taken into consideration depending on the amount of time, number of requests and actual usefulness as a whole to the community rather than to an individual.

16Q: What are the different type of backup uses cases that are supported with ghettoVCB?
16A: 1) Live backup of VM with the use of a snapshot and 2) Offline backup of a VM without a snapshot. These are the only two use cases supported by the script.



Useful Links:


Detail instructions on how to configure/schedule ghettoVCB on Windows (Raj Perumal's The World Runs on Technology Blog):

Part 1
Part 2
Part 3



Change log:

11/17/09 - The following enhancements and fixes have been implemented in this release of ghettoVCB. Special thanks goes out to all the ghettoVCB BETA testers for providing time and their environments to test features/fixes of the new script!

Enhancements:

  • Individual VM backup policy
  • Include/exclude specific VMDK(s)
  • Logging to file
  • Timeout variables
  • Configur snapshot memory/quiesce
  • Adapter format
  • Additional logging + dryrun mode
  • Support for both physical/virtual RDMs

Fixes:

  • Independent disk aware
Attachments:
Average User Rating
(11 ratings)




Dec 17, 2008 10:16 AM Shaveht  says:

How can i edit it to run on VIMA?

Dec 19, 2008 8:59 AM lamw  says:

Forgot to mention, you can also find more scripts/resources located at:

http://engineering.ucsb.edu/~duonglt/vmware/

Dec 19, 2008 9:08 AM lamw  says: in response to: Shaveht

Hi Shaveht,

This script can not be locally executed on VMware VIMA, but can be remotely kicked off from VIMA or any other UNIX/Linux, even a Windows host using plink.

The process is as follows:

You store the "ghettoVCB.sh" on shared storage (FC/iSCSI SAN / NFS), including the list of Virtual Machines you would like to backup. You can then create a cron entry that will kick off the backup process say every Friday at 12am. To ensure this does not require a user to enter a password, you'll need to utilize public/private SSH Key Authentication. This would then ssh into the ESX/ESXi host(s) and execute this script passing in the list which is also stored on the shared storage and the backup process would be kicked off.

This allows you to centralize your backup process without having to create separate cron entries on each of the ESX and ESXi hosts and storing a copy on each system. This does add an additional system to the process and if you know this VIMA host will always be accessible to the ESX/ESXi cluster, you should be fine.

An entry to the cron for the command would look like the following:

ssh root@A.B.C.D "/vmfs/volumes/SOME_DATASTORE/ghettoVCB.sh /vmfs/volumes/SOME_ADMIN_DATASTORE/virtual_machine_backup_list"


Again, you would just create a cron entry for the set of ESX/ESXi hosts and ensure that the datastore that contains the backup script and backup list are presented and visiable to all hosts. This also includes the datastore that is used to backup all the VMs are also visible/presented to all hosts

Hopefully this cleared up some of your questions and good luck

Dec 29, 2008 12:35 AM Shaveht  says: in response to: lamw

Hi lamw,
Thanks for the explanation.
in effect i was confused about how to use it.

thanks again.

Jan 9, 2009 6:43 PM dan82  says:

Hi,

I have 7 blade servers with approx 50 VM's, is it possible to run this script from just one esxi host and have it back up all the VM's that are running on it locally and also the VM's running on the other blades?

Jan 10, 2009 10:53 PM lamw  says: in response to: dan82

Take a look at the my previous comment. I would not suggest setting this up on an ESXi host, probably an administrative linux/windows or even VIMA host.


=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Jan 14, 2009 3:51 PM tuxfan2183  says: in response to: lamw

Nice script and Thanks for the same. The backup runs fine after few issues being faced in the start. I have the following queries.

1. Is there a way I can backup the vm's without shutting them down?
2. What is the ideal restore procedure? (assuming Its going to be a disk-to-disk restoration.)

Thanks
tux

Jan 14, 2009 4:05 PM lamw  says: in response to: tuxfan2183

Hi tuxfan2183,

1) The power down feature was recently added, if you want to backup your VM(s) while they're live, just ensure the flag "POWER_VM_DOWN_BEFORE_BACKUP" is set to 0=no, 1=yes. By default this option is set to 0 which is to backup while the VM is running

2) There are multitude of options, depending where and how the backups are being stored and what your backup scenario requires. You can either mount the backup datastore and register the VM either by browsing the VI Client datastore or manually using CLI tool like "vmware-cmd -s register" or "vim-cmd" for ESXi. If you do not want to directly mount your backup but rather restore back to your source ESX/ESXi host, you can just manually run "vmkfstools" copy from your backup datastore to your source datastore and then register your VM. Again, this will be environment specific, but those are your options and this can be easily scripted or done manually as this is a backup process which requires additional care.

Hope this answered your questions.


=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Jan 14, 2009 4:10 PM tuxfan2183  says: in response to: lamw

Thanks william. You are the best

Jan 21, 2009 6:57 PM nappyrat  says:

does this only back up 1 vmdk file per virtual machine? I ran it and it backed up teh vmdk of a vm i have but not another vmdk that is in the same directory

Jan 21, 2009 7:43 PM lamw  says: in response to: nappyrat

No, it should backup all "valid" VMDK(s) that is associated with a VM. Yon can verify this by going into the VM's "edit virtual machine settings" and ensure that all disks are listed within the hardware tab.

When you use the VIC to delete a disk and selecting the option "Remove from virtual machine", this will only remove the disk from being accessible to the VM, but the actual disk will still be located on the datastore and within the .vmx file, the disk will have a present value of "false". If you want to truly delete the VM's disk, you need to select the other option, so be sure before doing so.

Let me know if you have any other questions


=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Jan 21, 2009 8:09 PM tuxfan2183  says: in response to: lamw

There are certain things which I as a user thought could add more value to this script. When taking backup to compress and store the backup in a compressed format in the remote location. makes sense?

Jan 21, 2009 8:12 PM lamw  says: in response to: tuxfan2183

That is a good suggestion, but unfortunately there are many options in terms of compression format/type/etc and I would leave that to the end user to implement if required.

=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Jan 21, 2009 8:27 PM alubel  says: in response to: tuxfan2183

Why dont you try to setup a solaris 10 or opensolaris box and use a compressed ZFS file system via NFS to ESXi host?

Its extremely easy - and no expensive hardware required.

Jan 21, 2009 8:52 PM nappyrat  says: in response to: lamw

i found the problem. here is the 2nd disk in the .vmx file. I can almost guaruntee you this wasn't modified by hand because I don't think the person who created it has no idea how to.

scsi0:1.filename = "datastore_1.vmdk"

the line in your script that finds the disks is

VMDKS=`grep scsi "${VMX_PATH}" | grep fileName | awk -F "\"" '{print $2}'`

it's a case issue. maybe that should be changed to a "grep -i fileName"

Jan 21, 2009 9:47 PM lamw  says: in response to: nappyrat

Yea it should be -i, but from the various .vmx file I've viewed in the past for both 3.0 and 3.5 it's always been "fileName". What version of ESX are you running btw? This is the first I've heard of this issue


=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Jan 22, 2009 3:31 AM nappyrat  says: in response to: lamw

esx server 3i 3.5.0 build 123629

i just reproduced this by adding a second hard disk with VIC to the virtual machine and it puts it in the vmx with filename not fileName

Jan 22, 2009 6:54 AM Thomas BRETON  says: in response to: nappyrat

Hello,
I'm trying your script.
Thanks for your work.
Just a question relative to performance.
In fact i was using vcbMounter on a local datastore and on an nfs server.
Backup time for the same machine:
with vcbmount on local datastore: 7 min
with vcbmount on NFS: 13 min

With your script on local datastore: 5 min
With your script on NFS: 180 min

Have you got an explanation for this or any clue?
Regards
Tom

Jan 22, 2009 7:09 AM nappyrat  says: in response to: Thomas BRETON

my first run of this script was really slow over nfs too, around 25GB per hour. i blamed that on my cheap nas device.

i don't know what vcbmounter is, but does it copy with a straight copy or does it do a clone disk like this script does?

Jan 22, 2009 8:34 AM lamw  says: in response to: Thomas BRETON

I'm not familiar with the vcbMounter tool, YMMV with different environments and I've seen various postings about the different performance with NFS and it all depends on your configuration and the type of NFS server you're running. It should not differ with over 100+min so I'm not exactly sure what type of VM you're backing up/etc. Does this occur on all VM(s) or just this one?

Also and FYI, the VMware VCB tools that come installed by default on the ESX host are only available with the version of ESX w/Service Console, this is not part of the ESXi releaese.

=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Jan 22, 2009 8:35 AM lamw  says: in response to: nappyrat

Interesting, perhaps this is only with ESXi. I'll double check with my ESXi 3.5u3 and see if this is also the case, if so I'm surprised this is the first time it's been caught. I know there's quite a few people using this script on unlicensed version of ESXi. Thanks for the info

=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Jan 22, 2009 11:04 AM apignoloni  says:

when I run the command sh ./ghetto.sh vm_list from path / vmfs/volumes/datastore1/ of esxi 3.5 returns the following error:
. / ghetto.sh:. / ghetto.sh: 76: Syntax error: word unexpected (expecting "do").
What could be the problem?
Thank you.

Jan 22, 2009 11:27 AM lamw  says: in response to: apignoloni

I'm not exactly sure what the issue could be. I suggest re-downloading the script and ensure the script has been set to execute. If you download to a Windows system, you might have some ^M characters if you tried to edit prior to executing on ESX/ESXi host. Make sure you edit it on the host themselves to ensure you don't run into this issue.

You can always run:

sh -x ghetto.sh vm_list


and see what might be causing the issue.


=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Jan 22, 2009 11:49 AM apignoloni  says:

Thanks for your answer, the script has been set to execute and the file has been downloaded and modified with ubuntu desktop.
This is the result of the command:
/vmfs/volumes/4975d95d-45fc3458-7ff4-001b212e4341 # sh -x ghetto.sh vm_list
+
: not foundghetto.sh: 6:
+ VM_BACKUP_VOLUME=/vmfs/volumes/datastore2/backupvm/
+
: not foundghetto.sh: 9:
+ ENABLE_2GB_SPARSE=0
+
: not foundghetto.sh: 12:
+ VM_BACKUP_ROTATION_COUNT=3
+
: not foundghetto.sh: 15:
+ date +%F
+ VM_BACKUP_DIR_NAMING_CONVENTION=2009-01-22
: not foundghetto.sh: 17:
+
: not foundghetto.sh: 18:
+ POWER_VM_DOWN_BEFORE_BACKUP=0
+
: not foundghetto.sh: 23:
+ ENABLE_HARD_POWER_OFF=0
+
: not foundghetto.sh: 26:
+ ITER_TO_WAIT_SHUTDOWN=4
+
: not foundghetto.sh: 31:
+
: not foundghetto.sh: 36:
+ ENABLE_NON_PERSISTENT_NFS=0
+
: not foundghetto.sh: 38:
+ UNMOUNT_NFS=0
+
: not foundghetto.sh: 41:
+ NFS_SERVER=172.30.0.195
+
: not foundghetto.sh: 44:
+ NFS_MOUNT=/nfsshare
+
: not foundghetto.sh: 47:
+ NFS_LOCAL_NAME=nfs_storage_backup
+
: not foundghetto.sh: 50:
+ NFS_VM_BACKUP_DIR=mybackups
: not foundghetto.sh: 52:
+
: not foundghetto.sh: 53:
+
: not foundghetto.sh: 55:
+
: not foundghetto.sh: 57:
+ DEVEL_MODE=0
+
: not foundghetto.sh: 59:
+ basename ghetto.sh
+ SCRIPT_PATH=ghetto.sh
VM_FILE_INPUT\n ghetto.sh

VM_FILE_INPUT

+ exit
: not foundghetto.sh: 63: exit
+ }
: not foundghetto.sh: 64: }
+
: not foundghetto.sh: 65:
+ local BACKUP_DIR_PATH=vm_list
+ local BACKUP_VM_NAMING_CONVENTION=
+ ls -tr vm_list
: No such file or directory
+ LIST_BACKUPS=
+
: not foundghetto.sh: 70:
ghetto.sh: ghetto.sh: 76: Syntax error: word unexpected (expecting "do")
/vmfs/volumes/4975d95d-45fc3458-7ff4-001b212e4341 # sh -x ./ghetto.sh vm_list
+
: not found: ./ghetto.sh: 6:
+ VM_BACKUP_VOLUME=/vmfs/volumes/datastore2/backupvm/
+
: not found: ./ghetto.sh: 9:
+ ENABLE_2GB_SPARSE=0
+
: not found: ./ghetto.sh: 12:
+ VM_BACKUP_ROTATION_COUNT=3
+
: not found: ./ghetto.sh: 15:
+ date +%F
+ VM_BACKUP_DIR_NAMING_CONVENTION=2009-01-22
: not found: ./ghetto.sh: 17:
+
: not found: ./ghetto.sh: 18:
+ POWER_VM_DOWN_BEFORE_BACKUP=0
+
: not found: ./ghetto.sh: 23:
+ ENABLE_HARD_POWER_OFF=0
+
: not found: ./ghetto.sh: 26:
+ ITER_TO_WAIT_SHUTDOWN=4
+
: not found: ./ghetto.sh: 31:
+
: not found: ./ghetto.sh: 36:
+ ENABLE_NON_PERSISTENT_NFS=0
+
: not found: ./ghetto.sh: 38:
+ UNMOUNT_NFS=0
+
: not found: ./ghetto.sh: 41:
+ NFS_SERVER=172.30.0.195
+
: not found: ./ghetto.sh: 44:
+ NFS_MOUNT=/nfsshare
+
: not found: ./ghetto.sh: 47:
+ NFS_LOCAL_NAME=nfs_storage_backup
+
: not found: ./ghetto.sh: 50:
+ NFS_VM_BACKUP_DIR=mybackups
: not found: ./ghetto.sh: 52:
+
: not found: ./ghetto.sh: 53:
+
: not found: ./ghetto.sh: 55:
+
: not found: ./ghetto.sh: 57:
+ DEVEL_MODE=0
+
: not found: ./ghetto.sh: 59:
+ basename ./ghetto.sh
+ SCRIPT_PATH=ghetto.sh
VM_FILE_INPUT\n ghetto.sh

VM_FILE_INPUT

+ exit
: not found: ./ghetto.sh: 63: exit
+ }
: not found: ./ghetto.sh: 64: }
+
: not found: ./ghetto.sh: 65:
+ local BACKUP_DIR_PATH=vm_list
+ local BACKUP_VM_NAMING_CONVENTION=
+ ls -tr vm_list
: No such file or directory
+ LIST_BACKUPS=
+
: not found: ./ghetto.sh: 70:
./ghetto.sh: ./ghetto.sh: 76: Syntax error: word unexpected (expecting "do")
/vmfs/volumes/4975d95d-45fc3458-7ff4-001b212e4341 #

Jan 22, 2009 11:56 AM lamw  says: in response to: apignoloni

It's kind of hard to tell what's going on with the output. What system are you running this on? Which version of the script did you download? Can you also list the contents of your vm_list

Can you also try the following:

Change

VM_BACKUP_VOLUME=/vmfs/volumes/datastore2/backupvm/

to

VM_BACKUP_VOLUME=/vmfs/volumes/datastore2/backupvm

If that still yields the same results, can you also find the variable DEVEL_MODE and change that from 0 to 1 and see if the script progresses farther or continues to error out.


=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Jan 22, 2009 12:01 PM nappyrat  says: in response to: apignoloni

also, you didn't remove the first line with #!/bin/bash did you? or you're not using some wierd shell are you?

Jan 22, 2009 12:15 PM apignoloni  says:

I downloaded version ghettoVCB-enhance.sh. The contents of the list is as follows:

windows xp

ubuntu server 32bit

this change VM_BACKUP_VOLUME=/vmfs/volumes/datastore2/backupvm had no effect.

Aalso the change of value DEVEL_MOdE variable had no effect.

Jan 22, 2009 12:20 PM lamw  says: in response to: apignoloni

Are you running this on ESX or ESXi? I also noticed you're executing this script on one of your datastores, it should not matter but can you try to move the script to another location, perhaps /root. I just downloaded both scripts and they executed fine using the default and just modifying the backup path, the issue seems to be in your environment but I'm not sure what might be causing this issue.

Could you also run the following on the shell:

echo $SHELL


vmware -v 


=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Jan 22, 2009 12:24 PM apignoloni  says:

I have not touched the first line of the script and the shell I use is integrated into the system vmware ESXi 3.5.I try to move the script in the root.

Jan 22, 2009 12:32 PM apignoloni  says:

The command echo $SHELL returns:/bin/ash
The command vmware -v returns:VMware ESX Server 3i 3.5.0 build-123629
Moving the file in the root me back the message: Operation not permitted

Jan 22, 2009 12:38 PM lamw  says: in response to: apignoloni

Okay so looks like you're running the the latest ESXi 3.5u3, which is the same release I just finished testing as well and I don't see any issues. Since you're running on ESXi, there will not be a directory /root, just /.

It's going to get pretty difficult to troubleshoot exactly what the issue is, for some reason the system isn't liking the script. If you understand what the script is doing or have some scripting experience, you can setup some basic echo statements and see exactly where the script stops execution. From the looks of it, it seems to get through all the user defined variables but halts right before the actual code starts. If you can narrow down on the junk of code that it fails on, perhaps I can assist you further.

Also, your two VM(s) have the following displayName?

windows xp
ubuntu server 32bit

Actually locate the following line and change that from

# DO NOT MODIFY PAST THIS LINE #


to

exit

# DO NOT MODIFY PAST THIS LINE #


I'm wondering if the issue is after the variable declaration or after.

=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Jan 22, 2009 12:53 PM Thomas BRETON  says: in response to: lamw

Hello,
I don't know really the difference between vcbmount and snapshots.
I know that vcbmount work on vmdk files to compact them.
The NFS server is a FreeNAS on a 2x3Ghz xeon with one disk of 300Gb 15K U320.
I'm using ESX 3.5.

I don't think it's related to nfs configuration or server performance because for the same vm and for the same nfs server the vcbmount take 13 min and your script take 180 min
And yes it's the same problem for all machines

I'm still investigating on this
Regards
Tom

Jan 22, 2009 12:58 PM RENATOG123  says:

Can you tell me what variables need to be changed (other than NFS_SERVER and VM_BACKUP_DIR) in order for this script to work?
Also, how can I create a script that will initiate a snapshot of each VM, store them in the NFS (for daily backups) and another script that will do a full backup of each VM?
We are using ESXi 3.5u3
Thanks

Jan 22, 2009 1:00 PM lamw  says: in response to: RENATOG123

Please take a look at the documentation for your questions, it should answer majority of them.


=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Jan 22, 2009 1:00 PM apignoloni  says:

I am not an expert in scripting and general Linux environment, I am a beginner.
Yes, my two VM(s) have that name.
Also by entering the command exit the error is always in the same line in the script

Jan 22, 2009 1:11 PM lamw  says: in response to: apignoloni

The "exit' you inserted, allowed me to see where the issue is occuring. It's telling to the script to basically exit once it hits that line. This means the error is caused during the variable declaration section before it even starts to execute.

This brings me to believe the file may have some additional characters that may not be part of the original script/etc, perhaps characters from a Windows system. Did you download this from your Ubuntu box and scp the script to your ESXi host?

Can you run the following:

wc -l ghettoVCB-enhance.sh


wc -c ghettoVCB-enhance.sh


Also can you paste the variables you've modified from the default script and please format the output using the following tags {quote} ...your output... {quote}, it makes it easier for me to read and try to troubleshoot


=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Jan 22, 2009 1:11 PM RENATOG123  says: in response to: lamw

I'm sorry, can you provide a link for the documentation?
Thanks

Jan 22, 2009 1:17 PM lamw  says: in response to: RENATOG123

If you're posting in this section of the forum, you're already looking at the documentation. Please go over the instructions carefully, I do ask that new users read through the documentation before posting a question as you can answer most of your questions this way. You'll see that both your use cases can be solved by using this script and may require slight modifications, again this script is intended to help backup VM(s) that may reside on ESX/ESXi 3.5+. This script will not cover all processes/requirements for a backup or recovery scenario, I leave it to the discretion of the end user to understand what this script is doing and making modifications that fit your operating environment and needs.

You're welcome to post follow-up questions if you're still unsure of how the script operates or question about the functionality of the script. Hope this helps

=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Jan 22, 2009 2:04 PM apignoloni  says:

Problem solved: the file ghettoVCB-enhance.sh downloaded from the link higher contains the end of each line the notorious ^M, while the other file ghettoVCB.sh is clean
Thanks to all.

Jan 22, 2009 2:47 PM nappyrat  says:

William,

I was wondering if you could recommend teh best way for recovering a vm from a backup like this. Like say your esxi server blew up one day and you put a brand new one in it's place and hooked it up to the nas you had bacccked up your vms to.

most of hte instructions out there involve manually creating a vm in vic like the one you used to have, deleting it's hard drive, cloning the backup disk into your vm dir with vmkfstools -i and then adding it to your virtual machine.

since all the vm information is stored in a .vmx it seems like it should be easier to restore a vm, is it just that there aren't vm creation tools at the command line that can be used?

Jan 22, 2009 3:16 PM lamw  says: in response to: nappyrat

There are many scenarios in terms of recovery and this really depends on your requirements/environment. If you look at the simplest case where you have a new ESX/ESXi host and you present the NFS datastore which contains the backup VM(s) to the host. All you really need to do is just browse the datastore using the VIC and click into each of your VM(s) and right click and add to inventory. You should see your VM registered to the host and you can power them VM on. This assumes that want your recovered VM(s) running on your backup datastore, it's probably best to definitely copy the VM to your new host, register and power on. Going off of that, yes you'll need to copy the .vmx and copy the VMDK(s) associated with that VM and you should be using vmfkstools -i as you've suggested. Again once you understand this process manually, it's relatively easy to automate and script this process. Again, this process will vary from user to user and based on your requirements, you'll come up with a solution hat fits your environment.


=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Jan 22, 2009 3:28 PM nappyrat  says: in response to: lamw

gotcha, thanks again for your work!

Jan 23, 2009 6:38 AM apignoloni  says:

Good morning,
I created the script backupvm in /usr/local/bin running:
#!/bin/sh
ssh root@192.168.100.165 "sh /vmfs/volumes/datastore1/ghettoVCB.sh /vmfs/volumes/datastore1/vm_list"
#invio promemoria
echo backup vm posmailbe del `date ‘+%d-%B-%Y’`|mail -s “backup vm posmailbe” \ aaaaaa@iol.it

I also assigned the permission of execution.

I changed the file cron as follows:

americo@ubuntuserver32:/usr/local/bin$ sudo crontab -l

  1. m h dom mon dow command
15 15 * * * /usr/local/bin/backup_vm

but at the established nothing happens. The commands are formally correct?
Thank you

Jan 23, 2009 7:31 AM lamw  says: in response to: apignoloni

When setting up a cron entry, make sure the paths to all the commands use are the fullpath.

Please take a look at this thread to ensure they are: http://communities.vmware.com/message/1151164#1151164

I believe the vmkfstools is not being passed in my script as the full path, so you'll probably have to fix at least that command.


=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Jan 26, 2009 10:37 AM ollivetti  says: in response to: lamw

Hello, I have a question: Is it possible to backup additional added disks too? We have the OS on disk1 and the files on disk2. Does this backupscript support this. I could not find anything and tying it only made a backup of disk1.
Another thing I would like to ask is if you know any troubles using this script wiht ESX Version 3.02.

Thank you very much - also for the hard work writing this script!
Regards

Jan 26, 2009 10:38 AM lamw  says:

Yes, please download the latest script ghettoVCB-enhance.sh which will backup all valid VMDK(s) presented to the VM. This was added awhile back but I guess I must have forgotten to update the doc. I'll make sure I do that tonight and also remove the old instance of the script.


=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Jan 26, 2009 11:13 AM ollivetti  says: in response to: lamw

I just read in the comments about the grep -i fileName change...It now works ...
That's really great work you've done! Respect!
Thank you

Jan 26, 2009 11:48 PM ollivetti  says: in response to: lamw

Sorry one more stupid question - does it also work on ESX3.02? I see the note "You*'re not running ESX 3.5+ ....
Or are there known issues using the script with 3.02.
Thank you!

Jan 27, 2009 7:24 AM lamw  says: in response to: ollivetti

Hi ollivetti,

Sorry, this script only supports ESX 3.5+, the requirement is stated in the title and also noted in the body of the document. This was intentional since majority of the users were also using this on ESXi and the only common toolset between ESXi and ESX is vimsh. You probably can slightly modify it to support older version of ESX, as vimsh does exists going back to 3.0, but I have not tested that far back. You can uncomment the section of the code that blocks it from executing if you're not running either ESXi or ESX 3.5+.


=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Jan 27, 2009 1:21 PM RENATOG123  says: in response to: lamw

lamw,
I was finally able to get the NFS setup working with WSFU (in case anyone's pulling their hairs out, make that when you configure User Name Mapping, you map the LOCAL ADMIN account (not a domain admin) to "root")

I tested with a live running VIMA and it did a full backup of the VM.

I want to modify the script to do regular snapshots, not clone snapshots. Where/What do I have to change on the ghettoVCB-enhanced.sh script?
Thanks

Jan 27, 2009 1:24 PM lamw  says: in response to: RENATOG123

I'm not sure what you mean by regular snapshots, I'm aware of only one type and the snapshot can be taken with/without the state of the memory. Please look into script on where the snapshot is being taken, I believe it's documented in the script if you go through it.


=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Jan 28, 2009 5:56 AM RENATOG123  says: in response to: lamw

What would be the procedure to restore the ghettoVCB backups?

Jan 28, 2009 6:13 AM nappyrat  says: in response to: RENATOG123

the procedure i use is

If you just need to restore a vm to a state it was during the backup, and you still have your existing vm:

1. delete the hard drive of the vm from within vic, choosing to remove tne files from the disk as well.
2. clone the disk from backup to the directory of your vm with
vmkfstools -i /path/to/backup/disk.vmdk /path/to/vm/
3. add the hard drive to your vm choosing to use an existing virtual disk, select the /path/to/vm/disk.vmdk that you just made

If you need to restore the vm to another host or simply deleted it all together

1. make a directory /vmfs/volumes/whatever/vm-name
2. copy the .vmx file from backup to this dir
3. clone the disk from backup to the directory of the vm
vmkfstools -i /path/to/backup/disk.vmdk /vmfs/volumes/whatever/vm-name/
4. Browse the datastore in VIC, find the .vmx file, right click and select add to inventory.

not sure if theres a better way of doing it but it works for me.

Jan 28, 2009 6:35 AM RENATOG123  says: in response to: nappyrat

How were you able to create a directory? When I try "mkdir whatever" I get: Operation not permitted.
I am logged in as "root". Am I missing something?

Thanks

Jan 29, 2009 1:38 AM ollivetti  says: in response to: lamw

Hi, first of all thank you again for your response! I see you have quite a lot of questions to answer. One thing I would like to ask because I have problems is: I am using 3.02 and don't have vmware-vim-cmd so I use vmware-cmd or shall I use vimsh -n -e to execute commands. Unfortunately the execution stops here: echo "Error: failed to extract VM_ID for ${VM_NAME}!" Does it mean that the script is looking for der VirtualMachine ID in /tmp/vms_list.
Regards

Jan 29, 2009 8:27 AM lamw  says: in response to: ollivetti

Please take a look at the vimsh documentation to understand how it works.

http://engineering.ucsb.edu/~duonglt/vmware/#vmware_vimsh

=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Jan 30, 2009 9:07 AM ibhp  says: in response to: lamw

Hello

Thank you for this script! Really good work. The only thing that does not seem to work for me is backing up more than one vmdk in a vm. I tried several times with no luck. Do I have to do something special to get it to work?

Thank you for an answer.

Jan 30, 2009 9:14 AM lamw  says: in response to: ibhp

Are you running ESXi? If so, you might need to change the line "grep fileName" to' grep -i fileName".

Multi-VMDK(s) are supported, so long they're valid and presented to the guestOS.


=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Jan 30, 2009 11:01 AM ibhp  says: in response to: lamw

Yes, I am running ESXi. If I run the command:

VMDKS_FOUND=`grep scsi "${VMX_PATH}" | grep -i fileName | awk -F " " '{print $1}'`

on a cmd-sh, it gives me both scsi-vm-hdd... so thats all ok. But when I run your script, only the first (50G) HDD is backed-up, the second HD (300GB) not.

Do you have any ideas what could cause this problem?
Thank you very much!

Jan 30, 2009 11:29 AM nappyrat  says: in response to: ibhp

you have to modify the script to have grep -i as well, it only uses grep without the -i which only returns matches to the exact case fileName. esxi servers sometimes have it as filename (lower case n)

Jan 30, 2009 12:34 PM ibhp  says: in response to: nappyrat

Thank you for the response.

Of course I also modified the script... But still got only one vm-hdd backuped. I tried to troubleshoot in the script and what I found is the following. After the line:
grep "${SCSI_ID}.present" "${VMX_PATH}" | grep "true" > /dev/null 2>&1
it gives me the Value "1" for the second vm-hdd, which probably means it is not present??? But it is my data-disk which IS present in the vm... what do I have to modify?

Thank you.

Jan 30, 2009 1:10 PM lamw  says: in response to: ibhp

if you get a value of 1 for that particular line, it means that within the .vmx file for the ${SCSI_ID}.present = "true". This means that the VMDK was either removed from the VM but not deleted from the filesystem or it was removed and deleted from the filesystem. In either case, the reference is left in the .vmx file and the flag is just changed from true to false.

To verify this, you can look at your .vmx file, and if the code is returning a 1, it means that disk is not present to the VM which means it should not be showing up in the VI Client when you go into it's properties unless the .vmx file has been manually modified without the ESX/ESXi knowing about it.

=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Jan 30, 2009 4:43 PM ibhp  says: in response to: lamw

That seems to be strange... if you look at the content of my vmx-file:
/vmfs/volumes/497b9254-df6992a6-9fc0-0090270f57c5/Win2K3 TS # cat Win2K3\ TS.vmx
config.version = "8"
virtualHW.version = "4"
floppy0.present = "true"
nvram = "Win2K3 TS.nvram"
deploymentPlatform = "windows"
virtualHW.productCompatibility = "hosted"
tools.upgrade.policy = "useGlobal"
powerType.powerOff = "default"
powerType.powerOn = "default"
powerType.suspend = "default"
powerType.reset = "default"

displayName = "Win2K3 TS"
extendedConfigFile = "Win2K3 TS.vmxf"

numvcpus = "2"
scsi0.present = "true"
scsi0.sharedBus = "none"
scsi0.virtualDev = "lsilogic"
memsize = "1024"
scsi0:0.present = "true"
scsi0:0.fileName = "Win2K3 TS.vmdk"
scsi0:0.deviceType = "scsi-hardDisk"
ide0:0.present = "true"
ide0:0.clientDevice = "FALSE"
ide0:0.deviceType = "cdrom-image"
ide0:0.startConnected = "TRUE"
floppy0.startConnected = "false"
floppy0.clientDevice = "true"
ethernet0.present = "true"
ethernet0.networkName = "VM Network"
ethernet0.addressType = "generated"
guestOSAltName = "Microsoft Windows Server 2003, Standard Edition (32-bit)"
guestOS = "winnetstandard"
uuid.location = "56 4d 61 2a b1 4c 7f ca-b4 81 00 31 27 13 e1 0d"
uuid.bios = "56 4d 61 2a b1 4c 7f ca-b4 81 00 31 27 13 e1 0d"
toolScripts.afterPowerOn = "true"
toolScripts.afterResume = "true"
toolScripts.beforeSuspend = "true"
toolScripts.beforePowerOff = "true"

ide0:0.fileName = "/vmfs/volumes/497b9254-df6992a6-9fc0-0090270f57c5/Windows Server 2003/Windows Server 2003.Enterprise.German.ISO"
floppy0.fileName = "/dev/fd0"

scsi0:0.redo = ""
ethernet0.generatedAddress = "00:0c:29:13:e1:0d"
tools.syncTime = "FALSE"
sched.swap.derivedName = "/vmfs/volumes/497b9254-df6992a6-9fc0-0090270f57c5/Win2K3 TS/Win2K3 TS-af7ea147.vswp"
ethernet0.generatedAddressOffset = "0"
hostCPUID.0 = "0000000a756e65476c65746e49656e69"
guestCPUID.0 = "0000000a756e65476c65746e49656e69"
userCPUID.0 = "0000000a756e65476c65746e49656e69"
hostCPUID.1 = "00010676000208000008e39dbfebfbff"
guestCPUID.1 = "0001067800010800000802010febbbff"
userCPUID.1 = "0001067600020800000802010febbbff"
hostCPUID.80000001 = "00000000000000000000000120100000"
guestCPUID.80000001 = "00000000000000000000000000100000"
userCPUID.80000001 = "00000000000000000000000120100000"
evcCompatibilityMode = "FALSE"
scsi0:1.present = "TRUE"
scsi0:1.deviceType = "scsi-hardDisk"
scsi0:1.filename = "Win2K3 TS_1.vmdk"
scsi0:1.mode = "persistent"
scsi0:1.redo = ""
****************************************
Here you can see that scsi0:0 as well as scsi0:1 is present and true.... And I am working with this device every day, so it IS present...

Do you have any idea? Thank you very much for your help, I am really out of any guess....

Jan 30, 2009 4:49 PM lamw  says: in response to: ibhp

Look at what the script is doing .... it's grepping for "true" ... looks like your .vmx has "TRUE", see the problem.

I'm curious on why some of the user's .vmx files are slightly different from the one's I've worked with. I'm not sure if this is due to any specific version or user's are manually modifying their files. I've always seen the right hand side use lower case values, but I have seen it few times in older releases where it's all caps. I'll try to find some time this weekend to fix those two issues, it should be using grep -i.

That should fix your issue


=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Jan 31, 2009 3:03 AM ibhp  says: in response to: lamw

Thank you, it's now working like a charme!

But does somebody know how to start this script automatically with some kind of "cronjob" in ESXi? I tried the idea with "autobackup.sh" and included the "cron" directory in this script, but it does not seem to work... (Always get the following error:

diff: Can't stat '/tmp/auto-backup.237536.dir/var/spool/cron/crontabs/root': No such file or directory
which means this temporary directory/file has not been created by the script...

Thank you!

Jan 31, 2009 3:52 AM nappyrat  says: in response to: ibhp

I did it by adding the following lines to /etc/rc.local

/bin/echo "0 19 5 * * /vmfs/volumes/vmback/ghettoVCB.sh" >> /var/spool/cron/crontabs/root
/bin/busybox crond -b

then run auto-backup.sh it will backup the changes to the rc.local file

basically this makes it so on boot the ghettovcb entry is added to the crontab and crond is restarted.

Jan 31, 2009 8:24 AM lamw  says: in response to: nappyrat

I believe these changes do not persist do a reboot? I remember talking to someone about this and on reboot these changes are reverted to their original configurations, including the cron entry. Is that correct?


=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Jan 31, 2009 8:32 AM nappyrat  says: in response to: lamw

the auto-backup.sh script which runs like every hour or so i think backs up a number of files in /etc to be persistant upon reboot. this is why things like modifying inetd.conf to enable ssh still work after reboot. /etc/rc.local is another one that changes will be saved. that is why i put the code in there to add the crontab entry on boot.

Jan 31, 2009 2:07 PM lamw  says: in response to: nappyrat

Ah good to know, I'm aware of the backup but I thought someone had mentioned earlier in another forum thread that files are not persisted through a reboot. That is good to hear, I'll try to find some time to update the doc stating that fact. Thanks


=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Feb 1, 2009 2:42 AM ibhp  says: in response to: lamw

Hello

Yes, I can confirm the Backups are persistent when you write the stuff in rc.local. All runs without problems.

Thank you for all the good tipps!

Feb 10, 2009 1:50 PM cybersayo  says: in response to: ibhp

First, thank for the great script lamw!

Everything works well when I do ghetto from SAN to local hard drive, but when I try gheto to NFS I get
"DiskLib_Check() failed for source disk The system cannot find the file specified (25)" after cloning and snapshot remove lasts about 2 mins with lot of "...missing *-delta.vmdk" in ESX's /var/log/messages. There is no difference with Windows or Linux NFS server - backed vmdk looks fine but I don't know is this only warning or something to worry about. It's same story with all my ESXs.

Feb 10, 2009 1:59 PM lamw  says: in response to: cybersayo

Usually when you get those warnings, it means it was not able to find the source VMDK for whatever reason. I know some user's have had issues in the past where their VMDK(s) were stored in other directories or if they had multiple VMDK(s), earlier versions of the script did not handle that use case.

The latest script should be validating that certain VMDK(s) exists prior to trying to take a backup, though if you've manually edited the .VMX file, there could be some inconsistencies in the .vmx itself. You can always try the script with a -x flag which gives detail verbosity of what's happening while the script execute and see if you can anything that's off. If it works for SAN to Local, then it should also work for NFS unless you some miss-configurations on your NFS Server (you can always manually take a snapshot and manually run vmkfstools copy manually to make sure it's working with your NFS Server)

(e.g.)

sh -x ghettoVCB.sh my_back_vm_list.txt


If you're still not sure, you can direct that output to a file and attach to your reply and I can try to take a look.

Feb 11, 2009 12:41 AM cybersayo  says: in response to: lamw

Thanks, I'll try.

Another thing; currently I do three kind of backups from san: daily to local hard drive (raid1), dayly to nfs (raid1) and weekly to tape. Since there is not enough space on local hard drives to do rotation, ghetto returns error every second day (and delete files then, so backup is ok tommorow). Rotation count is 0.

What can I do to make this backup daily?

Feb 11, 2009 8:46 AM lamw  says: in response to: cybersayo

Well nothing is stopping the script do run daily backups, that is up to the end user's and the setup of their cron schedule. If you're looking for more elaborate backup processes such as transfer from SAN to local, then to NFS, etc, etc. You'll need to script that process, this script is intended to help provide a backup solution for your VM(s), it's left open for any modifications/specific requirements one may have for their environment.

=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Feb 12, 2009 1:07 PM ddigioia  says: in response to: lamw

William,

Thanks for sharing your great scripts and knowledge.

Everyone,

Thanks for the great forum. I've learned a lot here.

We are using ESXi with an NFS datastore on Openfiler 2.3.

I've modified William's script to make ESXi "thin" disk format backups, as it was not too easy to add backups or clones of VMs back to the VM inventory when they were in 2gbsparse disk format, and I did not want to lose the disk space "thick" backups would have required.

The backups and restore/clone seem to work fine with thin format, but I feel it seems too easy. Am I missing something?

Is there any reason why I should not use William's ghettoVCB.sh script to do thin backups rather than thick or 2gbsparse?

(I realize the 2gbsparse format is more portable to other filesystems, other versions of VMware, etc.)

Thanks,

-David

Feb 13, 2009 5:54 AM jaxislnad  says:

First off, this is really some great work. Thank you for posting this.

But, unfortunately I am having some issues. I downloaded the file yesterday 2-12-2009, onto my ubuntu machine. I opened it with gedit and it had the ^M throughout the file. I dont know if Ubuntu did that or the file up there has them but either way I fixed it with dostounix. So I set it up and ran it on a VM with 1 vmdk file and it worked like a charm. HDD to HDD on a 10 GB VM takes consistently less than 5 mins, which is great.

My next step was I added a vmdk with the VIC, I used the VM and added a partition and put files on the new hard drive, works fine. When I run the backup it still only backups the main HDD, or the first vmdk. I checked the vmx file and they are both set to "true". I checked your script and it is grep -i. So I am totally at a loss at what could be preventing the script from backing up the second vmdk.

Now my next question would be I have 4 HDD in the server. Disk 1 has a vmdk, Disk 2 has a vmdk, both for the same VM. Can I backup Disk 1 vmdk to Disk 3, and Disk 2 vmdk to Disk 4. All 4 drives are 1 TB drives. So both vmdk files are more than 1 TB which is the size of the other disk so I need each vmdk to go to a seperate location on the same server. I hope this makes sense if not let me know.

Also my last question is how does this backup run while the machine is on, can I still get a restorable copy of my files if I do the backup when the machine is powered on? Is it best to power down then do the backup?


********EDIT********02-13-2009 09:12
The 2nd vmdk that doesnt get backed up is stored on another drive, I added a 3rd disk to the same directory as the vmx and it backs up both, so for some reason it cannot find the 2nd vmdk on another drive.
Im also getting this when it tries to clone the disk:
DiskLib_Check() failed for source disk The system cannot find the file specified (25).

********EDIT********02-13-2009 09:45
I have attached the portion of my file that I believe to show the issue. As you can see the _2.vmdk and regular vmdk that are in the same directory as the vmx file backup fine. These files are in /vmfs/volumes/Main

Now the _1.vmdk is on /vmfs/volumes/Third, which it calls out by the long string of numbers which also match the string of numbers in the vmx file.

What looks wrong to me is it is starting out in the /Main directory then tries to go find it but cant. I could use some guidance on this one.

+ echo ################## Starting backup for MyVM ... #####################
+ OLD_IFS=

+ IFS=:
+ VMDK=MyVM_2.vmdk
+ 0 -eq 1
+ vmkfstools -i /vmfs/volumes/Main/MyVM/MyVM_2.vmdk /vmfs/volumes/Secondary/MyVMbkup/MyVM/MyVM-2009-02-13/MyVM_2.vmdk
+ VMDK=/vmfs/volumes/4896efad-39367fad-4058-00151762f7d0/MyVM/MyVM_1.vmdk
+ 0 -eq 1
+ vmkfstools -i /vmfs/volumes/Main/MyVM//vmfs/volumes/4896efad-39367fad-4058-00151762f7d0/MyVM/MyVM_1.vmdk /vmfs/volumes/Secondary/MyVMbkup/MyVM/MyVM-2009-02-13//vmfs/volumes/4896efad-39367fad-4058-00151762f7d0/MyVM/MyVM_1.vmdk
DiskLib_Check() failed for source disk The system cannot find the file specified (25).
+ VMDK=MyVM.vmdk
+ 0 -eq 1
+ vmkfstools -i /vmfs/volumes/Main/MyVM/MyVM.vmdk /vmfs/volumes/Secondary/MyVMbkup/MyVM/MyVM-2009-02-13/MyVM.vmdk
+ IFS=

I hope you can help me out, I do appreciate you taking a look.

Thanks again for the great work.

-Ryan

Feb 13, 2009 8:27 AM lamw  says: in response to: jaxislnad

I noticed another user had a similar issue too, I may have to look at the case when the VMDK(s) are stored in another datastore other than the root VM directory. I'm curious when it tries to backup the other drives, is the location correct? In terms of how it's able to backup VM(s) while it's still running is with a snapshot. When you take a snapshot, the main VMDK is changed to readonly and a new delta file is created which will contain all changes after the snapshot has been taken. This then releases a file lock on the main disk which allows you to backup the disk. Once the snapshot has been removed (committed), all changes will merge back with the primary disk. Then on the next backup, it'll do the same and those changes will be captured.

I'll take a look at the issue sometime next week ... need to spend sometime with the gf this weekend =)


=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Feb 13, 2009 8:31 AM jaxislnad  says: in response to: lamw

The location is correct that it comes up with. It matches the same string thats in the vmx file so it almost knows its there it just cannot copy it.

Also is there a way to backup one vmdk to one location and a second vmdk to another, even though they are in the same VM?

I thought it was using the snapshot feature, but I wasnt sure. I appreciate the update, and have a good weekend! :-)

Feb 13, 2009 8:37 AM lamw  says: in response to: jaxislnad

hm ... that's interesting. If the snapshot was taken successfully, then both those disks should be unlocked. You can always manually do what the script is doing to just verify that it should work. In terms of your second question, you would need to modify the script to duplicate it to two destinations. You can always just re-run the script with a second destination as a work around.


=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Feb 14, 2009 2:01 PM jsmithsd  says: in response to: lamw

Has anybody come up with a reliable method of monitoring this script for success/failure? Here's an idea off the top of my head for Windows users who use Kaseya/LPI for monitoring. I wouldn't have the expertise to write something like this but maybe somebody else would see value in this.

  • Have ghettoVCB produce a log file. Does it already do this?
  • Modify the .bat file in your scheduled task to download the log file to the Windows machine via Plink.

From there you could:
  • Launch a .vbs that would parse the log and write custom events to the event viewer. Monitor events with your monitoring tool of choice.
  • Parse the log file directly if your monitoring tools are capable of this (Kaseya is).

Feb 16, 2009 8:01 AM jaxislnad  says: in response to: lamw

How do I run it with 2 destinations, wont it copy the first vmdk each time. So I would only end up with one of the 2 vmdks in 2 places?

Im not sure where in the script I should try manually.

Thanks for the help.

Feb 16, 2009 9:49 AM lamw  says: in response to: jaxislnad

You'll have to add that logic into the script if you're looking to split your destination copy.


=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Feb 17, 2009 2:16 AM JoeyDE  says:

Many thanks for your great script!!

To everyone:

Everything works great except the output to a log file. I have a scheduled task on a windows 2003 server machine to run batch file which executes ghettoVCB.sh via plink.exe. Thanks to Raj Perumal for his blog guide.

The command looks like this:
plink.exe root@192.168.100.200 -pw mypassword "nohup ./vmfs/volumes/vmfs-storage/ghettoVCB.sh /vmfs/volumes/vmfs-storage/vmlist > /vmfs/volumes/vmfs-storage/backuplog.txt &"

After a successful backup the backuplog.txt contains not a single line and the file size is 0 btyes.

When I execute the command in a putty session the output to the backuplog.txt works great.

Any ideas whats wrong?

Feb 18, 2009 9:59 AM cyberfire  says: in response to: JoeyDE

I have a problem.....
It all works find but VM_BACKUP_ROTATION_COUNT=1 does not do any thing.
I have now
.15_SpiceWorks-2009-02-17
.15_SpiceWorks-2009-02-16
as backups and if I run it now I get
.15_SpiceWorks-2009-02-18

any ideas?

Feb 18, 2009 10:04 AM lamw  says: in response to: cyberfire

Looks like something was modified in the script because the rotation count is kept track by a special extension "--X" ... I don't see that in your output, did you change something in the script?

=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Feb 18, 2009 10:11 AM cyberfire  says: in response to: lamw

Config part
VM_BACKUP_VOLUME=/vmfs/volumes/489326a8-7adbcdf8-a9f4-00188bf6e6f5

POWER_VM_DOWN_BEFORE_BACKUP=0

Code part
LIST_BACKUPS=$(ls -Atr ${BACKUP_DIR_PATH})
This is due to that my VM names are .15_Name_XXXX

Feb 18, 2009 10:13 AM cyberfire  says: in response to: cyberfire

BTW, wnat can I comment out in order to run all but the actual cloning of the folder?

Feb 18, 2009 10:19 AM cyberfire  says: in response to: cyberfire

OK, I recopied the original code.
this is my output.

~ # /ghettoVCB.sh /backup_vms

                                1. Taking backup snapshot for .15_SpiceWorks ... ################
Destination disk format: VMFS thick
Cloning disk '/vmfs/volumes/Virtual_OS_V2/SpiceWorks/XP_Base_1.vmdk'...
Clone: 100% done.
Removing snapshot from .15_SpiceWorks ...
bash: /vmfs/volumes/489326a8-7adbcdf8-a9f4-00188bf6e6f5/.15_SpiceWorks/.15_SpiceWorks-2009-02-17: bad number
/ghettoVCB.sh: /ghettoVCB.sh: 322: Syntax error: /vmfs/volumes/489326a8-7adbcdf8-a9f4-00188bf6e6f5/.15_SpiceWorks/.15_SpiceWorks-2009-02-17+1

Feb 18, 2009 10:21 AM lamw  says: in response to: cyberfire

Ah, then I think you can just remove the -A param, as that ignores "." Any reason why you're naming convention is in that form? I would probably change that since that usually interpreted as hidden directories (just a thought).


=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Feb 18, 2009 10:24 AM lamw  says: in response to: cyberfire

I'm not sure what you mean by actual cloning of the folder? If you're asking about the rotation count, you'll need to set that = 1, it does not make sense to set it to 0.

You should give the script a read through, the logic should not be too difficult to follow and you're welcome to ask further questions. If you can manually run through this process, then the script will make more sense.


=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Feb 18, 2009 10:26 AM lamw  says: in response to: cyberfire

Again, this is probably due to your naming convention, so it's unable to rename the directory since it's looking for a "--X' extension. Please take a look at the previous reply for a fix or modify the way you VM directory.


=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Feb 18, 2009 10:31 AM cyberfire  says: in response to: lamw

Just changed the name of the VM. No .15_ as prefix.
Running the code.....
Lets see.

Feb 18, 2009 10:47 AM cyberfire  says: in response to: cyberfire

What I ment about cloning the folder... was that I would like to coment the part that actualy does the backup until I get the rotation count working

BTW, VM_BACKUP_DIR_NAMING_CONVENTION="$(date +%F)" is what is set for the naming.

Feb 18, 2009 10:54 AM cyberfire  says: in response to: cyberfire

is Date: 11/01/2008 the last version of the file? I see updates later than that

Feb 18, 2009 10:57 AM lamw  says: in response to: cyberfire

That is actually the date I started the project. The latest script will always be available in the download section

To your other comemnt, that is the naming convention that is appended to the backup directory, this can be anything but I thought having the date as part of the backup directory might be useful. This can be changed to any string you would like.


=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Feb 18, 2009 11:15 AM cyberfire  says: in response to: lamw

mmmm
now its creating
SpiceWorks-2009-02-18--1
I will rename to 02-17--1 and run again.

Feb 18, 2009 12:11 PM cyberfire  says: in response to: cyberfire

YES!!!!!!!!!!!!!!!!!!!!!!
Thanks!!!!!!!!
Now I need to just find a way to get the files of the ESXi server.

Regards.
George.

Feb 18, 2009 12:13 PM lamw  says: in response to: cyberfire

Glad to hear. Try setting up an NFS Server, it's pretty simple and this will allow you to get the VM(s) off the host to other backup or tape storage.


=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Feb 19, 2009 7:08 AM ScottChapman  says: in response to: lamw

When I am running the script I am getting the following error:
DiskLib_Check() failed for source disk The system cannot find the file specified (25).

I turned on tracing on the script and discovered it is happening as a result of this command:
vmkfstools -i /vmfs/volumes/datastore2/OpenFiler//vmfs/volumes/4947b0ac-5b9a4e28-9b21-0011092a9380/OpenFiler/OpenFiler_2.vmdk /vmfs/volumes/Disk1/vmbackups/OpenFiler/OpenFiler-2009-02-19//vmfs/volumes/4947b0ac-5b9a4e28-9b21-0011092a9380/OpenFiler/OpenFiler_2.vmdk

Any ideas what is causing this?

Feb 19, 2009 7:12 AM santalaus  says: in response to: ScottChapman

Realy nice Work, but I found an Izzue ;)
When you have multiple vmdks on different datastores in one vmx thd filename contains the fullpath to the vmdk
So the Script could not save this vmdk because it is not in the VMX_DIR Path.

I hope you understand this.

Feb 19, 2009 7:16 AM jaxislnad  says: in response to: ScottChapman

Same issue Im having. Im trying to modify the script but no success so far.

Feb 19, 2009 7:17 AM ScottChapman  says: in response to: santalaus

Nope, sorry you lost me.

I do have a couple of different VMs on different datastores, but I got this error when I tried to back up just one of them.

Are you saying that all my VMs need to be on the same datastore for the script to work?

Or am I just not understanding this...

Feb 19, 2009 7:20 AM jaxislnad  says: in response to: ScottChapman

My situation is my VM's have 2 vmdk files. They are both on different datastores. When I run the script only the vmdk that is on the same datastore as the vmx gets backed up. The vmdk on the other datastore does not and it gives me the same error.

Feb 19, 2009 7:25 AM ScottChapman  says: in response to: jaxislnad

Oh wait, I think I (might) get it!

So, yes the VM I am backing up also has a couple of disks which do reside on different data store.

Fortunately I do not actually need to back those up (they are storage for openfiler which I am spanning across a software RAID).

I really just need to backup the main disk associated with the VM.

So I am guessing I can just ignore this error.

If you do happen to extend the script to support this, you might consider allowing the user to specify which disks to back up and which to ignore...

Feb 19, 2009 7:27 AM santalaus  says: in response to: jaxislnad

Jepp, this is because the filename of the vmdk on the diffrent Datastore contains the fullPath.

scsi0:0.fileName = "Fileserver.vmdk"
scsi0:1.filename = "/vmfs/volumes/4982de6f-6ea7343b-c3c9-00221986180a/Fileserver/Fileserver_1.vmdk"

So you could not easily use the VMDK Name as source or target for copy.
You have to check first the path an the make 2 arrys VMDKS and VMDKFULLPATH

Feb 19, 2009 8:24 AM lamw  says: in response to: santalaus

All, this has been acknowledged by a few as an issue, the current workaround is to only backup VM(s) that reside on the same datastore.

I've been occupied with other projects recently and when I get some time I'll take a look and provide a fix. If anyone has implemented a a working solution, feel free to post or send me a PM.


=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Feb 19, 2009 12:53 PM docsys  says: in response to: lamw

Anyone having issues downloading the ghettoVCB.sh from this page? I get it and it doesn't run. It shows a "Bad Interpreter" File Not Found error. It seems to be corrupt or have some control characters in it (^M). I can't see them in vim or vi and I only downloaded to a windows xp system, didnt edit it at all on windows.

It seems the ghettoVCB.sh on http://engineering.ucsb.edu/~duonglt/vmware/ and here on VMware site are different revisions, but the one from the ucsb site is working OK.

TIA.

Feb 19, 2009 1:01 PM lamw  says: in response to: docsys

Sorry about that, I must have forgotten to update the engineering account. They should be the same, I've uploaded the current version and can you try the download on the VMTN doc again?


=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Feb 19, 2009 1:18 PM ScottChapman  says: in response to: lamw

If you do have a problem with the trailing "^M" line termination you can do the following to get a good version of the script:

sed 's/.$//g' ghettoVCB.sh > ghettoVCBFixed.sh

Just make sure to turn the execution bit on...

Feb 19, 2009 1:36 PM docsys  says: in response to: ScottChapman

Alright it seems the file from the vmware site still has the ^M somehow, tried the sed command and it was OK.
The file from the ucsb site is updated and Good still.
Thanks.

Feb 20, 2009 10:19 AM Gregori  says:

How to change the ghettoVCB.sh to delete the old backup before execute new backup?

Thanks.

Feb 20, 2009 12:45 PM lamw  says:

I'm looking at the issue and basically it boils down to the SOURCE and DESTINATION path, the VMDKS array will contain either the local VMDK disk names with respect to the VM's folder which you'll need to append the VMX_PATH variable or if the disk is stored in another datastore, it'll contain the full path to the VMDK. A quick fix would to check the variable that goes through each for loop iteration to see if it starts with /vmfs/volumes, if so then you know it's a disk that's located in another datastore and setup the variable accordlying. Running through some print statements, I noticed an issue with the DESTINATION which also needs similar logic.

Though right now the issue from my basic test is the following: I have one Windows VM with 1 disk call it Quentin.vmdk which is the unique descriptor describing one of Quentin's disk that is stored in Datastore A. I know add a second disk and store i in Datastore B, I commit the changes and then look at the disk name from both the VIC and on the filesystem and what do I notice?

The name of the .vmdk is the same as disk 1, this will be an issue when backing up the disks to your destination as these filenames are no unique and will most likely over write one another. I then added a third disk two the VM and stored it in Datastore B and the .vmdk now has a unique name appended with _1.

The observation, at least on ESX w/SC (haven't tested on ESXi) if you have a VM with 1 disk and you add another and you're going to store it on another datastore the name will not be unique as it'll default to the VM's display name. This will cause a problem when backing up ... I'm trying to think of what changes would need to occur but it seems that it'll most likely requiring the modification of the .vmdk name's to the destination which may or may not be something end users want.

I'm still pondering over the issue right now over lunch ... if anyone has any suggestions I'm open, but this may be a feature that may not be supported due to the way the disk's are not uniquely labeled across datastores.


=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Feb 20, 2009 2:47 PM ScottChapman  says: in response to: lamw

I think what would make sense would be to create folders for the datastores names and put the files there.

This would also make it a lot easier to restore since one can easily tell what when where...

Make sense?

Feb 20, 2009 2:52 PM ScottChapman  says: in response to: ScottChapman

Or more technically, retain the path relative to /vmfs/volumes

Feb 20, 2009 2:55 PM lamw  says: in response to: ScottChapman

Unfortunately that does nothing for the current situation other than additional directories and a disconnect between what's listed in the .vmx file and the additional work a user would have to remove the disk reference and re-map on a backup/recovery. The solution would be too specific as some user's may want to mount the backup datastore directory whereas others would want to manually copy from the recovery datastore but not directly register the VM(s) from backup.

The more I think about this, the only decent solution is to automatically rename and update the backup VMDK(s) as they're being backed up and set them to be referenced locally within the VM's directory. This then allows a user to either mount the VM directly if he/she would need to recovery or restore from backup and have all VMDK(s) referenced properly. The only difference with VM(s) that were initially stored across multiple datastores will not be preserved (the ability to recovery may be more important than how the disks were initially stored). For further use cases, that'll be something end-users will need to customize for their enviornment.


=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Feb 20, 2009 2:58 PM lamw  says: in response to: ScottChapman

Even if you retain the path ... what's to say a user can't bring up the original datastores, they're recovering to another ESX/ESXi host with another datastore or local. This really goes hand in hand with recovery which is going to be unique for each environment. This script will not be able to handle all those use cases, hence it's up to the end users to customize as needed for their enviornment. We're trying to generalize the process so that such customization is available if necessary.


=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Feb 20, 2009 3:34 PM lamw  says:

How about the following as a compromise:

To preserve the functionality and familiarity of the script with user's that have already implemented a recovery/restore solution, I will continue to backup all VMDK(s) that are stored locally with the VM to the destination folder as you're aware of. The added fix would then support VMDK(s) that are not stored in the same datastore as the VM but in backing those VMDK(s) up to take into consideration of non-unique VMDK names provided by VMware, I would create an additional directory which will be the unique UUID of the original VMDK destination and then it would be up to the end user's to provide a solution on recovery/restoration.

This will preserve the original .vmx file as I have currently in the script and if a user chooses to restore a VM to it's initial configuration, the only added step would be to vmkfstools copy any VMDK(s) that were not stored with the VM to it's correct datastore. A user would also be able to directly mount the backup datastore but then would be required to manually update the location of the VMDK(s) that were not stored with the original VM ( this would have to be done even if the current script supported VMDK(s) across multiple datastores as your recovery .vmx file will not contain the correct paths )

Example:


  • DS1/VM_TEST
    • DS1/VM_TEST.vmdk
    • DS1/VM_TEST_1.vmdk
  • DS2/VM_TEST/VM_TEST.vmdk

Backup would be:

  • VM_TEST
    • VM_TEST.vmdk
    • VM_TEST_1.vmdk
    • DS2/VM_TEST.vmdk

I think this makes the most sense and preserves the original script's behavior and I can not stress this enough, that it's the responsibility of the end user's to design/automate a process that fits their operating environment. This script is to aide in backing up your VM(s) but as you know there will be different sets of requirements for environment and the specifics will need to be customized by the end users.


=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Feb 22, 2009 8:43 PM lamw  says:

Script has been updated, please let me for those that have multiple VMDK(s) across multiple datastores if this works. Thanks


=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Feb 23, 2009 4:12 AM santalaus  says: in response to: lamw

It seemed to work good.
Now I have an backup of the vmdk which where on the second datastore

Feb 25, 2009 4:09 AM bpsmanagement  says: in response to: lamw

First of all.. thank you William and all others who have contributed to this. The script is sweet. Much faster than other scripts that use other backup methods. I am however getting speeds that are unusually slow for file transfer on an internal LAN.
I am running ESXi embedded on my host and I have a Allegro NFS Demo running on a physical server 2008 box (attempted to configure Unix on server 2008 using native Windows tools with no luck; authentication issues). The export is located on my local server 2008 storage. It's a 1.5TB Barracuda. Both boxes have Intel Gigabit Nics and are connected VIA a Linksys Gigabit switch. I tested my transfer speeds using wireshark at 15.8MBit/sec while running this script. I tested windows transfer from my guest VM to my Windows 2008 server at ~320MB/s. I know it's not my network configuration because of the results I get with Windows. Is allegro just slow as mollases? Server 2008 and Allegro Hate eachother? I know Server 2008 hates Unix (unless it's solaris 10), but thats another story.. What numbers should we expect/shoot for? What are other seeing backing up to NFS storage?

Feeling down? Need a good laugh? 100GB of data split between two VM's..

Start time: Wed Feb 25 00:16:28 UTC 2009
End time: Wed Feb 25 11:56:51 UTC 2009
Duration : 700.38 Minutes

Completed backing up specified Virtual Machines!

Feb 25, 2009 11:08 AM cyberfire  says: in response to: bpsmanagement

Quick question.
How do I restore form the Backup?
I currently store the Backup on the same Datastore.
Do I just add to Inventory and run from there? or do I move the files to the original Folder?
What happens with multiple vmdks?

Feb 25, 2009 11:55 AM cyberfire  says: in response to: cyberfire

mmm
I just did a backup of a server that has its OS on one DS and the data on a second DS.
The only vmdk that was backedup was the data disk. the the actual OS vmdk was not.

Feb 25, 2009 11:58 AM lamw  says: in response to: cyberfire

Please make sure you're using the latest version.

Restore can be either direct mount from your backup datastore and just register or replicate from your backup datastore using vmkfstools. I would recommend that latter, that way you don't use your backup for use but replicate it to the host for recovery/restore. The recovery/restoration process is something that is more manual and can be scripted but the requirement will be based around your requirements and should be implemented based on that.


=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Feb 25, 2009 12:41 PM bpsmanagement  says: in response to: bpsmanagement

no comment?

Feb 25, 2009 12:46 PM lamw  says: in response to: bpsmanagement

not really, I'm not familiar with NFS off of Windows, there are many configurations that could cause the speeds you're seeing. If you look in the forums, you'll find various comments on good/bad speeds. If you're running an NFS Server on VM, you may see speed decreases than on a physical. Your export options can also affect the speeds (e.g. sync vs async). There have been many individuals getting very good speeds and many that get less than up to par/expected. Your best bet is to ask the community for their configurations but can also be due to the hardware you're using... unfortunately when you're discussing performance, ymmv depending on your setup.

The script has nothing to do with your performance if that's what you're after.

=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Feb 27, 2009 12:23 AM ibhp  says: in response to: lamw

hello all
I am backing up about 4 different vm-images each night with the script. But somethimes the snapshots are not removed after backing up and so the next time the backup of this vm will fail.

  • would it be possible to backup a vm also if a snapshot exists? What's the reason you check for existing snapshots?
  • How is it possible to send a mail after each backup with the content of the ghettovcb-script?

Thank you,

ibhp

Feb 27, 2009 8:12 AM lamw  says: in response to: ibhp

VM(s) w/Snapshots are not supported because snapshots in general should not be kept for long periods of time. They're meant to be used for quick testing and all changes should be merged back into the main VMDK as soon as possible. If you're looking to send email, a quick search online you'll find many solutions available including using default utilities like (mail or mutt) if you're on a UNIX/Linux system.


=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Feb 28, 2009 12:38 PM ibhp  says: in response to: lamw

Thank you for your response. But somethimes the snapshots created by ghettovcb are not removed correctly and so the next backups are not performed anymore.

Is there a way to remove every snapshot automatically (in the script) before the new backups are performed? That would ensure that the backups run even if there are "old" snapshots.

Feb 28, 2009 1:33 PM lamw  says: in response to: ibhp

Interesting, I haven't heard of any issues of snapshots not being removed. Are there any previous snapshots on the VM when running the backup? If so, that may cause some issues.

Currently with the method of using the vimsh there is not an option to remove all snapshots, you also don't want to automate that process of committing older snapshots without checking the state of those snapshots. Committing snapshots should be a manual process to ensure you don't revert or make any changes to the system that the Application/System owner is not aware of. Again, the script enforces the rule that if it finds any prior snapshots it will not continue. You should not be using snapshots for long durations and should commit the changes as soon as possible especially if you're looking to backup the VM(s).


=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Feb 28, 2009 1:45 PM ibhp  says: in response to: lamw

I have a directory with my virtual disc and a snapshot created from ghettoVCB (not removed after the backup). When I try to:
${VMWARE_CMD} vmsvc/snapshot.remove ${VM_ID}

then I get a segmentation fault. So that seems to be the problem the snapshots are not correctly removed after the script terminates.

Any idea what could be the reason?

Mar 2, 2009 1:42 AM shechtl  says: in response to: ibhp

Hello lamw,

since your script is running now for a few weeks, I got two days ago this error:

on esxi1:

Clone: 100% done.
Powering back on ps1
bash: /vmfs/volumes/iscsi1backupdsa1/backups//ps1/ps1-2009-02-26: bad number
/vmfs/volumes/iso/backup/ghettoVCB-enhance-iscsi1.sh: /vmfs/volumes/iso/backup/ghettoVCB-enhance-iscsi1.sh: 323: Syntax error: /vmfs/volumes/iscsi1backupdsa1/backups//ps1/ps1-2009-02-26+1

on esxi2:

Clone: 100% done.
Powering back on exchange3
bash: /vmfs/volumes/iscsi1backupdsa1/backups//exchange3/exchange3-2009-02-26: bad number
/vmfs/volumes/iso/backup/ghettoVCB-enhance-iscsi1.sh: /vmfs/volumes/iso/backup/ghettoVCB-enhance-iscsi1.sh: 323: Syntax error: /vmfs/volumes/iscsi1backupdsa1/backups//exchange3/exchange3-2009-02-26+1
Plink error: Remote command failed
(Exit code 2)

I can see that your script was not removing the backup files: Backup rotation is set to: 2 and there are 3 directories now in the folder.

It looks like that only the last vm of my machinelist had this problem. I did not change anything in your script an machinelist since weeks.

Hope you have a answer.

Mar 2, 2009 3:50 AM hremul  says: in response to: shechtl

Sorry, but where i can't find ghettoVCB-enhance.sh script?

Mar 2, 2009 8:34 AM lamw  says: in response to: shechtl

Please download the current version of the script and manually try again and see if you run into the same issues, if not, then it could be some issues when remoting in with plink.


=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Mar 2, 2009 8:35 AM lamw  says: in response to: hremul

The current download is the most up to date version of the script, please look over the documentation if you have further questions.

=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Mar 3, 2009 12:18 PM shechtl  says: in response to: lamw

Hello lamw

I updated to the latest version, but I got the same problem.
See:

                                    1. Starting backup for dc2 ... #####################
Failed to clone disk : The file already exists (39).
Destination disk format: VMFS thick
Cloning disk '/vmfs/volumes/iscsi2dsa4/dc2/dc2.vmdk'...
Powering back on dc2
bash: /vmfs/volumes/iscsi1backupdsa1/backups/dc2/dc2-2009-03-02: bad number
/vmfs/volumes/iso/backup/ghettoVCB-iscsi1.sh: /vmfs/volumes/iso/backup/ghettoVCB-iscsi1.sh: 337: Syntax error: /vmfs/volumes/iscsi1backupdsa1/backups/dc2/dc2-2009-03-02+1

I am sure that i deleted all backuped subfolders which I dont needed so there should be not more then two subfolders be in. Rotation is set to 2

I started your script direct per putty and only the machine dc2 and I got the complete same error.
In the backup folder there are only to subfolders dc2-2009-02-28--2 and dc2-2009-03-01--1

Any idea what this problem could be ?

Mar 3, 2009 12:35 PM lamw  says: in response to: shechtl

I think you might have had some bad backups that were not rotated out properly which is causing some issues. Can you please move any previous backups whether they're good/bad out of that directory or purge them completely. Try a fresh backup


=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Mar 4, 2009 12:01 AM shechtl  says: in response to: lamw

I deleted the complete folder with the backups and tried 3 backups only with this problematic machnine and they were running. So I delted also the other folders with
problematic machine. I have to wait now for a few days to see if everything is working again.

Mar 4, 2009 9:27 AM Yulman  says: in response to: jsmithsd

Just like you I wanted to log to a file.

This is what I came up with

http://communities.vmware.com/docs/DOC-9653

I did this at my own risk...I'm not a shell programmer so this should be tested before used in a production environment.

Hope this helps

Mar 4, 2009 9:34 AM lamw  says: in response to: Yulman

Thanks for the post, the logging feature will be available in an upcoming release. Stay tuned


=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Mar 5, 2009 8:21 PM hremul  says: in response to: lamw

First of all, i wish to thank for great script.

I have one suggestion. It is possible to add functionality to backup power off machines which have snapshots?
In some kind applications (like development) night downtime does not matter. But snapshots does. Thank you.

Mar 5, 2009 8:25 PM lamw  says: in response to: hremul

Hi hremul,

As mentioned in the previous posts, snapshots should not be kept for long durations. They can grow and left uncheck could cause issues on your datastores being filled up. If you're looking to backup VM(s) that have snapshots, best practice is to commit those changes and merge the delta files back to the VM then backup the virtual machine. There some complexity with the way the script handles removing snapshots if you're going to try to backup a VM with snapshots and partially it's a limitation with the vimsh and keeping track of the snapshots. It's best that you don't backup VM(s) with snapshots, but if you do, you'll need to make modifications to the script and that is an unsupported feature.


=========================================================================
--William Lam
VMwae vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Mar 10, 2009 2:42 AM jbrandligt  says:

Hi lamw,

Thanks for a great script! I have one question though. Is it possible to change the script in such way that it can copy the backups to a datastore on a remote esxi host using something like scp?

Mar 10, 2009 10:07 PM lamw  says: in response to: jbrandligt

You could append some scp commands and using paired SSH keys to remotely copy the backups to external storage or another host. There have been some threads regarding the implementation of scp on the unsupported console and the performance/speed in copying large files. You might want to take a look at a free tool by Veeam fastscp, I have not used it personally but I've heard many good things about their product. That might be a better approach if you need to copy files in/out of ESXi.

You also have the option to leverage vifs.pl from the VI Perl Toolkit default utilities, but again these are customizations that'll need to be added to your custom version of the script.


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

Mar 11, 2009 4:24 AM jbrandligt  says: in response to: lamw

Thanks for your reply. Fastscp is a nice tool, but it is only a file copy-tool. It does not handle running vm's because it does not take snapshots.

There is also veeam-backup 3.0 now with support for esxi. The draw back of this tool is that it does not backup to a target esxi host, only local storage or san or iscsi storage. Veeam-backup makes use of the console of esx to make incremental backups of vm's and esxi of course does not have an esx-like console, so that is why it cannot use esxi as a target for its backups.

And then there is also an other tool, vm-explorer, which does do backups to other esxi hosts, but this tool does not run as a service. It is intended to be run as a user only.... For me that is not an option for a backup tool. I could run the tool with a service wrapper, to run it as a service, but i cannot test this scenario with the trial license because there is this annoying popup window, you have to click away every time you start the tool.

So it looks like i have to customize your script. Wish me luck ;)

Jeroen

Mar 25, 2009 8:36 AM dotcom  says: in response to: lamw

Compressing the backup is more than a good suggestion... here is why...

The VM filesystem is stored as a sparse file. When you copy that data to the network storage, you are un-sparsing it, unless you encapsulate the data into a compressed file, using compression that knows how to properly restore the sparse data.

So my 20g vm, that is really only using 270m of disk space in it's sparsely allocated file, will grow instantly to 20g using your backup system. If you restore it, or use the backup to clone in, you are no longer sparse... Instead you suddenly have a big file full of zeros. And those zeros take up network bandwidth.

The backup is not accurate if it fails to preserve the state of the stored data, and this includes the sparseness.

Sparse files are strange beasts, and programs like cp do not handle them correctly most of the time, so the moment you "forget" to handle the file correctly, it inflates to a non-sparse state. In a sparce file, an unallocated block of 0's is not stored on disk, rather the index points to null, which represents an unallocated data block assumed to be zeros. If you cat the file, the filesystem produces those 0's, but they don't really exist on disk. If you copy the file without an awareness of the sparse allocation, you end up with a huge file full of unneeded zeros... and this takes up network bandwidth as well as disk io. When you unsparse a file, there is a heavy performance cost and storage cost.

While some might say "use a compressed filesystem on the NFS server"... That does not deal with the whole issue. On a compressed filesystem you are still storing unneeded 0's, and when you move the file to a non-compressed filesystem, all that space is consumed, along with the disk io needed to write it all out. So you go from a vm that takes twenty seconds to move from one server to another using vmware's tools, to one that takes 3 hours to move. And if you depend on your network bandwidth to do work, now you have a whole lot less of it... not to mention the time lost. I in a day can move hundreds of vm's that only take 20 seconds to transit across the network... but that number falls to 8 when they take 3 hours each.

If you have 3 vm's to back up, it's a minor issue, especially if you do the backup when you sleep. But if you store the backup with the intent to clone it during work hours, it's is a big hit on productivity.

The backups need to preserve the sparseness, a sparse aware compression tool needs to be used. There are not a lot of compression tools on your ESXi system, there is one. So the suggestion that there are many options is wrong. And the suggestion that this is not an issue is misguided. And using a compressed filesystem to store the data on is also not addressing the main issue.

If you don't know what a sparse file is, you can read about it at:
http://administratosphere.wordpress.com/2008/05/23/sparse-files-what-why-and-how/

This does need to be addressed for this tool to be useful the the larger audience.

It is a great tool by the way, don't let my sparse rant take away from the fact that this tool is wonderful. My point is that compression in the utility is not as optional as you would like to think. Compression and correct sparse handling are critical.

Apr 1, 2009 10:47 PM mylesw  says: in response to: lamw

Hi there and thank you for a wonderful script and contribution to the community!

I have two ESXi host machines that are colocated at a data center. There is a 3rd Linux backup computer with NFS on it, and I want to be able to backup the VMs running on these hosts on a regular basis. I have a 'public' WAN network (the VLAN provided by the data center that is public to the world) and a private LAN that is not private. All machines have dual NICs - one for the public WAN and one for the private LAN.

I would like to have it so that my NFS server runs the backups of all VMs using the LAN for this. I'm also sensitive to security concerns, particularly brute force attacks on SSH which are showing up routinely. As a result, all public servers on the WAN have their SSH ports changed from default ports to non-default ports, and Fail2Ban scripts installed to detect brute force login attacks on these boxes. This has been very successful so far.

I cannot install a firewall in this environment because the cost of doing so is prohibitive since I have about 20 WAN IP addresses on the VLAN. I may do this in the future when I work out how to set this up with pfSense but for now, its prohibitive as an option. Consequently every server that is WAN facing has their own local IPTables firewalls in place.

I understand from reading the posts and documentation on the ghettoVCB scripts that it appears to run from within a ESXi host which is made available through a SSH port enable on the box. As much as I would like to be able to do this, its not possible due to security concerns. I can't have default port 22 open like this. So is there a way that I can install it on my NFS server for the LAN only, and not have any of the ESXi boxes set with SSH at all?

Or if not, is there anyway to apply some 'best practice' security approach to enabling SSH on the ESXi hosts that allow for the use of non-default ports, and some form of script that could be run to thwart brute force attacks on the boxes?

Thanks again for your wonderful work, and I look forward to any comments or suggestions.

Myles

Apr 3, 2009 3:43 PM lamw  says: in response to: mylesw

Hi Myles,

Thanks for the comments.

I wanted to get a few things cleared up and this may help you decide on how you go forward with implementing a backup solution. ghettoVCB can run on both ESX/ESXi as you know and specifically on ESXi, you'll need to enable the unsupported SSH console. This is not required for the backup to work but you'll need a way to execute the script from a remote system and currently SSH is the only method to communicate with the host to run the script.

You should also note that the unsupported SSH Console is unsupported by VMware, if you have a support contract this could potentially void the agreement. Best practice is not to enable the console, but there are certain things that is limited with ESXi if you were to just rely on RCLI or VIMA to manage and sometimes an admin may need to login to the console. It's best that you secure your environment and ensure that your hosts are not directly accessible to the public WAN network and only hosts within your environment can communicate to your ESXi host(s).

Hopefully this clears up a few things and good luck on your implementation.


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

Apr 25, 2009 3:51 PM GruberK  says:

Hi,
I am using ESXi 3.5 Update4 with the ghettoVCB.sh script downloaded from this website.
I trying to backup 3 machines: Ubuntu 8.10, Windows 2003 STD, Windows 2008 STD, on all 3 machines are the latest VMWare tools installed to a NFS share which is mounted.

I have tried to backup all 3 machines with putty connected to the ESXi server.
su root ./ghettoVCB.sh virtual_machine_backup_list

The problem now is that I would like to backup the machines while they are running (Online)
POWER_VM_DOWN_BEFORE_BACKUP=0
ENABLE_HARD_POWER_OFF=0
2 of the 3 machines are shut down immediately (not gracefully, its like power off) when I start the backup script.

Can anyone tell me where the problem can be?
Thanks in advance for any suggestions!

Apr 25, 2009 3:56 PM lamw  says: in response to: GruberK

Your stated configurations and your expectations slightly contradict each other? Are you trying to perform the backup while the VM(s) are running? If so, the VM(s) should not be shutting down, unless there is some other issue with the VM(s) or host. If you're trying to backup the VM(s) and have them power down prior to backup, then you'll need to enable the appropriate flags. If you enable both flags to be 1 and you do not have VMware Tools installed on the guest, then the host will hard power off the VM after a certain duration.

Please clearly describe your scenario and setup.


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Apr 25, 2009 5:38 PM GruberK  says: in response to: lamw

Thanks for your quick answer, the 2 machines where the problem with the hard shutdown occurs have the current VMWare Tools installed, the two machines are also Powered On and running before starting the backu script.

Apr 28, 2009 8:45 PM tbsky  says:

hi:
thanks for your great script!

i use ghettoVCB.sh under ESX 3.5i u4 with live snapshot(no shutdown before snapshot).
i wonder if it is a quiesced snapshot? i can not find information about the command "svmvc/snapshot.create".
i hope MS-SQL server with vmwaretools would be happy with the snapshot.
can you give me some advice?
thanks for your help!!

Regards,
sky_li

Apr 30, 2009 8:49 AM gbras  says:

Hi,
I'm confused about the versions of this script. The version I downloaded today from the link in the "attachments" section of this page (or from "http://engineering.ucsb.edu/~duonglt/vmware/") is 11/01/2008:
#!/bin/bash

  1. Author: william2003atgmaildotcom
  2. Date: 11/01/2008

the "CHANGELOG" section lists a version of the script (11/22/2008) that detects existing snapshots and RDMs: where can download it?

Thanks
Guido

Apr 30, 2009 10:21 PM tbsky  says: in response to: gbras

hi:
the author didn't modify the change log. but they are the latest version and can detect existing snapshot. i have tried that.

the attachment and the script at author's website is different files. but after filtering all the white spaces, they are the same.

May 1, 2009 7:20 AM lamw  says: in response to: tbsky

Hi sky_li,

If you're running hight transactional databases, it's generally not recommended to use snapshots for backups due to transactions occurring within a DB. There is something called VSS which is available within VMware Tools that makes the guest aware that a snapshot is going to occur and it forces all data to be flushed from memory to disk, I've not used this personally and I believe it may only be available when VMware VCB is called, Duncan has an article at http://www.yellow-bricks.com/2008/07/26/vss-snapshots/

I would probably stay away from taking VMware snapshots and rely on database snapshots.

In terms of vimsh wrapper for creating snapshots, you won't find much information on any of the commands as these are not officially supported by VMware even though it provides a slew of advanced functionality.

You can always run the following for some basic info:

[root@himalaya scripts]# vmware-vim-cmd vmsvc/snapshot.create
Insufficient arguments.
Usage: snapshot.create vmid [snapshotName] [snapshotDescription] [includeMemory]

Creates a snapshot for the vm.



Where the includeMemory accepts a boolean


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

May 1, 2009 7:45 AM lamw  says: in response to: gbras

Hi Guido,

As tbsky stated, the latest script is currently available for download on this page. The date within the script may be a little miss-leading, it's actually the date that I started develoment of the script. The chanelog on the other hand is accurate in terms of the changes that have taken place since the release of the script and again the latest download will always be available on the VMTN document download page.

I'll ensure that both the script on the VMTN and on our website is the same, sorry for any confusion


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

May 1, 2009 7:50 AM lamw  says: in response to: gbras

Hi Guido,

As tbsky stated, the latest script is currently available for download on this page. The date within the script may be a little miss-leading, it's actually the date that I started develoment of the script. The chanelog on the other hand is accurate in terms of the changes that have taken place since the release of the script and again the latest download will always be available on the VMTN document download page.

I'll ensure that both the script on the VMTN and on our website is the same, sorry for any confusion


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

May 2, 2009 5:20 AM ibhp  says:

hello lamw

I ve got a server to backup which has only space for one backup at a time. Now your
script does first the backup and then rotates/deletes the old backups. This means, in
some time during the backup there are to backups on the disc...

Would it be possible to just move the "rotate"-function to the beginning of your script
and do the backup after rotating/deleting the old backups? Or can you see any problems?

Thank you,

ibhp

May 2, 2009 6:24 AM tbsky  says: in response to: lamw

hi lamw:

i am just curios. "quiesced windows snapshot" seems become complete at 3.5 update 2 with sync+vss driver. but the link you give me tell us stay away from exchange,ad,sql. then i don't know what this "quiesce" function for.

also there seems some version of snapshot command line have "quiesce" option, like the link mentioned:
http://www.esxguide.com/esx/index.php?option=com_mambowiki&page=createsnapshot&page_heading=&show_pageheading=&allowanonymoususers=

but it seems the new command line version didn't have the "quiesce" parameter, only "memory" option is left. i wonder if the snapshot is quiesced automatically now, or the option is because "quiesced" may bring problems.

someone said that if you do a "quiesced snapshot", ms-sql log will tell you.i haven't any real ms-sql server running in the vm now. maybe i can check that in the future.

May 2, 2009 4:29 PM lamw  says: in response to: ibhp

The reason I put the rotate function after the backup is to ensure we have a good backup prior to rotation, especially in the case of just rotating once. I would say please ensure that you have sufficient space for all backups


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

May 2, 2009 4:34 PM lamw  says: in response to: tbsky

Yea I'm not too familiar with the expected behavior of VSS other than asking the VM to flush its data from memory to disk. I just know from reading on the VMTN forums from other experts it's not recommended to using VMware snapshots on VM(s) like databases and if you do, you'll need to look into VSS which is only available per VMware VCB (I think). You may need to run a few tests to see the behavior and I would actually recommend posting a question regarding this on the main VMTN forum and I'm sure an expert familiar with the process can provide further insight.


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

May 11, 2009 1:51 AM pietcur  says:

Hi lamw,

First of all, thx for this great script! I have a question though and hope that the following might also be possible with your script: can you specify a vmdk within a vm that you want to backup? I would like to backup only one vmdk of a vm that is on the same datastore. So basically I want to exclude all the other vmdk's that are attached to this vm and stored on a different datastore. Is this possible?

Thank you,

Pietcur

May 11, 2009 8:51 AM lamw  says: in response to: pietcur

Specific VMDK disk(s) backups are not supported, only full backups. You're more than welcome to modify the script to fit your needs.


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

May 12, 2009 6:34 PM tbsky  says: in response to: lamw

hi:
i am considering put all the windows pagefile and linux swap file to a separate vmdk file. so i can skip backing up them in the future. would you consider implement this feature? or would you consider receive patch?

thanks for your help!!

May 13, 2009 2:22 PM mhanby  says:

Thanks for the script.

Shouldn't the script bypass the creation of a snapshot if the guest is in a powered down state? Seems like extra work to take a snapshot and then merge the snapshot back into the base when the machine is already static.

Also, I got the following error while backing up a guest that was powered off:

/vmfs/volumes/datastore1/scripts # ./ghettoVCB.sh single_vm

################ Taking backup snapshot for Windows XP 32bit Base ... ################
DiskLib_Check() failed for source disk Insufficient permission to access file (38).
Destination disk format: VMFS thick
Cloning disk '/vmfs/volumes/Development/Windows XP 32bit Base/winxp-32bit-base.vmdk'...
Clone: 16% done.

The clone appears to have worked, however out of all the guests that I backed up, that was the only one that echoed the DiskLib_Check() message.

May 13, 2009 2:31 PM mhanby  says: in response to: mhanby

I notice that the script also doesn't appear to take into consideration whether or not a vmdk is thinly provisioned. (as previously mentioned by ddigioia)

I could alter the command:
vmkfstools -i "${SOURCE_VMDK}" "${DESTIONATION_VMDK}"
to
vmkfstools -i "${SOURCE_VMDK}" -d thin "${DESTIONATION_VMDK}"

But:
a) is there a way for the script to identify if a vmdk is thin, and if so add '-d thin'
b) is there any danger in storing thin clones? maybe why the script doesn't already do the previous

May 13, 2009 3:36 PM lamw  says: in response to: mhanby

You know I think this was something I had missed when dealing with the option of allowing a user to configure the shutdown of a guest, I think I might have forgotten to take into consideration the current state of the VM. You're right, this may be a bug. Majority of the user's I've spoke to that have used the script are running live backups and would not run into the issue, but it's a good point and I'll ensure the next update of the script is fixed.

Thanks for bringing it to my attention


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

May 13, 2009 3:45 PM lamw  says: in response to: mhanby

At the time, we were not looking at using thin provision backups, it does not hurt and provides optimized storage consumption (hence probably why vSphere officially supports it now)

Your modifications will work and thinly provision disks upon backup, also a note when you're backing up to NFS datastore, it'll automatically thin provision the disk for you AFAIK

a) You can look at the descriptor file and you'll find a line that says: ddb.thinProvisioned = "1"
b) In terms of backup, there is are no dangers, better storage utilization. In terms of running thin provision VM(s), you just need to be aware of your storage utilization and with ESX 3.5, there are not sufficient monitoring on the datastores to notify you as VM(s) start to fill up, with vSphere there are better notifications/reports.

In an upcoming release of the script all 3 backup types will be supported zeroedthick, thin and 2gb sparse

Thanks for the comments


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

May 14, 2009 6:14 PM tbsky  says: in response to: lamw

hi:
please consider add "monolithic sparse" also. with that you get a small,single vmdk file.
backup tools like rdiff-backup can compare two versions for a file and only backup the difference.
with "monolithic sparse" single vmdk file, backup tools can easily backup many versions of vms with little harddisk space.

May 18, 2009 12:16 PM ibhp  says:

Hello community

I have a win2k3 server running on a ESXi-host with 2 virtual harddrives attached. Now one time the backup runs correct (backing up both virtual harddrives) and the other time it backs-up only the first virtual harddrive (every second time only one virtual hdd is backed-up). This looks like this:

Failure:
Destination disk format: VMFS thick
Cloning disk '/vmfs/volumes/First_750GB_HD/Win2K3 TS/Win2K3 TS_1.vmdk'...
Destination disk format: VMFS thick
Cloning disk '/vmfs/volumes/First_750GB_HD/Win2K3 TS/Win2K3 TS.vmdk'...
Clone: 100% done.
*******************************

Success:
Destination disk format: VMFS thick
Cloning disk '/vmfs/volumes/First_750GB_HD/Win2K3 TS/Win2K3 TS_1.vmdk'...
Clone: 100% done.
Destination disk format: VMFS thick
Cloning disk '/vmfs/volumes/First_750GB_HD/Win2K3 TS/Win2K3 TS.vmdk'...
Clone: 100% done.
*******************************

Any idea what this could be caused from?
Thanks for any help!

May 21, 2009 7:25 AM lamw  says:

Hi everyone,

We're proud to announce the release of ghettoVCBg2 the next gen of ghettoVCB. You can find more information located at: http://communities.vmware.com/docs/DOC-9843

Hope you guys like it!

=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

May 26, 2009 5:48 AM freez267  says: in response to: lamw

I've just upgraded my ESXi from 3.5 to 4.0 and the old ghetto script doesn't work.
Infact if I connect with putty and launch the script:

./ghettoVCB.sh weekly
I receive
-ash: ./ghettoVCB.sh: not found

I can't use the new script ghetto2 because I have the free version of ESXi
Can someone help me?

May 26, 2009 10:44 AM lamw  says: in response to: freez267

ghettoVCB has not been tested/certified for ESX(i) 4.0, we've been pretty busy and just have not had the time to test. This holds true for variety of other scripts and some will fail due to changes in vSphere release. In general, I think the script should work and it does not utilize anything that is not already available in ESXi 4.0, make sure the permissions on your script is set to executable. I'll try to do a quick run tonight and post back.


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

May 26, 2009 10:56 AM mhanby  says: in response to: freez267

The error is telling you that ghettoVCB.sh doesn't exist in your current directory.

Was your ghettoVCB.sh script on a datastore or on one of the OS file systems? If it wasn't on a datastore, the version 4 upgrade probably wiped it.

Copy it back to a datastore and execute it from there and see if it will work with v4.

May 26, 2009 11:15 AM lamw  says: in response to: freez267

Okay, just got ESXi 4.0 installed as a VM on our ESX 4 (physical) and I see the problem, looks like there was some change to their shell environment and if you didn't know the busybox console runs on ash ... kinda like bash. It looks like it has a problem when you try to do the following:

./ghettoVCB.sh

-ash: ./ghettoVCB.sh: not found


clearly, I can see the script is in the current directory.

The workaround is the following:

1) Edit the script and change the top line to:

#!/bin/ash


OR

2) execute with the ash interpreter:

ash ./ghettoVCB.sh


Give this a go and it should work, in terms of the actual backup ... I have not verified, so let me know if this works. In the coming weeks, will be verifying some of older scripts and release updates for ESX(i) 4.0 if necessary.


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

May 26, 2009 11:56 PM freez267  says: in response to: lamw

Ok now I can launch the script but I have these errors:

/vmfs/volumes/48c6a14e-37156b78-c647-001a925eca7c # ash ./ghettoVCB.sh weekly
Error: failed to extract VM_ID for 2008Termi!
Error: failed to extract VM_ID for al
Assiste!
Error: failed to extract VM_ID for zaVista2!

Start time: Wed May 27 06:51:45 UTC 2009
End time: Wed May 27 06:51:48 UTC 2009
Duration : 3 Seconds

Completed backing up specified Virtual Machines!

May 27, 2009 12:06 AM lamw  says: in response to: freez267

I ran a quick test earlier and realized some of the code may need to be updated. I have not had a chance to dig further on what needs to be modified.


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

May 29, 2009 2:24 PM lamw  says: in response to: freez267

Have you had a chance to try out ghettoVCB4i.sh to see if the issues are resolved?


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

May 30, 2009 5:20 AM atrussokc  says:

Thanks for the great script. I finally have an option for backing up my ESXi (free) 4 VMs. I downloaded ghettoVCB4i.sh and attempted to use it but encountered a problem where all of my VMs with the letter 'n' in the name where causing an error. This is similar to the issue described by freez267 above. I don't fully understand why but commenting out the line

IFS=$'\n'

appeared to resolve the issue for me. I am not sure what this line does.

Thanks
Tony Russell

May 30, 2009 1:44 PM lamw  says: in response to: atrussokc

That's odd... it should work, I've verified on our ESXi 4 system.

IFS=$'\n'


Is called the Internal Field Separator:
http://en.wikipedia.org/wiki/Internal_Field_Separator
http://learnlinux.tsf.org.za/courses/build/shell-scripting/ch11s11.html

Basically when I loop through the list of VM(s) after some sanity checks and extracting out the VmId which is used in the vimsh to uniquely identify a VM, I'm also extracting the VM(s) displayName. When user's use white space in their VM names, by default the IFS is looking for a 'space' as a delimiter to denote the next line of data so a workaround is to redefine the IFS to look for a newline that way you can capture the line of text with spaces. In either cases it will not hurt if you don't have spaces in your VM name, but it'll only help if you do.

Again, I'm not exactly sure why you're having an issue since '\n' is representing a newline and not the 'n' char.


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

May 31, 2009 1:28 PM paulkc  says:

I am running this on ESXi 4. I have tried to follow the directions very closely but I keep getting a Permission Denied error every time I try to actually run the script. Any suggestions?

May 31, 2009 1:37 PM lamw  says: in response to: paulkc

Did you change the permissions on the script to have executable permissions?

chmod +x ghettoVCB4i.sh


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Jun 1, 2009 12:23 AM freez267  says: in response to: paulkc

I continue to have this error

Error: failed to extract VM_ID

On the VMs that have 'n' in the name. For example is impossible to backup the VM '2008Terminal' and 'AssistenzaXp' but no problem with 'W7RC'

Jun 1, 2009 9:10 AM lamw  says: in response to: freez267

I just created some dummy VM(s) using the names you've specified and it looks like the environment is not treating $'\n' as a newline char but the literal char 'n'. This cause the loop to break off once it sees the first char 'n' and a VM with the name: "2008Terminal" will be chompped into "2008Termin" and "al" which neither of which will match, hence it fails. If you specify a list of VM(s) w/o 'n' then the backup is successful. This is pretty odd and I'll have to look into it some more.

You said if you remove the IFS=$'\n', everything works?


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Jun 1, 2009 9:16 AM paulkc  says: in response to: lamw

That is exactly what happened in my case. If I commented out that line, it worked fine.

Jun 1, 2009 9:53 AM lamw  says: in response to: paulkc

Looks like the newline needs to be defined in the following manner:

IFS='
'


notice where the single tick starts and ends which is on the following line. If you make this modification, it will backup all 3 VM(s) properly .... I'll push an update out tonight, it looks like the new Busybox ash environment may have been slightly changed and does not recognize $'\n' as a newline. The real reason for redefining the IFS is for VM(s) names that may contain spaces, which I consider a bad practice...but if you know your naming convention will never have spaces,tabs,etc...then you should be fine.


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Jun 7, 2009 9:44 AM carlotto  says:

Hi,
Thanks for a fantastic script. Works well, but I have a problem with the rotation. Anyone with a clue why it won't work? See output from a sh -x command (last bit):

Cloning disk '/vmfs/volumes/HB-ESXi2-scsi1/HB-Label/HB-Label.vmdk'...
Clone: 100% done.
+ IFS=

+ ! 0 -eq 1
+ /bin/vim-cmd vmsvc/snapshot.remove 256
+ echo Removing snapshot from HB-Label ...
+ ls /vmfs/volumes/HB-ESXi2-scsi1/HB-Label
+ grep -q delta
+ sleep 3
+ ls /vmfs/volumes/HB-ESXi2-scsi1/HB-Label
+ grep -q delta
+ sleep 3
+ ls /vmfs/volumes/HB-ESXi2-scsi1/HB-Label
+ grep -q delta
+ checkVMBackupRotation /vmfs/volumes/Thecus/Backup/HB-Label /vmfs/volumes/Thecus/Backup/HB-Label/HB-Label-2009-06-07
+ local BACKUP_DIR_PATH=/vmfs/volumes/Thecus/Backup/HB-Label
+ local BACKUP_VM_NAMING_CONVENTION=/vmfs/volumes/Thecus/Backup/HB-Label/HB-Label-2009-06-07
+ ls -tr /vmfs/volumes/Thecus/Backup/HB-Label
+ LIST_BACKUPS=HB-Label-2009-05-31
HB-Label-2009-06-05
HB-Label-2009-06-07
+ -z 4
+ TMP_DIR=/vmfs/volumes/Thecus/Backup/HB-Label/HB-Label-2009-05-31
+ echo /vmfs/volumes/Thecus/Backup/HB-Label/HB-Label-2009-05-31
+ TMP=/vmfs/volumes/Thecus/Backup/HB-Label/HB-Label-2009-05-31
+ /vmfs/volumes/Thecus/Backup/HB-Label/HB-Label-2009-05-31 = /vmfs/volumes/Thecus/Backup/HB-Label/HB-Label-2009-06-07
+ /vmfs/volumes/Thecus/Backup/HB-Label/HB-Label-2009-05-31 -ge 4
sh: /vmfs/volumes/Thecus/Backup/HB-Label/HB-Label-2009-05-31: bad number
+ echo /vmfs/volumes/Thecus/Backup/HB-Label/HB-Label-2009-05-31
+ BASE=/vmfs/volumes/Thecus/Backup/HB-Label/HB-Label-2009-05-31
/vmfs/volumes/Thecus/Script/HB-Label/ghettoVCB.sh: /vmfs/volumes/Thecus/Script/HB-Label/ghettoVCB.sh: 340: Syntax error: /vmfs/volumes/Thecus/Backup/HB-Label/HB-Label-2009-05-31+1
/vmfs/volumes/46df116f-b561be9a/Log #

I have a few different VM's with different rotation counts (I keep several copies of the script). At least one does not delete when more than the rotation count, I suspect the problem above. Any clue anyone? Why syntax error etc?

Jun 8, 2009 2:20 PM Ritchy059  says: in response to: carlotto

I had a similiar Problem here an a ESX Server 3.5:

At first: Script works well from the Root-Shell...

But, when i Plan the Script via Crontab, the Script starts, make's the Snapshot, Backup the *.vmdk and *.vmx File in a newly created Folder BUT at the End of the Backup the Script don't rename the Folder in correct manner.

Script stopped working. I have to rename the Folders manually in correct Name und Numbers and have to remove the Snapshot manually from ESX Server's VI Client.

The Script only Backups the First VM in the Backup List and after Backup stopped working !

mfg
Ritchy059

Jun 15, 2009 3:02 AM adiXSG  says: in response to: Ritchy059

I've running an ESXi 4.0 Server.
The backup does function well. But there is one problem wich is descibed by other persons above. It is the empty log file. Is there a solution for it or not? At the moment I see through all folders if the backup success. But that can't be the final solution.
Further the current version of ghettoVCB4i.sh runs great if there are no whitespaces in the vm name. Otherwise the rename after backup fails and because of that the backup rotation fails too. So I've removed all whitespaces in VM names like lamw describes as best practice :)

Thanks lamw for his great work... really really usefull script!!

Jun 18, 2009 5:40 AM voro  says:

For those interested in logging, maybe this helps you:

Run the script like this

sh ghettoVCB.sh vmlist.txt 2>&1 | busybox logger -t ghettoVCB -p 1

and then, push ESXi logs to a remote syslog-ng server.

Jun 27, 2009 6:17 PM relegated  says: in response to: voro

Does this backup method copy the vmdk to the same vmfs volume and to get it offsite you would have to download the backup vmdk file from the datastore?

Jun 28, 2009 10:50 PM mylesw  says: in response to: relegated

You could just mount a NFS volume and select that as the destination for the backup. That's what we do. Works great.

Jun 28, 2009 10:54 PM mylesw  says: in response to: lamw

Quick question... I am running ghettoVCB.sh on ESXi 3.5 and its working great on most of my VMs. However I have a VM that seems to have a snapshot associated with it. I checked in the datastore, and there was a 'delta' file there. I powered down the VM and then deleted the delta file. Powered it back on, and then attempted to run ghettoVCB.sh. It again wouldn't do the backup because it said that there was a snapshot there. I checked it again, and the delta file had returned...

I know this isn't a specific question of ghettoVCB, but how do I get rid of these snapshots so I can do a clean backup of a live VM?

Jun 28, 2009 11:42 PM voro  says: in response to: mylesw

You shouldn't delete deltas by hand. Instead, remove snapshots from VIC.
Deltas track changes to the main vmdk, but information about snapshots are kept in vmsd files.

Jun 29, 2009 12:38 PM relegated  says: in response to: voro

Unfortunately I only have my one ESXi box at home with 1 HDD in it and my desktop so I have no NFS volume to mount :(

So for me, does that mean that this script just backs up the running vmdk and I would need to manually download it?

If that is the case the primary function of the script would be to reduce downtime as otherwise I would need to power down the VM and copy the vmdk correct?

Jun 29, 2009 12:43 PM mylesw  says: in response to: relegated

So for me, does that mean that this script just backs up the running vmdk and I would need to manually download it?

What it basically does is a clone of the VM. The location of the cloned VM is up to you, and set in the script preferences. If you have NFS storage mounted and available to ESXi, then you can elect to use that as the storage location. Otherwise you'd have to store it in a local datastore somewhere. Once its done, then you can download it to offline storage using SCP or some other form of transport that you can support with ESXi.

If that is the case the primary function of the script would be to reduce downtime as otherwise I would need to power down the VM and copy the vmdk correct?

You do not need to power down the VM to do the clone. The script will create a snapshot before it starts its processing and remove it when its completed it. You do have the option to power down the VM in the script, however, but by default it is turned off.

Jun 29, 2009 12:46 PM mylesw  says: in response to: voro

You shouldn't delete deltas by hand. Instead, remove snapshots from VIC.
Deltas track changes to the main vmdk, but information about snapshots are kept in vmsd files.

Thanks. I found a way to remove the snapshots using VM Explorer's free edition (http://www.trilead.com). Works great.

Jul 1, 2009 4:55 AM bjoernbergmann  says:

Great script! Thank you so much... We are backing up 4 ESXi 3.5 servers successfully with about 6VMs each.

There is only one problem to backup a Debian Linux 60GB virtual harddisk. Snapshot seems to be OK. Backing up the disk (one of two) failed after some time with the following error message.

Taking backup snapshot for DEASX401 ... ################
Destination disk format: VMFS thick
Cloning disk '/vmfs/volumes/datastore1/DEASX401/DEASX401_2.vmdk'...
Clone: 79% done.Failed to clone disk : Insufficient permission to access file (38).
Destination disk format: VMFS thick
Cloning disk '/vmfs/volumes/datastore1/DEASX401/DEASX401.vmdk'...
Clone: 100% done.
Removing snapshot from DEASX401 ...
Completed backup for DEASX401! ####################
Start time: Wed Jul 1 06:45:27 UTC 2009
End time: Wed Jul 1 09:21:51 UTC 2009
Duration : 156.40 Minutes
Completed backing up specified Virtual Machines!

Might it be possible that the disk is to big? Is there any timeout?

Here some more information:
./ghettoVCB.sh is running with root account!
backup disk mouted vie NSF from a Win2003R2 server
share is an external 1GB USB disk
nsf shared folder is windows compressed (can save until 75% of original space)

Regards,

Bjoern

Jul 8, 2009 6:46 AM spray6969  says: in response to: lamw

Hi !

Very great Job !

I try to use it under ESXi 4.0 (last release) but I encountered a problem. I logged it :

+ SOURCE_VMDK='/vmfs/volumes/Datastore 1/Fedora 9_Nagios_Centreon//usr/lib/vmware/isoimages/linux.iso'
+ DESTIONATION_VMDK='/vmfs/volumes/NFS_GED//Fedora 9_Nagios_Centreon/Fedora 9_Nagios_Centreon-2009-07-08//usr/lib/vmware/isoimages/linux.iso'
+ ''
+ vmkfstools -i '/vmfs/volumes/Datastore 1/Fedora 9_Nagios_Centreon//usr/lib/vmware/isoimages/linux.iso' '/vmfs/volumes/NFS_GED//Fedora 9_Nagios_Centreon/Fedora 9_Nagios_Centreon-2009-07-08//usr/lib/vmware/isoimages/linux.iso'
DiskLib_Check() failed for source disk The system cannot find the file specified (25).

Someone could help me ?

Jul 10, 2009 6:55 AM lamw  says:

Sorry for the delay of response but I've been extremely busy over the last month and I currently do not have the cycles to look into the current issues. I'm aware there are some interesting problems being faced that may all be related. I will provide some more details when I get a chance to take a look at the issue hopefully in a few weeks after my VCP4 exam. Thanks for your patience


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Jul 13, 2009 5:56 AM shechtl  says: in response to: lamw

Hello lamw,

I used your script since a long time without problems (great work any many thanks), but yesterday we changed to esxi4.0 and I changed to your latest ghettovcb4.x version.
Like others I get this error:
+ vmkfstools -i /vmfs/volumes/5fbd225c-3cf7a7b1/xpsp2.iso /vmfs/volumes/iscsi2backupdsa1/backups/endiancfg/endiancfg-2009-07-13/5fbd225c-3cf7a7b1/xpsp2.iso/xpsp2.iso
DiskLib_Check() failed for source disk The file specified is not a virtual disk (15).

your script tries to backup the iso file of the cdrom. Why ? I there a way to disable it or is it only a bug ?
Also if the cdrom is a phys. cdrom of the host I get this disklib errors.
So my workaround now is to remove the complete cdrom from the vm hardware. Not nice but working.
The harddiskbackup is still working

Hope you will find a solution, because I check my backup logs automatically for the word failed and error and that
CDrom problem will prevent my autolog check from correct running.

Jul 13, 2009 11:44 PM jllopezg  says:

Hello everybody,
I am trying to do the backup of a esxi with this script, it is working perfecty, but I need to backup the vm´s with rdp too.
I have tried the ghettoVCBg2.pl without success.
Anybody has the code to add to the script to backup the vm´s ignoring the rdp?

Thanks a lot for yor help!
Regards.
Jose

Jul 14, 2009 12:50 AM freez267  says: in response to: shechtl

Same problems with cdroms and same solution of "shechtl".
I have to delete the cdrom on some VM to complete the backup

Jul 14, 2009 8:02 AM maweko  says:

Hello,

In terms of the strange path pointing to an ISO file I had the same behaviour and after removing all mounted CD on all VM's it was gone.

My experience about the "DiskLib_Check() failed for source disk" error message in a ESXi3.5 environment is that the error is caused when the backup loop in the script executes "vmkfstools -i "${SOURCE_VMDK}" "${DESTIONATION_VMDK}".
During first cycle in the loop of a new VM the Source_VMDK and Destination_VMDK do not point to files, they point to folders and this is causing not supported by the vmkfstools. I am not a shell developer but this is how it looks to me.

By the way somethign interesting.
On a ESXi4 using the ghettoVCB4i.sh I noticed that a "DiskLib_Check() failed for source disk" error is only shown if the VM config file has been created as a version 7. All VM's version 4 can be backed up without the error to pop up.

Jul 14, 2009 12:47 PM cyberfire  says: in response to: maweko

Hi.
I just upgraded the scripts for 4.0 and get this error on one of 2 VM one the box.

RDM was found for 14_MSCLink_TestOS_Win2k8, backup will not take place

Jul 14, 2009 12:49 PM cyberfire  says: in response to: cyberfire

ah.
Found the comment at the begining of the doc.
Sorry!

BTW, the VM has 2 disks, one virtual and one RAW. Is there a way to backup the virtual one?¿

Jul 19, 2009 10:27 AM lamw  says:

Hi everyone, I've just pushed out an update to both ghettoVCB.sh and ghettoVCB4i which should fix the issue with the script trying to backup .iso when you have a mounted CD-ROM, this should not be an issue anymore and supports backing up w/o having to remove the CD-ROM device.

I've also added 2 additional VMDK output format and added a new variable to support the various types:

# Format output of VMDK backup
# 1 = zeroedthick
# 2 = 2gbsparse
# 3 = thin
# 4 = eagerzeroedthick
VMDK_OUTPUT_FORMAT=1


Please take a look at the change log for more details (07/19/09) and if you're interested in any type of logging, there is a new section at the top for Advanced Logging.

Please download the latest scripts and let me know if you're still running into the .iso issues.

=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Jul 19, 2009 10:49 AM mylesw  says: in response to: lamw

I am running this script with VMWare ESXi 3.5 and it works great. Well almost. One of my VMs is a Linux based file server that has a small vmdk for itself, and also uses NFS mounted disk storage for the bulk of its storage. I only want the local vmdk to be backed up in this case. Is there a way, on a per VM basis, that you can set preferences to only backup the local vmdk of a vm with this script if there are remote storage (NFS or iSCSI) for the vm that you don't want backed up?

Hope that makes sense.

Myles

Jul 19, 2009 10:56 AM lamw  says: in response to: mylesw

Not a supported feature of the script, you're more than welcome to modify to fit your needs or create separate backup jobs. Remember, the script itself is providing a generic backup solution, if you need something more specific you'll need to make those changes.


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Jul 19, 2009 11:05 AM mylesw  says: in response to: lamw

I can certainly create separate backup jobs for this particular VM, but if I understand the way this works, I'd have to not only create a separate file with the target VM to backup, but I'd also have to create a modified ghettoVCB.sh script to tell it to only backup the specified vmdk files, right? That's ok, but it obviously requires a programming change in the way that the script determines what to backup by VM. Just before I launch down that path (which I'm fine with doing), I just wanted to make sure that there wasn't a preference property already available in the standard ghettoVCB.sh script that would cater for this...

Myles

Jul 19, 2009 11:29 AM lamw  says: in response to: mylesw

Yes, you'll need to add some type of logic to on figuring out which VMDKs to backup and not backup and have a way to specify that in either a local configuration file stored within each VM or a config file read into the script. There's nothing in the script today that supports the request you're talking about, good luck.


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Jul 20, 2009 1:22 AM maweko  says:

Hello,

Can anyone tell me best way to determine a ghettoVCB backup is running on a ESXi?

Beside this what is the best way to stop a backup process and how do I have to performe this?

I do not have any problems with the scripts so far, but would like to know how to kill things without messing up my whole ESXi.

Thanks in advance for a reply.

maweko

Jul 20, 2009 1:37 AM voro  says: in response to: maweko

To check if the process is running, from ssh:
ps|grep ghettoVCB.sh

To kill the process:
kill -9 id_from_above

If you kill it, remember to manually remove snapshots using VirtualCenter or whatever you use, don't delete snapshot files by hand.

Jul 20, 2009 2:03 AM maweko  says:

Thank's for the info.

Tested it on my ESXi 3.5 U4 and although a backup process is actually running the ps does not display any process with name "ghettoVCB.sh" .
That's a bit confusing.

I started the backup with ./ghettoVCB.sh "vmlist file"

Any ideas

Jul 20, 2009 5:36 AM adiXSG  says: in response to: maweko

I've tested the new version of the script. I try to create thin format for the backup. But although it creates flat format vmdk's. Where could be problem?

thanks in advance for a reply.

Adrian

Jul 20, 2009 6:56 AM lamw  says: in response to: adiXSG

I think "thin" provisioning for post vSphere ESX(i) 4.0 may not act in the way people expect, I certainly haven't played with thin provisioning too much. I need you to do the following two things:

1) What is the script configured to, meaning what value did you set the VMDK_OUTPUT_FORMAT, default is 1 which is zeroedthick

2) On the VM that was backed up thin, can you go into the folder and cat out the .vmdk file and NOT the *-flat.vmdk

3) When running the backup, can you do it manually and see if you see a screen output similar to this:

~ # ./ghettoVCB4i.sh vmbackuplist
################ Taking backup snapshot for ghettoVCB4i-test-vm-backup ... ################
Destination disk format: VMFS thin-provisioned
Cloning disk '/vmfs/volumes/datastore1/ghettoVCB4i-test-vm-backup/ghettoVCB4i-test-vm-backup.vmdk'...
Clone: 100% done.
Removing snapshot from ghettoVCB4i-test-vm-backup ...
#################### Completed backup for ghettoVCB4i-test-vm-backup! ####################


Specifically you're looking for the key words "Destination disk format: VMFS thin-provisioned", if so, then thin provisioning is occurring and this goes back to my initial thought on how thin provisioning may work in ESX(i) 3.5. Remember by default if you backup to NFS datastore, it 'should' be thin by default whether or not you select it from vmkfstools, least from my own experiences.


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Jul 20, 2009 11:12 PM shechtl  says: in response to: lamw

Hi Lamw,

I changed now to your new version with the cdrom fix. It works with most of our machines, but there is one vm where I got problems.
Its the only VM with Win98 and a ide hdd (I know Win98 but its a must)
If I start the script, the scripts makes a snapshot and removes the snapshot after that immediately, but no disks will be copied.
I think the problem is ide. With the old version backup is running but only without the cdrom.

Here is the relevant part of the log:

+ IFS=
+ echo ide0:0
+ SCSI_ID=ide0:0
+ grep -i ide0:0.present /vmfs/volumes/iscsi2dsa1/samwin/samwin.vmx
+ grep -i true
+ 0 -eq 0
+ grep -i ide0:0.deviceType /vmfs/volumes/iscsi2dsa1/samwin/samwin.vmx
+ grep -i scsi-hardDisk
+ 1 -eq 0
+ IFS=

+ vim-cmd vmsvc/power.getstate 224
+ tail -1
+ ORGINAL_VM_POWER_STATE=Powered on
+ 0 -eq 1
+ [ ! 0 -eq 1 ]
+ [ Powered on != Powered off ]
+ echo ################ Taking backup snapshot for samwin ... ################
+ date +%F
+ vim-cmd vmsvc/snapshot.create 224 vcb_snap VCB_BACKUP_samwin_2009-07-21
+ OLD_IFS=

+ IFS=:
+ IFS=

+ [ ! 0 -eq 1 ]
+ [ Powered on == Powered on ]
+ vim-cmd vmsvc/snapshot.remove 224
+ echo Removing snapshot from samwin ...
Removing snapshot from samwin ...
+ ls /vmfs/volumes/iscsi2dsa1/samwin
+ grep -q delta
ls: /vmfs/volumes/iscsi2dsa1/samwin/samwin-000001.vmdk.lck: No such file or directory
+ sleep 3
+ ls /vmfs/volumes/iscsi2dsa1/samwin
+ grep -q delta
+ [ 0 -eq 1 ]
+ TMP_IFS=

Hope you could help

Jul 21, 2009 8:31 PM lamw  says: in response to: shechtl

Okay, I see the issue. This should hopefully be fixed now in the latest version of the script. Give it a run and let me know how it goes.

=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Jul 22, 2009 5:42 AM freez267  says: in response to: lamw

/vmfs/volumes/4965afe0-76fbdae2-48e3-00221952c5db # ls
ANTHEAFILESThin PieraVMThin TimbratureVMThin
ANTHEAR10TEST R10INTERNO ghettoVCB4i.sh
AntheaDom R9SVP weekly
IvanoVMThin RosalbaVMVistaThin weekly2
/vmfs/volumes/4965afe0-76fbdae2-48e3-00221952c5db # sh ghettoVCB4i.sh weekly2

                                1. Taking backup snapshot for IvanoVMThin ... ################
Destination disk format: VMFS zeroedthick
Cloning disk '/vmfs/volumes/datastore1/IvanoVMThin/IvanoVMThin.vmdk'...
Clone: 100% done.
Removing snapshot from IvanoVMThin ...
sh: /vmfs/volumes/VMBACKUP/ESX22/IvanoVMThin/IvanoVMThin-2009-07-21: bad number
ghettoVCB4i.sh: line 374: syntax error: /vmfs/volumes/VMBACKUP/ESX22/IvanoVMThin/IvanoVMThin-2009-07-21+1
/vmfs/volumes/4965afe0-76fbdae2-48e3-00221952c5db #

I receive always this error when I backup this thin VM with windows XP.
Can someone help me?

Jul 22, 2009 6:56 AM lamw  says: in response to: freez267

Are you using the latest version of the script? Also if you have the right permissions set, you don't need to execute with "sh", you should do something like this:

./ghettoVCB4i.sh weekly2


Also there is a param in the script after the "DO NOT EDIT" portion that provides some debugging information called "DEVEL_MODE" can you please change this from 0 to 1 and re-run the script and provide the output of that. To ensure the forum does not mangle your screen output, please wrap it in {code} tags


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Jul 22, 2009 1:45 PM clone0326  says: in response to: adiXSG

First of all, thanks to all who have had a part putting this script together. I'm very new to VMWare and Linux, and this has all been such a huge help. However, I'm having the same issue as adiXSG. I have a Linux VM that I have given a thin disk, and I have uploaded the most recent version of the ghettoVCB4i.sh script, choosing option 3 for thin disk format. However, the output is "servername-flat.vmdk" and the file size is 100 gigs, not the 5.2 or so gigs that it should be (the size of the original thin .vmdk file).

I hope I'm describing this properly, does anyone know what the problem could be? Thanks!

Jul 22, 2009 4:23 PM lamw  says: in response to: clone0326

Please take a look at this response http://communities.vmware.com/docs/DOC-8760#comments-11794 and provide the requested output


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Jul 22, 2009 11:21 PM freez267  says: in response to: lamw

I'm running the latest version of the script. I tried with ./ghetto..... but the problem remain.
The file have the rights "rwxr-xr-x"

If I change DEVEL_MODE I receive this information

/vmfs/volumes/4965afe0-76fbdae2-48e3-00221952c5db # ./ghettoVCB4i.sh weekly2
(vim.fault.DuplicateName) {
dynamicType = <unset>,
faultCause = (vmodl.MethodFault) null,
name = "VMBACKUP",
object = 'vim.Datastore:192.168.111.23:/VMBACKUP',
msg = "The name 'VMBACKUP' already exists.",
}
##########################################
Virtual Machine: IvanoVMThin
VM_ID: 448
VMX_PATH: /vmfs/volumes/datastore1/IvanoVMThin/IvanoVMThin.vmx
VMX_DIR: /vmfs/volumes/datastore1/IvanoVMThin
VMX_CONF: IvanoVMThin/IvanoVMThin.vmx
VMFS_VOLUME: datastore1
##########################################

##########################################
Virtual Machine: PieraVMThin
VM_ID: 432
VMX_PATH: /vmfs/volumes/datastore1/PieraVMThin/PieraVMThin.vmx
VMX_DIR: /vmfs/volumes/datastore1/PieraVMThin
VMX_CONF: PieraVMThin/PieraVMThin.vmx
VMFS_VOLUME: datastore1
##########################################

##########################################
Virtual Machine: TimbratureVMThin
VM_ID: 400
VMX_PATH: /vmfs/volumes/datastore1/TimbratureVMThin/TimbratureVMThin.vmx
VMX_DIR: /vmfs/volumes/datastore1/TimbratureVMThin
VMX_CONF: TimbratureVMThin/TimbratureVMThin.vmx
VMFS_VOLUME: datastore1
##########################################

##########################################
Virtual Machine: RosalbaVMVistaThin
VM_ID: 416
VMX_PATH: /vmfs/volumes/datastore1/RosalbaVMVistaThin/RosalbaVMVistaThin.vmx
VMX_DIR: /vmfs/volumes/datastore1/RosalbaVMVistaThin
VMX_CONF: RosalbaVMVistaThin/RosalbaVMVistaThin.vmx
VMFS_VOLUME: datastore1
##########################################

Start time: Thu Jul 23 06:16:31 UTC 2009
End time: Thu Jul 23 06:16:34 UTC 2009
Duration : 3 Seconds

DEVEL MODE OUTPUT COMPLETE

/vmfs/volumes/4965afe0-76fbdae2-48e3-00221952c5db #

Jul 22, 2009 11:25 PM lamw  says: in response to: freez267

I don't see anything wrong from the output, is this the only VM you're having problems with? Can you ensure there are no left over snapshots from the script?


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Jul 23, 2009 6:29 AM clone0326  says: in response to: lamw

Ok, I hope I'm being clear, please let me know if you need clarification:

1) For VMDK_OUTPUT_FORMAT, I set the value to 3 for thin disk

2) I'm not sure what you mean by this. Can you provide instructions on how to "cat out" the .vmdk file? I do see two vmdk files, one is the -flat file (100 gigs) the other is servername.vmdk but is only 1k.

3) When running the script, I do see that output and the line "Destination disk format: VMFS thin-provisioned"

I also was able to clone the disk manually using the following command, which appears in the ghettoVCB4i.sh script:
#vmkfstools -i /vmfs/volumes/san_vmfs/my_vm/large_disk.vmdk -d thin /vmfs/volumes/san_vmfs/my_vm/new_thin_disk.vmdk

That command worked in converting the vmdk to a thin disk, so I'm not sure why the script isn't.

Jul 24, 2009 12:04 AM freez267  says: in response to: lamw

I'm sure no snapshot on the VM.
I have the same problem on another VM with different OS.

The backup process seems to work fine. Infact it arrive at 100% and the file created seems correct.
Maybe the problem is when try to cancel the old folder backup or the snapshot.

Jul 24, 2009 3:00 PM cookieme  says: in response to: freez267

I've spent the past 2 hours or so reading through this thread from start to finish!! Incredibly valuable help from all!

However, I have a few questions that I feel have not been asked/answered.

1. I access my ESXi host remotely with HP iLO via VPN. Am I correct in saying that I can copy the script from my remote system to the ESXi system WITHOUT enabling the unsupported mode and/or SSH if I use vCLI with command vifs?

2. Maybe I have missed something, but where do you actually store the ghettoVCB script? It seems that you can choose to store it on external or internal storage. I am interested in internal, but where is the appropriate location?

3. I understand that most users are starting the script from another system via SSH. This is well explained, but I am interested in scheduling the script from within the ESXi host. Now there are a few references to crontab (new to me) and some suggestions on how to set this up. Some say edit rc.local and others are doing something like this

*echo "0 2 * * 6 /vmfs/volumes/vmiscsi/tools/ghettoVCB4i.sh" > /var/spool/cron/crontabs/root*

However, the different approaches have me confused, so William could you please add a section at the top with the "best practice" of configuring a crontab to run the script or post a recommendation?

Thanks for an excellent free backup solution!!

Jul 24, 2009 3:05 PM cookieme  says: in response to: voro

voro can you please elaborate on how to push ESXi logs to a syslog server and what the advantages are (I'm new to this)? I found a virtual appliance http://www.syslogappliance.de/en/ would this work if it resides on the same ESXi host?

Thanks

Jul 25, 2009 12:32 AM voro  says: in response to: cookieme

3) If you want to schedule it without keeping a ssh session open or using a remote system, you have to use ESXi's crond. Busybox's crond is limited and adding that line in /var/spool/cron/crontabs/root is the only way, but it will be lost upon rebot. That's why some suggest adding that echo in rc.local

Jul 25, 2009 12:47 AM voro  says: in response to: cookieme

About Remote logging

  • Advantages:
Easier manageability, you don't need to keep the VIClient/VCenter open to read the logs, you can parse them with third party tools/custom scripts, you don't lose them if something goes wrong, you can setup alerts if certain entry is logged,etc. There are dozens of reasons, just google it.

  • Howto:
Very easy. Log to local syslog running the script as I posted before
./ghettoVCB4i.sh vmbackuplist 2>&1 | busybox logger -t ghettoVCB4i -p 1
then, configure ESXi's syslog to log to a remote host
vi /etc/syslog.conf
or with VIClient configuration tab (it's in advanced features), just add remote syslog's IP or hostname.

Configuring remote daemon can be as easy as doing nothing (depends on your defaults) or allowing ESXi's to push their logs there, or even using a separate file to store those logs (easier with syslog-ng)

It doesn't matter if it's another VM on the same host, a physical computer or even a server on a different network as long as ESXi can reach UDP Port 514 on the remote syslog.

Jul 25, 2009 1:17 PM lamw  says: in response to: clone0326

When looking at the actual size of thin provisioned disk, if you do 'ls -lha', it will not show you the actual disk consumption. So by running the conversion in a script or from the CLI, it should yield the same results. Are you sure you're using the same VM and doing one backup and then doing it from the CLI to ensure you're looking at the same VM? You'll be able to see the actual consumption if you do something like 'du -h' since ESXi unsupported console does not have 'du' nor 'vdf'.

Here is an example:

I have a VM that is allocated thick with 8gb:

/vmfs/volumes/4a59c382-f2feee8e-0280-005056825b84/ide-vm # ls -Falh
drwxr-xr-x    1 root     root          980 Jul 25 12:06 ./
drwxr-xr-t    1 root     root         1.2k Jul 25 12:03 ../
-rw-------    1 root     root         8.0G Jul 21 19:36 ide-vm-flat.vmdk
-rw-------    1 root     root          440 Jul 21 19:36 ide-vm.vmdk
-rw-------    1 root     root            0 Jul 21 19:36 ide-vm.vmsd
-rwxr-xr-x    1 root     root         1.5k Jul 21 19:36 ide-vm.vmx*
-rw-------    1 root     root          261 Jul 21 19:36 ide-vm.vmxf


I have a local datastore that has 5.6G free, which is where this specific VM is stored and where the backup will go (vmfs3 is the local storage):
/vmfs/volumes/4a59c382-f2feee8e-0280-005056825b84/ide-vm # df -h
Filesystem                Size      Used Available Use% Mounted on
visorfs                 278.2M    243.3M     34.9M  87% /
nfs                       1.3T    789.7G    558.7G  59% /vmfs/volumes/d32c5a97-e039bdbf
vfat                      4.0G    384.0k      4.0G   0% /vmfs/volumes/4a59c381-8059e09f-33a3-005056825b84
vfat                    249.7M     76.2M    173.5M  31% /vmfs/volumes/7db9337b-a328f52c-2a05-87d4ed7807df
vfat                    249.7M      4.0k    249.7M   0% /vmfs/volumes/eb676f73-6dd0961e-3224-09791e2c7199
vfat                    285.9M    230.2M     55.7M  81% /vmfs/volumes/c2a427e4-2d317086-fef9-b5750d88536c
vmfs3                    15.0G      9.4G      5.6G  62% /vmfs/volumes/4a59c382-f2feee8e-0280-005056825b84


I know manually clone on the CLI:
/vmfs/volumes/4a59c382-f2feee8e-0280-005056825b84/ide-vm # vmkfstools -i ide-vm.vmdk -d thin ide-vm-THIN.vmdk
Destination disk format: VMFS thin-provisioned
Cloning disk 'ide-vm.vmdk'...
Clone: 100% done.


As you can see from the above, it thinly provisioned and it was done VERY quickly and now lets take a look at the directory listing to see what 'ls' shows us:
/vmfs/volumes/4a59c382-f2feee8e-0280-005056825b84/ide-vm # ls -Falh
drwxr-xr-x    1 root     root         1.2k Jul 25 12:08 ./
drwxr-xr-t    1 root     root         1.2k Jul 25 12:03 ../
-rw-------    1 root     root         8.0G Jul 25 12:08 ide-vm-THIN-flat.vmdk
-rw-------    1 root     root          494 Jul 25 12:08 ide-vm-THIN.vmdk
-rw-------    1 root     root         8.0G Jul 21 19:36 ide-vm-flat.vmdk
-rw-------    1 root     root          440 Jul 21 19:36 ide-vm.vmdk
-rw-------    1 root     root            0 Jul 21 19:36 ide-vm.vmsd
-rwxr-xr-x    1 root     root         1.5k Jul 21 19:36 ide-vm.vmx*
-rw-------    1 root     root          261 Jul 21 19:36 ide-vm.vmxf


Both the original and thin clone still shows up 8gb, but if you look at 'df' you'll notice that available space is still 5.6gb, meaning the disk was thin provisioned else I would have ran out of space:
/vmfs/volumes/4a59c382-f2feee8e-0280-005056825b84/ide-vm # df -h
Filesystem                Size      Used Available Use% Mounted on
visorfs                 278.2M    243.3M     34.9M  87% /
nfs                       1.3T    789.7G    558.7G  59% /vmfs/volumes/d32c5a97-e039bdbf
vfat                      4.0G    384.0k      4.0G   0% /vmfs/volumes/4a59c381-8059e09f-33a3-005056825b84
vfat                    249.7M     76.2M    173.5M  31% /vmfs/volumes/7db9337b-a328f52c-2a05-87d4ed7807df
vfat                    249.7M      4.0k    249.7M   0% /vmfs/volumes/eb676f73-6dd0961e-3224-09791e2c7199
vfat                    285.9M    230.2M     55.7M  81% /vmfs/volumes/c2a427e4-2d317086-fef9-b5750d88536c
vmfs3                    15.0G      9.4G      5.6G  62% /vmfs/volumes/4a59c382-f2feee8e-0280-005056825b84


Just to prove that this case, I try to do a standard clone which by default is zeroedthick which fails:
/vmfs/volumes/4a59c382-f2feee8e-0280-005056825b84/ide-vm # vmkfstools -i ide-vm.vmdk ide-vm-THICK.vmdk
Destination disk format: VMFS zeroedthick
Cloning disk 'ide-vm.vmdk'...
Failed to clone disk : There is not enough space on the file system for the selected operation (13).


So the script is indeed doing what you're setting it up to and you probably were looking at the wrong file when comparing the disk usage as there is a -flat.vmdk which is the actual vDisk and the .vmdk which is the descriptor file for a given VM.

=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Jul 26, 2009 7:38 AM mylesw  says: in response to: voro

Question: I know that ghettoVCB.sh will skip a backup if any snapshots exist. We have a couple of ESXi servers that we never use snapshots on. Is there any danger in modifying the script to forcibly remove any snapshots with the script if it finds any and then do the backups? I know that the script can remove snapshots - I just don't want backups skipped if they were attempted before, and the script failed for some reason, leaving the VMs in a state where they can be never backed up afterwards unless there is some manual intervention to remove the snapshots.

Myles

Jul 26, 2009 10:20 AM lamw  says: in response to: mylesw

The script should always remove all snapshots that 'it' creates so long as you don't intervene or manually tweak with a VM during the backup process. I'm not exactly sure what you mean your initial statement, of ESXi servers that never use snapshots. The backup process requires snapshots as you know OR you have the option of powering off the VM before backup. If you're worried for some reason that snapshots may be left behind for whatever reason, you of course could modify the script in such a way to loop through all VMs and removeallsnapshots, but you will receive no support if you do make such modifications. If you follow all requirements and you've verified before implementing ghettoVCB, you should not have any issues with VMs having snapshots in the first place and they should all be removed prior to moving to the next VM.

Hopefully this cleared up your concerns, also if this was an issue, I'm sure I would have heard from many others about it ;)

Thanks again.


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Jul 26, 2009 10:34 AM cookieme  says: in response to: cookieme

Hmm, are my questions too trivial that no one wants to respond? I'm not asking just for the sake of it. There are many repeat questions/ answers not just here, but on any forum. However, like I said I have gone through this thread diligently and I couldn't find answers to what may be simple questions. I'm sure others would benefit.

Well, I look forward to some response, so I can better understand how to use this. Thanks

Jul 27, 2009 9:33 PM lamw  says: in response to: cookieme

1. I access my ESXi host remotely with HP iLO via VPN. Am I correct in saying that I can copy the script from my remote system to the ESXi system WITHOUT enabling the unsupported mode and/or SSH if I use vCLI with command vifs?

2. Maybe I have missed something, but where do you actually store the ghettoVCB script? It seems that you can choose to store it on external or internal storage. I am interested in internal, but where is the appropriate location?

3. I understand that most users are starting the script from another system via SSH. This is well explained, but I am interested in scheduling the script from within the ESXi host. Now there are a few references to crontab (new to me) and some suggestions on how to set this up. Some say edit rc.local and others are doing something like this

*echo "0 2 * * 6 /vmfs/volumes/vmiscsi/tools/ghettoVCB4i.sh" > /var/spool/cron/crontabs/root*

1) Wrong, you'll need to enable the unsupported mode to both upload and configure/execute the script. You technically can use vifs to upload the script if you're going to be executing on a datastore that's not local to the ESXi hosts such as NFS,FC/iSCSI SAN but the configuration/setup will require the unsupported SSH console. The information regarding the upload, setup and configuration is defined in the documentation, it may not be explicitly state that you must do this and this but the assumption is made that users understand they'll need to unlock the unsupported console when using this script.

2) Again, this is a choice left up to the end users. As you can see there are advantages/disadvantages to storing the script on either internal or external storage. If you decide to store it locally and not have it rely on other sources, then you'll need to deal with the persistent configuration to ensure the script itself is persisted in a reboot and any type of cron jobs scheduled. There is no 'best practice' on where to store your script, that is for you to figure out and perhaps through trial/error you'll get a feel for what will work in your environment.

3) Again, there is no best practice. You're more than welcome to schedule this within ESXi, have an external VM whether that be Windows/Linux make an SSH connection and execute the backup job and run it in the background to ensure that no persisted TCP connection is required. As you know from reading through not only this thread but many others in the VMTN forum regarding configuring the cron jobs, there's more than one way and more than one location that'll keep the configurations persisted through a reboot.

One example can be found at this thread: Re: FTP on ESXi 3.5??

You can also find a nice detailed 3 part article by Raj on configuring this on a Windows system if you're more comfortable and familiar than on a UNIX/Linux system.

So, when you say provide a best practice, there really isn't one. The scope of this script is to provide a general backup solution that enables some flexibility on end users and if you need something more specific such as detail logging, compression, scheduling, etc. I expect end users to find/research the best solution that'll work in their operating environment.

Hopefully this clears up your question and again you can find more information by doing a search within the main VMTN forum as well. I'm sure you'll find many other threads that can help you understand some of what people have done, I know a very popular thread that contains implementation of this script can be found in ~last 10-15pages of: Free ESXi Backup Solution for Windows


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Jul 29, 2009 8:04 AM shechtl  says: in response to: lamw

Hello Lamw,

thanks for your work. All backups are running ok now.

Jul 30, 2009 7:28 AM vmuser23  says: in response to: shechtl

The best free backup script ever written was the VISBU

The main important features were
1. Backup vm mentioned based on criteria powered on or off only
2. compress the backup
3. restore script included

Important features
1. Specify which vmdk's can be backed up in a vm for example we have a few vm's that have vmdk and an rdm so we specify the backup to only backup the vmdk and skip the rdm from the vm
2. CIFS/NFS/LOCAL DESTINATION

Unfortunately its no longer available, will this script have all the features and become the best free script to work on esx/esxi without any license needed from vmware ?

Aug 3, 2009 8:45 PM lamw  says: in response to: vmuser23

Please take a look at the documentation (this document) for the features provided with this script, if you can not find it, then it does not exists.


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Aug 4, 2009 8:55 AM tnol2  says: in response to: ollivetti

"Error: failed to extract VM_ID"

The solution is:

Check this fields on the VMX file:

displayName = "Vmname"
extendedConfigFile = "vmname.vmxf"

Both need be the same, example:

displayName = "vmname"
extendedConfigFile = "vmname.vmxf"

Aug 5, 2009 3:50 AM Stephan84  says:

Hi,

i am using ghettoVCB4i.sh on ESXi 4.0.0 171294 and have some problemes with white spaces in VMs names.

While executing the Script i get the following errors:

ls: /vmfs/volumes/Storagesrv01_backups//itorga: No such file or directory
ls: backuptrigger: No such file or directory
ls: /vmfs/volumes/Storagesrv01_backups//dnie: No such file or directory
ls: workstation: No such file or directory

The names of the virtual machines are: "itorga backuptrigger" and "dnie workstation"

I checked the IFS:

IFS='
'

I think that the error occures in Line 314:

echo "Removing snapshot from ${VM_NAME} ..."
while ls "${VMX_DIR}" | grep -q delta;
do
sleep 3
done

Does anybody has an idea how to fix this? I can't rename all VMs.

Thanks,
Stephan

For those of you who are trying to run the script via chronjob:

  • Use a secound Linux machine
  • Use ssh/authorized_keys file
  • write/use a shell script like this:

ssh ESX Host IP "date > NFS Path to Logfile.log"
ssh ESX Host IP "./sbin/ghettoVCB4i.sh /sbin/vm_backup_list >> NFS Path to Logfile.log"
cat LOCAL NFS Path to Logfile | mail -s Backup_subjekt Mail@Host

Aug 5, 2009 4:46 AM tnol2  says: in response to: Stephan84

The problem is the empty space, on the name of virtual machines. Remove it.

Aug 5, 2009 5:45 AM Stephan84  says: in response to: tnol2

Hi tnol2,

as i said: i can't rename all the VMs :(

Aug 5, 2009 5:56 AM bjoernbergmann  says: in response to: bjoernbergmann

Hi!

Since there much more activity now here I want to ask you again if there is any idea about the problem posted several weeks ago.
We are using the 3.5 version of ghettoVCB.sh. If you need any more details - just let me know....

*-------
We are backing up 4 ESXi 3.5 servers successfully with about 6VMs each.

There is only one problem to backup a Debian Linux 60GB virtual harddisk. Snapshot seems to be OK. Backing up the disk (one of two) failed after some time with the following error message.

Taking backup snapshot for DEASX401 ... ################
Destination disk format: VMFS thick
Cloning disk '/vmfs/volumes/datastore1/DEASX401/DEASX401_2.vmdk'...
Clone: 79% done.Failed to clone disk : Insufficient permission to access file (38).
Destination disk format: VMFS thick
Cloning disk '/vmfs/volumes/datastore1/DEASX401/DEASX401.vmdk'...
Clone: 100% done.
Removing snapshot from DEASX401 ...
Completed backup for DEASX401! ####################
Start time: Wed Jul 1 06:45:27 UTC 2009
End time: Wed Jul 1 09:21:51 UTC 2009
Duration : 156.40 Minutes
Completed backing up specified Virtual Machines!

Might it be possible that the disk is to big? Is there any timeout?

Here some more information:
./ghettoVCB.sh is running with root account!
backup disk mouted vie NSF from a Win2003R2 server
share is an external 1GB USB disk
nsf shared folder is windows compressed (can save until 75% of original space)

*------

Regards,

Bjoern

Aug 5, 2009 7:02 AM lamw  says: in response to: bjoernbergmann

Again, I'll tell you the same thing I told you awhile back, there are no known issues of timeout or VMDK being too large so long as you're under the < 2TB range.

The error dictates this to be a permission issue and not anything with the script. I would highly recommend you manually do a backup by hand to ensure that you are in fact able to backup using vmkfstools and isolate the problem that may be occuring.


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Aug 5, 2009 7:36 AM bjoernbergmann  says: in response to: lamw

Thank you. It seems I was not able to read your answer before.
I will try to do it manually using vmkfstools and give you feedback.

Aug 5, 2009 7:45 AM fqu89  says:

Hi,
I think you can greatly reduce the down time of a VM when you power it off before doing the backup by doing this:

1 - take down the VM
2 - create a snapshot
3 - restart the VM
4 - start the backup (without the snapshot files)
5 - remove the snapshot while the VM is on

The VM is down only the time to do the snapshot
what do you think of this ?

Aug 5, 2009 8:25 AM lamw  says: in response to: fqu89

Majority of the use cases is live backup of a running VM, I don't know of many environments that can actually afford to take down their VMs/physical systems for backups. Again this option is present in the script if you wish to power down your VM, in which case a snapshot is NOT required as the VMDK is not locked. A snapshot is only necessary when it's running and a VMFS lock is issued and a snapshot will create a delta in which the main VMDK will be set to read-only allowing for the backup.


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Aug 5, 2009 8:37 AM fqu89  says: in response to: lamw

I do agree with you that usually, it's not possible to stop VM to do backups.
But you're script give the option to stop VM before backing up.
My post was just a little idea to try to minimize the down time of a VM IF you can stop it, and don't have to wait that the tons of gigs of the VMDK files be copied before restarting the VM.

Aug 5, 2009 6:55 PM IT_Architect  says: in response to: lamw

How does GhettoVCB handle VMs that have virtual hard disks on two different volumes?

Thanks!

Aug 5, 2009 9:11 PM lamw  says: in response to: IT_Architect

ghettoVCB handles it like a champ ;)

If you take a look at this document, it provides a list of features, one of which is:

  • Fully support VMDK(s) stored across multiple datastores


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Aug 5, 2009 10:05 PM IT_Architect  says: in response to: lamw

Normally the vmdks are stored with the VMs. When the backup of a VM with a second vmdk on a different disk, does ghetto move the secondary vmdk files into the same directory as the other vmdk?

Aug 5, 2009 10:11 PM lamw  says: in response to: IT_Architect

It moves the VM's VMDK(s) to the backup datastore, it does not matter if the VMs disk is spread across multiple datastores. The way it's stored in the final backup is if the original disk reside on multiple datastores, the backup folder will have a directory for each of the datastore and the disk will be backed up into that directory.

I would highly recommend trying the script out on a dummy/test VM to see what the script is capable of.


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Aug 6, 2009 6:39 PM lamw  says:

I think there has been quite a bit of confusion on Thin Provisioning, not only with this script which has supported this feature for awhile but also in the general forums.

Within the guestOS, it may show free/unsused space but it does not mean that blocks have not been allocated in the past that could have used up more space than it's showing. Remember, when you delete something, you're just not referencing it anymore, it's still there. Blocks within the OS needs to be zeroed out and this is explained in detail from Mr. 007 himself Duncan Epping at: http://www.yellow-bricks.com/2009/07/31/storage-vmotion-and-moving-to-a-thin-provisioned-disk/

Thin provisioning does work using vmkfstools but you need to ensure you've zeroed out any unused blocks before actually see this when trying to backup or even convert a VMDK.

Hopefully this clears things up


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Aug 7, 2009 12:42 AM Stephan84  says:

Hi,

i am using ghettoVCB4i.sh on ESXi 4.0.0 171294 and have some problemes with white spaces in VMs names.

While executing the Script i get the following errors:

ls: /vmfs/volumes/Storagesrv01_backups//itorga: No such file or directory
ls: backuptrigger: No such file or directory
ls: /vmfs/volumes/Storagesrv01_backups//dnie: No such file or directory
ls: workstation: No such file or directory

Any ideas?

Tanks, Stephan

Aug 7, 2009 8:40 AM JamesClark@ke…  says: in response to: Stephan84

Hi William,

Thanks for such a great script!

Were using it in an ESXi 3.5 environment. I have presented 380GB iSCSI storage to the host as a datastore.
Ive used Starwind to create the iSCSI target.
When I run the script I get:

/bin # ./ghettoVCB4i.sh servers.txt
Invalid desination disk format 'zeroedthick'
Removing snapshot from (servername)

The remove snapshot hangs.
There are no lingering snapshots or backups on the server Im testing.
Ive tried changing the format output but get same message with relevent storage type name instead of zeroedthick.
Any clues as to why this is failing?

Thanks,
Perry.

Aug 7, 2009 8:46 AM lamw  says: in response to: JamesClark@ke…

Well one thing that should worry you is Invalid desination disk format 'zeroedthick', it looks like you might have not setup the right destination format. Please take a look at the document for instructions on how to set the output VMDK format (note, it's configured as 1,2,3,4)


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Aug 7, 2009 8:58 AM JamesClark@ke…  says:

Hi William,

Thanks for such a great script!

Were using it in an ESXi 3.5 environment. I have presented 380GB iSCSI storage to the host as a datastore.
Ive used Starwind to create the iSCSI target.
When I run the script I get:

/bin # ./ghettoVCB4i.sh servers.txt
Invalid desination disk format 'zeroedthick'
Removing snapshot from (servername)

The remove snapshot hangs.
There are no lingering snapshots or backups on the server Im testing.
Ive tried changing the format output but get same message with relevent storage type name instead of zeroedthick.
Any clues as to why this is failing?

Thanks,
Perry.

Aug 8, 2009 12:45 AM lamw  says: in response to: Stephan84

Spaces in a VM name is bad! ;)

Anyway, I think I know is wrong and I just uploaded a new revision of ghettoVCB4i.sh which should fix the issue.

Here is a sample run in our development environment:

/vmfs/volumes/4a59c382-f2feee8e-0280-005056825b84 # ./ghettoVCB4i.sh backuplist
################## Starting backup for ghettoVCB4i-test-vm-backup ... #####################
Destination disk format: VMFS zeroedthick
Cloning disk '/vmfs/volumes/datastore1/ghettoVCB4i-test-vm-backup/ghettoVCB4i-test-vm-backup.vmdk'...
Clone: 100% done.
#################### Completed backup for ghettoVCB4i-test-vm-backup! ####################

################## Starting backup for itorga backuptrigger ... #####################
Destination disk format: VMFS zeroedthick
Cloning disk '/vmfs/volumes/datastore1/itorga backuptrigger/itorga backuptrigger.vmdk'...
Clone: 100% done.
#################### Completed backup for itorga backuptrigger! ####################

################## Starting backup for dnie workstation ... #####################
Destination disk format: VMFS zeroedthick
Cloning disk '/vmfs/volumes/datastore1/dnie workstation/dnie workstation.vmdk'...
Clone: 100% done.
#################### Completed backup for dnie workstation! ####################


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Aug 10, 2009 2:41 AM Stephan84  says: in response to: lamw

Thank you! There are no more error messages.

Aug 10, 2009 4:52 AM voro  says:

Has anybody seen this message?

ls: /vmfs/volumes/raid/bktst1/bktst1-Snapshot148.vmem.MULTILOCK: No such file or directory

However, backup gets done (snapshots are created and deleted successfully and the disk image can be added to the inventory)
so I guess ESXi is to blame rather than the script.

Aug 12, 2009 7:57 PM IT_Architect  says: in response to: JoeyDE

Backup log file containing no information problem

The problem is in the Windows batch file. Do something like this and it will work:

"C:\Program Files\PuTTY\plink.exe" root@xxx.xxx.xxx.xxx -pw MyPassword "/vmfs/volumes/datastore1/ghettoVCB/ghettoVCB4i.sh /vmfs/volumes/datastore1/ghettoVCB/backup_list > /vmfs/volumes/datastore1/ghettoVCB/backuplog.txt &"

nohup is the problem

Aug 13, 2009 3:09 AM dide2000  says:

Hi,

I'm trying to get the script up and runing and already took some hurdles but now I'm getting the following error while trying to backup first vm :
Failed to open '/vmfs/....mydisk.vmdk' file : failed to lock the file ( 16392 )

I have ESXi 4.0. The VM I'm trying to backup is located on a separate NFS box ( netgear readynas pro ). The vm is not powered on.

Any ideas ?

thx

Aug 13, 2009 5:36 AM dide2000  says: in response to: dide2000

Resolved: The VM I tried to backup as test was actually booted on the main ESXi host ! ( Oops..).
When I use one that is not in use, the script runs correctly.

Dirk

Aug 13, 2009 12:17 PM willmarmn  says:

Is anyone else getting the ^M characters on the downloaded script? I downloaded it onto my NFS share and when I open it up in VI from ESXi, it shows all the lines have the ^M characters in them - it has never been opened on Windows. It is the script straight from this website. Otherwise, any ideas on removing them?

Should mention it is the ghettoVCB.sh script.

Aug 13, 2009 12:44 PM clone0326  says:

I'm using ESXi and I was using one NFS datastore for backups successfully. I recently switched the NFS storage to a new server, but I'm getting an error. I've tried doing just one server at a time, from 3 different esxi boxes, but it always fails after a few minutes. Are there any logs I can check to get a better idea of what's happening, or whether this is a network issue? thanks. Here is what I get:

/vmfs/volumes/4a6efadf-c0cc9be4-7146-000d601a03f2 # ./ghettoVCB4i.sh vmbackups

1. Taking backup snapshot for myserver... ################
Destination disk format: VMFS thin-provisioned
Cloning disk '/vmfs/volumes/datastore1/myserver/myserver.vmdk'...
Clone: 66% done.Failed to clone disk : Input/output error (327689).
Removing snapshot from myserver...
ls: /vmfs/volumes/VM_Backups/myserver: Input/output error

1. Completed backup for myserver! ####################
Start time: Thu Aug 13 19:02:33 UTC 2009
End time: Thu Aug 13 19:22:47 UTC 2009
Duration : 20.23 Minutes

Completed backing up specified Virtual Machines!

Aug 13, 2009 12:49 PM willmarmn  says: in response to: willmarmn

One other note:
I am getting an error saying I am not running 3.5 or 4. (I am running 3.5.0, 158869).
It appears that modifying the version check in the script to use print $5 instead of print $4 has fixed the problem.

Aug 13, 2009 12:55 PM willmarmn  says: in response to: willmarmn

dos2unix.org works good to remove the ^M characters.

Aug 13, 2009 2:24 PM lamw  says: in response to: willmarmn

This should not be the case, I've downloaded the most recent version directly to the ESX(i) host several times and it's been fine. Are you using ESXi 3.5 or ESXi 4.0? With 4.0, it comes with 'curl' and you can donwload it to the host directly.

=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Aug 13, 2009 2:25 PM lamw  says: in response to: clone0326

This is due to a network connectivity issue, ensure you're not saturating your NFS link. Take a look at this VMware KB: http://kb.vmware.com/kb/2116375


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Aug 13, 2009 2:27 PM willmarmn  says: in response to: lamw

I am using 3.5, so I am downloading it on a Windows host NFS share (not opening it).
I had the old script working fine, but am just upgrading to support my future 4 upgrade. Using that website, I did get it to work, just wanted to make sure the file on the server was correct. I'll just chalk it up to my Windows machine somehow.

Aug 13, 2009 3:12 PM lamw  says: in response to: willmarmn

Which script is giving you this issue? I think this was fixed in the latest ghettoVCB.sh


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Aug 13, 2009 3:12 PM lamw  says: in response to: willmarmn

It's good if you're downloading from this VMTN document.


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Aug 13, 2009 11:05 PM aj24  says:

Hi

I am using your script to backup thin provisioned disks to an NFS on a windows machine however when they are backed to the nfs datastore they switch to flat full size vmdk files. I have tried the sdelete script as suggested to zero out all the data and also created new virtual machines however it still does the same. Is this set-up supported or is there anything I could be doing wrong.

Thanks

Aug 13, 2009 11:13 PM lamw  says: in response to: aj24

What version of ESX(i) are you running and how big is the VMDK allocated and how much is actually being consumed from the guestOS perspective? afaik, when transferring to NFS datastore, it'll alaways be thin provisioned. One other thing I would double check is to check the NFS datastore free space before the backup and then after and see if it's changed, even if the VMDK shows the full size when doing 'ls -lha'


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Aug 14, 2009 4:59 AM tranceking  says:

Is there a modification where we can backup other vmdk in a vm and skipping only rdm disk instead of skipping the whole vm.

Aug 14, 2009 6:23 AM willmarmn  says: in response to: lamw

It was ghettoVCB.sh downloaded from above on 8/13/09.

Aug 14, 2009 6:50 AM lamw  says: in response to: willmarmn

You've only answered the first question .... what about the rest?

What version of ESX(i) are you running and how big is the VMDK allocated and how much is actually being consumed from the guestOS perspective? afaik, when transferring to NFS datastore, it'll alaways be thin provisioned. One other thing I would double check is to check the NFS datastore free space before the backup and then after and see if it's changed, even if the VMDK shows the full size when doing 'ls -lha'


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Aug 15, 2009 11:04 AM IT_Architect  says: in response to: lamw

I would like to propose the addition of a RUN_AFTER variable. The ability to serialize operations is invaluable.

Example: After the first set of backups you need another that backs up to a different destination and you want to append the output to the same log. After the final backup, you want to sendmail the log content. etc.

Aug 16, 2009 11:32 AM DSTAVERT  says:

The current as of 8/16 script checks the ESXi version. It appears to reject ESXi 3.5 or 4.

Also I have a three disk VM. The vmx file contains the path (/vmfs/volumes/9d044c9e-6965e94b etc) to the original third disk. The third disk was cloned to the 9d044c9e-6965e94b folder within the backup folder. I will run it again to make sure.

Aug 16, 2009 12:45 PM lamw  says: in response to: IT_Architect

You can easily create something similar by setting up a cronjob that executes a file that contains the various backups that you've defined, which can be in a sequential order which accomplishes what you're looking for. This is not a backup request but a scheduling request.

e.g.

cat my_backups
/root/ghettoVCB.sh /root/backuplist1
/root/ghettoVCB.sh /root/backuplist2
/root/ghettoVCB.sh /root/backuplist3


and my_backups is what would be in your cronjob, this assumes you want the various backups to kick off one after a another.

=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Aug 16, 2009 12:46 PM lamw  says: in response to: DSTAVERT

The code check might be denying 3i, but 4i is working. I'll have a fix for the string later this evening.

What version of ESX(i) 3.5 and 4.0 are you using?

Can you please output the following for ALL ESX(i) host's you're using the script against by doing the following"

vmware -v

=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Aug 16, 2009 2:18 PM DSTAVERT  says: in response to: lamw

I noticed it on 4 with the latest patches. Sorry I can't get to the 4 server right now.

Aug 16, 2009 2:37 PM DSTAVERT  says: in response to: DSTAVERT

on the 3 server VMware ESX Server 3i 3.5.0 build-120505

Not my server but I will update and re run.

Aug 16, 2009 3:09 PM DSTAVERT  says: in response to: DSTAVERT

Just updated the server.

VMware ESX Server 3i 3.5.0 build-176894
/vmfs/volumes/4d074c9e-6965e94b/scripts # ./ghettoVCB.sh backup.daily
You're not running ESX(i) 3.5+ or 4.0+!

Aug 16, 2009 3:15 PM DSTAVERT  says: in response to: DSTAVERT

ESX_VERSION=$(vmware -v | awk '{print $3}') Should be print $5

Aug 16, 2009 6:01 PM lamw  says: in response to: DSTAVERT

Yes, I'm aware of the 3i issue and I'll have an update later this evening. I'll still be using $3 but doing a different check for 3i since with 4i, they've gone back to the version number.

=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Aug 17, 2009 12:34 AM tranceking  says:

I have a vm with 2 vmdks one of them is a raw disk , how can I only skip that disk instead of skipping the whole vm ?

Aug 17, 2009 6:19 AM xHaplo  says:

A terrific script lamw. thanks very much for posting. I am using the latest script and cannot get it to backup BOTH VMDKs for a VM. The script will always backup the 'myvmname.vmdk' but not the 'myvmname_1.vmdk'. After injecting some echo's in the script I have learning the following:

The VMDKS_FOUND variable returns the follwoing: scsi0:0.filename scsi0:1.filename ide0:0.filename

obviously it is seeing both scsi stores at this point

However the loop 'for DISK in ${VMDKS_FOUND};' only ever iterates once

if I echo the DISK variable I get (on seperate lines)
scsi0:0.filename
scsi0:1.filename
ide0:0.filename

Could it be that the script is seeing DISK as a string rather than an array and therefore only looping once?

if this is occuring the following line:
SCSI_ID='echo ${DISK%%.*}'

will just bite off the first 'scsi0:0' from the string which explains why the script works for the first VMDK

Appreciate any thoughts/comments/suggestions

Aug 17, 2009 6:53 AM lamw  says:

This is a known issue, I'll be pushing a fix later this week. Sorry for the inconvenience. The reason this is occurring is due to a variable declaration that is not defined within the script and this definition is crucial to the looping of the VMDK(s) within the script. If you would like to remediate this yourselves, you can edit the script and add the following to line 193:

original code:

IFS='
'


modified code:
ORIG_IFS=${IFS}
IFS='
'

=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Aug 17, 2009 3:44 PM xHaplo  says:

Thanks William - this appears to work perfectly!
Appreciate your time in posting

Aug 18, 2009 2:11 PM penzipa  says:

Anyone know why I would get a Your not running ESX(i) 3.5 or 4.0 when running the ghetoVCB.sh script. I am running Esxi 3.5 update 176894? This should work right?

Aug 18, 2009 2:22 PM willmarmn  says: in response to: penzipa

Yes, see comments above:
DSTAVERT says: in response to: DSTAVERT
ESX_VERSION=$(vmware -v | awk '{print $3}') Should be print $5

Aug 18, 2009 3:02 PM penzipa  says: in response to: willmarmn

That did not work, I still get:
ghettoVCB.sh: ghettoVCB.sh: 460 : 3i: not found
You're not running ESX(i) 3.5+ or 4.0+

I made the change to the script above
any assistance is greatly appreciated

Aug 18, 2009 4:44 PM lamw  says:

The logic regarding the version check is as the following:

Pre-ESX(i) 4.0, the text would read something like the following when executing vmware -v "VMware ESX Server 3.5.0 build-163429", to get the major release you'll print out column #4

Post-ESX(i) 4.0, VMware decided to rebrand their hypervisor and remove the word Server from vmware -v and if you run this on 4.0 box you'll get "VMware ESX 4.0.0 build-164009" and as you can see, you'll need to now print out column #3

This gets interesting as with 3i, the version was not 3.5.0 but "3i" and again with 4i, this was not the case and we're back to just "4.0.0".

I have 4 ESX systems I use to verify/test this script agains, unless this oddity is occuring in another release, I've tested this against:

ESX 3.5u4
ESXi 3.5u4
ESX 4.0
ESXi 4.0

and they all sucessfully pass the check and execute backups.

Let me explain the logic, so everyone can understand, since others are thinking we need to print out other columns which is not the case:

First off, I check for 4.0.0 which uses col #3, since both ESX and ESXi 4.0 use the same version (no 4i crap), I first see if it's 4.0. If it's not, then I assume it's running 3.5 which can be any of the various flavor/updates + ESXi, in which case, it's column #4. I redefine the ESX_VERSION variable to capture the new version and then check for either 3.5.0 (classic ESX 3.5) or 3i (ESXi) and this should cover all the use cases.

	ESX_VERSION=$(vmware -v | awk '{print $3}')
        if [ "${ESX_VERSION}" == "4.0.0" ]; then
	        VER=4
        else
		ESX_VERSION=$(vmware -v | awk '{print $4}')
		if [[ "${ESX_VERSION}" == "3.5.0" || "${ESX_VERSION}" == "3i" ]]; then
			VER=3
		else
			echo "You're not running ESX(i) 3.5+ or 4.0+!"
                	exit
		fi
        fi


This has nothing to do with the brackets/etc. Generally if you're comparing 1 value, a single set of brackets is fine and if you're doing && or || than you'll need a double set.

If for whatever reason people are still running into this issue, can you please provide the actual update you're running and please please please, post what YOUR system shows when running vmware -v. I've noticed everyone is trying to help and provide a fix, but I need to understand exactly what is going on and what version YOU ARE running.

=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Aug 18, 2009 4:54 PM zdali  says: in response to: lamw

Hi William,
vmware -v outputs VMware ESX Server 3i 3.5.0 build-153875

Code i'm running looks like


	ESX_VERSION=$(vmware -v | awk '{print $3}')
	if [; then
		VER=4
	else
		ESX_VERSION=$(vmware -v | awk '{print $4}')
		if [ || [; then
			VER=3
		else
			echo "You're not running ESX(i) 3.5+ or 4.0+!"
			exit
		fi
	fi


Your logic is bang on here. I suspect the issue lies in the shell variable expansion.

TIA

dali

  • Now i only need to figure out how to make the code show up properly...

Aug 18, 2009 4:59 PM lamw  says: in response to: zdali

Can you please wrap your text output in \{code\} tags and actually do the following instead:

sh -x ./ghettoVCB.sh <your_input_list>


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Aug 18, 2009 5:28 PM zdali  says: in response to: lamw

Unmodified script outputs following:

/scripts # sh -x ghettoVCB1.sh backup_list
+ VM_BACKUP_VOLUME=/vmfs/volumes/backup/tempest
+ VMDK_OUTPUT_FORMAT=1
+ VM_BACKUP_ROTATION_COUNT=3
+ date +%F
+ VM_BACKUP_DIR_NAMING_CONVENTION=2009-08-19
+ POWER_VM_DOWN_BEFORE_BACKUP=0
+ ENABLE_HARD_POWER_OFF=0
+ ITER_TO_WAIT_SHUTDOWN=4
+ ENABLE_COMPRESSION=0
+ ENABLE_NON_PERSISTENT_NFS=0
+ UNMOUNT_NFS=0
+ NFS_SERVER=172.30.0.195
+ NFS_MOUNT=/nfsshare
+ NFS_LOCAL_NAME=nfs_storage_backup
+ NFS_VM_BACKUP_DIR=mybackups
+ DEVEL_MODE=1
+ IS_4I=0
+ [ ! -f /bin/bash ]
+ sanityCheck 1
+ NUM_OF_ARGS=1
+ [ ! 1 == 1 ]
+ [ -f /usr/bin/vmware-vim-cmd ]
+ [ -f /bin/vim-cmd ]
+ VMWARE_CMD=/bin/vim-cmd
+ VMKFSTOOLS_CMD=/sbin/vmkfstools
+ vmware -v
+ awk {print $3}
+ ESX_VERSION=Server
+ [ Server == 4.0.0 ]
+ vmware -v
+ awk {print $4}
+ ESX_VERSION=3i
+ [[ 3i == 3.5.0
sh: missing ]]
+ 3i == 3i ]]
ghettoVCB1.sh: ghettoVCB1.sh: 460: 3i: not found
+ echo You're not running ESX(i) 3.5+ or 4.0+!
You're not running ESX(i) 3.5+ or 4.0+!
+ exit

Aug 18, 2009 5:45 PM zdali  says: in response to: zdali

Sorry to double post here, but I seem to fail at editing :-(

Currently running code

	ESX_VERSION=$(vmware -v | awk '{print $3}')
	if [ "${ESX_VERSION}" == "4.0.0" ]; then
		VER=4
	else
		ESX_VERSION=$(vmware -v | awk '{print $4}')
		if [ "${ESX_VERSION}" == "3.5.0" ] || [ "${ESX_VERSION}" == "3i" ]; then
			VER=3
		else
			echo "You're not running ESX(i) 3.5+ or 4.0+!"
			exit
		fi
	fi


outputs:
+ VM_BACKUP_VOLUME=/vmfs/volumes/backup/tempest
+ VMDK_OUTPUT_FORMAT=1
+ VM_BACKUP_ROTATION_COUNT=3
+ date +%F
+ VM_BACKUP_DIR_NAMING_CONVENTION=2009-08-19
+ POWER_VM_DOWN_BEFORE_BACKUP=0
+ ENABLE_HARD_POWER_OFF=0
+ ITER_TO_WAIT_SHUTDOWN=4
+ ENABLE_COMPRESSION=0
+ ENABLE_NON_PERSISTENT_NFS=0
+ UNMOUNT_NFS=0
+ NFS_SERVER=commander.swerve.co.nz
+ NFS_MOUNT=/nfsshare
+ NFS_LOCAL_NAME=nfs_storage_backup
+ NFS_VM_BACKUP_DIR=mybackups
+ DEVEL_MODE=1
+ IS_4I=0
+ [ ! -f /bin/bash ]
+ sanityCheck 1
+ NUM_OF_ARGS=1
+ [ ! 1 == 1 ]
+ [ -f /usr/bin/vmware-vim-cmd ]
+ [ -f /bin/vim-cmd ]
+ VMWARE_CMD=/bin/vim-cmd
+ VMKFSTOOLS_CMD=/sbin/vmkfstools
+ vmware -v
+ awk {print $3}
+ ESX_VERSION=Server
+ [ Server == 4.0.0 ]
+ vmware -v
+ awk {print $4}
+ ESX_VERSION=3i
+ [ 3i == 3.5.0 ]
+ [ 3i == 3i ]
+ VER=3
+ [ 0 -eq 1 ]
+ [ ! -f ]
+ whoami
+ [ ! root == root ]
+ ghettoVCB backup_list
+ VM_INPUT=backup_list
+ date
+ START_TIME=Wed Aug 19 00:38:32 UTC 2009
*snip*
Completed backing up specified Virtual Machines


I've had less trouble fixing the problem than working out how to use the forums :-) Thanx again for the excellent script.

dali

Aug 18, 2009 6:22 PM DSTAVERT  says: in response to: lamw

The output for my version
VMware ESX Server 3i 3.5.0 build-120505
3.5 is in the fifth column not fourth. It could be that VMware is "messin witcha".

Aug 18, 2009 6:33 PM zdali  says: in response to: DSTAVERT

That's precisely why the code checks for both "3.5.0" (4th column on ESX) and "3i" (4th column on ESXi) :-)

Aug 18, 2009 6:59 PM DSTAVERT  says: in response to: zdali

The code didn't check for 3i and 3.5. When I reported a problem on the 16th the code read
if ; then VER=3

I was just going by the changelog date and assumed it hadn't changed.

My apologies for thinking that William couldn't count. ;)

Aug 18, 2009 7:09 PM lamw  says:

Okay, I see what's going on and I've pushed a 'fix' for the issue.

Looks like I had two internal versions and the one I was working on had the following (which works):

if [ "${ESX_VERSION}" == "3.5.0" ] || [ "${ESX_VERSION}" == "3i" ];


but the version that was released had the following:

if [[ "${ESX_VERSION}" == "3.5.0" || "${ESX_VERSION}" == "3i" ]];


which will not work since it's missing their brackets within each comparator. Sorry for the doozy, it should work without any further issues.

Please download the latest version of ghettoVCB.sh and thanks for you guys feedback/patience.


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Aug 18, 2009 7:11 PM penzipa  says: in response to: DSTAVERT

Here is my output

+ VM_BACKUP_VOLUME=/vmfs/volumes/Backup/VMBack_Daily
+ VMDK_OUTPUT_FORMAT=2
+ VM_BACKUP_ROTATION_COUNT=1
+ date +%F
+ VM_BACKUP_DIR_NAMING_CONVENTION=2009-08-19
+ POWER_VM_DOWN_BEFORE_BACKUP=0
+ ENABLE_HARD_POWER_OFF=0
+ ITER_TO_WAIT_SHUTDOWN=4
+ ENABLE_COMPRESSION=1
+ ENABLE_NON_PERSISTENT_NFS=0
+ UNMOUNT_NFS=0
+ NFS_SERVER=172.30.0.195
+ NFS_MOUNT=/nfsshare
+ NFS_LOCAL_NAME=nfs_storage_backup
+ NFS_VM_BACKUP_DIR=mybackups
+ DEVEL_MODE=1
+ IS_4I=0
+ ! -f /bin/bash
+ sanityCheck 1
+ NUM_OF_ARGS=1
+ ! 1 == 1
+ -f /usr/bin/vmware-vim-cmd
+ -f /bin/vim-cmd
+ VMWARE_CMD=/bin/vim-cmd
+ VMKFSTOOLS_CMD=/sbin/vmkfstools
+ awk {print $5}
+ vmware -v
+ ESX_VERSION=3.5.0
+ http:// 3.5.0 == 4.0.0
+ vmware -v
+ awk {print $5}
+ ESX_VERSION=3.5.0
+ [[ 3.5.0 == 3.5.0
sh: missing ]]
+ 3.5.0 == 3i ]]
ghettoVCB1.sh: ghettoVCB1.sh: 460: 3.5.0: not found
+ echo You're not running ESX(i) 3.5+ or 4.0+!
You're not running ESX(i) 3.5+ or 4.0+!
+ exit

Aug 19, 2009 5:01 AM aliog  says:

Great script. Has been really useful. I particularly like the new output format option.

Aug 19, 2009 6:45 AM penzipa  says: in response to: lamw

New Script works like a charm, thanks very much for the assistance

Aug 19, 2009 6:51 AM lamw  says: in response to: aliog

np. Thanks for the feedback


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Aug 19, 2009 6:51 AM lamw  says: in response to: penzipa

awesome to hear! Thanks for your feedback


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Aug 19, 2009 7:30 AM penzipa  says: in response to: lamw

Lamw is there a way to only backup the root disks? I have some VM's with disks on different datastores which I do not want to include in the backup, as they only contain user data and get backed up with a regular windows backup agent.

Aug 19, 2009 8:04 AM DSTAVERT  says: in response to: penzipa

I agree that would be a helpful addition.

For vmdks that are on different datastores it would be useful to run sed against the vmx file to remove the "/vmfs/volumes/${DS_UUID}/" so that the vmx file doesn't point to the original disk.

Really sorry that this probably keeps you up nights. I do voluntary support for a small college and I know that they really appreciate your efforts. I do as well.

Thanks

Aug 20, 2009 6:08 PM IT_Architect  says: in response to: lamw

You can easily create something similar by setting up a cronjob

When I try to do something like this work from a batch file, and schedule it, the second backup never executes.

"C:\Program Files\PuTTY\plink.exe" root@10.17.127.132 -pw MM6ufG6eg "/vmfs/volumes/datastore1/ghettoVCB/ghettoVCB4i.sh
/vmfs/volumes/datastore1/ghettoVCB/backup_list > /vmfs/volumes/nas-2/log/s2-backuplog.txt2 &"
"/vmfs/volumes/datastore1/ghettoVCB/ghettoVCB4iSingle.sh" "/vmfs/volumes/datastore1/ghettoVCB/backupSingle_list >>
/vmfs/volumes/nas-2/log/s2-backuplog.txt &"

If I do them in two separate batch files, and call plink a second time and guess how much time I need for the first one before calling the second one, these same commands work, but that's not reliable since it's tough to know how long the first one will take.

Aug 20, 2009 7:58 PM lamw  says: in response to: IT_Architect

A) You're using an old version of the script, I would highly recommend using the latest as it has fixes/updates to any previous issues/bugs.
B) If you can do this manually and it's successful, then this is an issue with your scheduling.
C) I don't know how you're scheduling them on Windows, but to avoid contention, you should schedule these to be in sequential order and as I've suggested several times, instead of manually calling each of these backups, have a script that call these two backups sequentially and all you run is just one single script which contains these two within the file.


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Aug 20, 2009 8:31 PM IT_Architect  says: in response to: lamw

>You're using an old version of the script<
The script was downloaded from here on August 6. I'll check if you have anything more current than that. It's so named to match the calls in the batch file that was created for an earlier version of the script.

>one single script which contains these two within the file<
Rather than both in the same batch file script. I could try that.

Thanks!

Aug 21, 2009 2:05 PM DSTAVERT  says: in response to: IT_Architect

T_Architect
You could add some simple conditional things to the ghettoVCB script. I add the following to the ghettoVCB script to have a weekly copy in another datastore. It wouldn't be hard for you to add other conditionals.


if [ "$(date +%A)" = "Saturday" ]; then   
VM_BACKUP_VOLUME=/vmfs/volumes/somewhere_else
else VM_BACKUP_VOLUME=/vmfs/volumes/sameplace
fi


Problem with this bit is that you would need to add it every time the script changes.

I run ghettoVCB from a script and that script generates the list of VMs to clone. I have a list of all VMs that I need to clone regardless of the host they are on "globaltobecloned". The script compares the list of VMs on the local host "currrentvms" to the globaltobecloned. If a local VM is on the globaltobecloned it is added to the local list to be cloned and that is what ghettoVCB uses. This way if I move a VM from one host to another I don't need to edit a list for each host.

# start
rm /tmp/list
vim-cmd vmsvc/getallvms | awk -F " " '{print $2}' | sed '1,1d' > /tmp/currentvms
for i in `cat /tmp/currentvms` ;do
awk -v var=$i -F, '$1==var' /vmfs/volumes/nfs-datastore/scripts/globaltobecloned >> /tmp/list
done
/vmfs/volumes/nfs-datastore/scripts/ghettoVCB.sh /tmp/list


You can repeat some of the first part of the script to generate different types of lists and add some conditional things inside ghettoVCB depending on the name of the list.

Aug 21, 2009 3:29 PM lamw  says: in response to: DSTAVERT

This will not be supported, that is what cron and other scheduling tools are for. As you've said, it's trivial to add 'your' own 'personal' modification, but when you need to support this in the general community, this task becomes much larger. Your simplest example is using a breakdown of the week M-S. What is someone wants it by the hour, that is a huge amount of conditions you're adding ... then what if someone wants it hourly or every other day except for odd months out,etc,etc...this list can get infinite and adds unnecessary logic to the backup script, which can potentially lead to other issues/bugs.

Again, I've said this several times and I'll continue saying it, the purpose of this script is to provide a free generic backup solution that individuals can utilize in their ESX(i) environment. Any other requirements that fall outside of the actual backup process, users are more than welcome to modify/customize the script to fit their needs/requirements in their environment. You can easily set this up using cron and executing various scheduled backups and why re-invent the wheel when a tools such as cron or Windows scheduler is available?

Thanks for sharing your work but this feature will not be integrated into the script.

=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Aug 22, 2009 7:31 AM DSTAVERT  says: in response to: lamw

I had no intention of suggesting that this be included at all. My comments were directed at IT_Architect who had posted a few steps back that they wanted different datastores and different outcomes. I appreciate the basic nature of the script and wouldn't want it to become otherwise. I was saddened by the need to accommodate spaces in VM names but such is life.

Thanks.

Aug 22, 2009 2:07 PM IT_Architect  says: in response to: DSTAVERT

I run ghettoVCB from a script and that script generates the list of VMs to clone...This way if I move a VM from one host to another I don't need to edit a list for each host.

Great idea! In my situation, I have two servers that cross-backup to each other, each with a Windows VM with a NAS on a second virtual disk for the backups. Backing up the two Windows VMs then becomes a special case where I must only backup the first virtual disk to avoid storing backups of backups on the host they came from. Thus, I made copy of the ghetto script and added a break to the virtual disk loop. After the restore of a Windows VM and before starting it, one must first delete the second virtual disk and then re-add it. The procedure works perfectly and there are no issues.

Against all logic and after several attempts, I was unable to come up with a syntax that would enable both backups to execute when stacked in a batch file. Adding an intermediate script as suggested did fix the problem and made the batch file syntax a lot less touchy.

Thanks all!

Aug 24, 2009 2:20 PM cyberfire  says:

Where is the ghettoVCB4i file download?

Aug 24, 2009 2:22 PM lamw  says: in response to: cyberfire

Please download the latest version of the script on this document which is just ghettoVCB.sh. Take a look at the change log for more details on the updates.


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
http://twitter.com/lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Aug 26, 2009 5:57 AM Anonymus07  says:

Hey Lamn!
Your script is really nice!! Thanks a lot for it!

Now to my little problem:
Situation as it is now: I'm using an ESXi 3.5 153875. I edited the /var/spool/cron/crontabs/root as mentioned by you (see below). And i asured that it would survice a reboot.
If I start yout script manually it works fine.
But if the crond runs your script I got the following output in /var/log/messages
_______________________
Aug 25 23:55:01 crond1472: USER root pid 124920 cmd /vmfs/volumes/volume01/ghettoVCB.sh /vmfs/volumes/volume01/backuplist 2>&1 | busybox logger -t ghettoVCB4i -p 1
Aug 25 23:55:01 crond1289: USER root pid 132147 cmd /vmfs/volumes/volume01/ghettoVCB.sh /vmfs/volumes/volume01/backuplist 2>&1 | busybox logger -t ghettoVCB4i -p 1
_______________________
If I now do a 'ps|grep cron*' I get this: 1289 1289 busybox crond

What is this second crond with PID 1472??? And why does it always start just nanoseconds after the 'real'(?!) crond with PID 1289?

I observed that this second crond is also comming up with another task defined in the crontab.
________________________
Aug 26 14:40:01 crond1289: USER root pid 360693 cmd /sbin/decodeSel.sh #Every 10 minutes, translate the latest IPMI SEL data
Aug 26 14:40:01 crond1472: USER root pid 360695 cmd /sbin/decodeSel.sh #Every 10 minutes, translate the latest IPMI SEL data
________________________

Here's my crontab as it is right now:
________________________
#syntax : minute hour day month dayofweek command
01 01 * * * /sbin/tmpwatch.sh
01 * * * * /sbin/auto-backup.sh #first minute of every hour (run every hour)
00,10,20,30,40,50 * * * * /sbin/decodeSel.sh #Every 10 minutes, translate the latest IPMI SEL data
01 * * * * /sbin/vmwarerootwatch.sh #first minute of every hour.
55 23 * * * /vmfs/volumes/volume01/ghettoVCB.sh /vmfs/volumes/volume01/backuplist 2>&1 | busybox logger -t ghettoVCB4i -p 1
________________________

Do you have a clue why this second crond is running? It's causing me massive problems with my backups! The script runs twice but there's just one backup and even worse the backuprotation routine is used twice --> so there's just one backup left instead of three.

Hope you can provide me with some ideas!
Best regards
Grimes

Aug 26, 2009 6:50 AM lamw  says: in response to: Anonymus07

I recommend you change the time of your backup so you don't run into these issues. The IPMI deals with health monitoring of the server and this is a default script from VMware and would not recommend modifying/changing it.


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Aug 28, 2009 1:00 PM etpelle72  says: in response to: lamw

(ESXi)
The script seems to backup okay, but it always hangs at "Removing snapshot". The code loops looking for a file with the word "delta" in it. This file is never created though so the loop is infinite. At least that is what the problem seems to be. Am i the only one having this problem?

Aug 28, 2009 7:10 PM lamw  says: in response to: etpelle72

That's actually incorrect, what the script does is takes a snapshot in which a *-delta.vmdk should be created, upon successful backup, the script will remove the snapshot. You're right that there is a loop but it will only loop if it continues to find a file in the VM directory with name "delta".

When you kick off the script, is the snapshot being taken? Can you verify that it has been removed? It could be the case that your snapshot is very large and it's taking some time to commmit the changes. Is this the only VM with issues? Can you provide some background on this specific VM? Size? Are the VMDK(s) all located within the same datastore, do you have them spanned over multiple datastores?

When commenting on an issue, please be diligent in providing additional information other than "its not working" so that I can further assist. Thanks


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Aug 29, 2009 8:22 AM DSTAVERT  says: in response to: lamw

I would like to propose for consideration that ghettoVCB use a configuration file that was fed on the command line. All editable variables would be contained in the config file. Multiple config files could be used for different destinations, different backup lists, different nfs stores etc. One script could satisfy any host or destination and no direct editing of the script.

Aug 29, 2009 12:24 PM IT_Architect  says: in response to: DSTAVERT

One small tweak I made is to move the start time to a couple different places to include the time to make the snapshot. The log still ends up looking the same.

Aug 31, 2009 9:44 AM etpelle72  says: in response to: lamw

I just tried it again and it seems to be working. I have no idea what I did differently, but it looks good. The only thing is I never see the "-delta.vmdk" mine are named "-0001.vmdk". And the removing snapshot didn't take long at all, and the snapshot files were indeed removed.

Sep 1, 2009 12:29 PM clone0326  says:

What is the process for deleting unwanted backups? I've tried deleting them through the NFS store machine, through the ssh connection, and with WinSCP and no matter what it tells me access is denied or that the file is in use. It doesn't matter if I've unshared the store. Any ideas?

Sep 3, 2009 1:45 AM jonasb  says:

Since we often create new machines and move machines around between ESX:es we want to make sure ALL machines present on the ESX are backed up. Is there any way (or plan) to enable the script to backup ALL machines running on the ESX rather then the need to specify all VMs manually (like putting "ALL" or "*" in the server list file).

Sep 3, 2009 8:37 AM DSTAVERT  says: in response to: jonasb

jonasb
I have that problem as well. I now use a generic script script directory that all ESXi hosts have access to. I use a generic script that I add to the rc.local on each host. That script generates a new ghettoVCB launch script specific to that ESXi host. The launch script first generates the list of guests to backup. I have a global list of machines to clone and the launch script compares the global list to the local list. If a local machine is on the global list I add it to the daily backup list and then launch ghettoVCB using that daily list.

Just a simple script (no error checking or provisions for spaces in names) that would create a local list.

vim-cmd vmsvc/getallvms | awk -F " " '{print $2}' | sed '1,1d' > /tmp/local_vms
ghettoVCB.sh /tmp/local_vms

Sep 7, 2009 12:41 AM scowse  says:

Thanks lamw and others for ghettoVCb - after getting all the errors listed on this page it is now running like a dream.

I have several large (500GB+) vms on ESXi and use ghettoVCB to backup to a 2003 NFS ds. Obviously this takes many hours so i installed rsync (daemon mode) and this also works well manually.

Being a noob as well as being a bit thick I would ask for some assistance to hack rsync into ghettoVCB since the cloning only really needs to be done once - differences after that. I can see that i do not need rotation anymore but i still need snapshotting.

Anyone done this?

Sep 8, 2009 12:54 PM SIFTU  says:

I am having a problems running the script (ESX 3.5). I downloaded it via lwp-download, set it to execute and get the following when I try to run it.

root@virt-07 xxx# ./ghettoVCB.sh
: command not founde 5:
: command not founde 8:
: command not founde 15:
: command not founde 18:
: command not founde 20:
: command not founde 21:
: command not founde 26:
: command not founde 29:
: command not founde 34:
: command not founde 37:
: command not founde 42:
: command not founde 44:
: command not founde 47:
: command not founde 50:
: command not founde 53:
: command not founde 56:
: command not founde 58:
: command not founde 59:
: command not founde 61:
: command not founde 63:
: command not founde 65:
'/ghettoVCB.sh: line 66: syntax error near unexpected token `{
'/ghettoVCB.sh: line 66: `printUsage() {

Each of the lines mentioned is a blank line. Anyone got any ideas?

Sep 9, 2009 12:06 AM fqu89  says: in response to: SIFTU

I think it's because the ghettoVCB.sh file is in DOS format (with ^M characters at the end of each line)

Sep 9, 2009 9:09 AM SIFTU  says: in response to: fqu89

yes you are correct, I ran the script through dos2unix on a linux machine and it now works. Isnt this script designed to be run on a linux system anyway? Why would it be in dos format?

Sep 9, 2009 6:49 PM lamw  says: in response to: SIFTU

The method in which you downloaded the script using lwp-download probably caused the ^M character to show up versus LF. The script by default will work off the bat if downloaded properly and edited within ESX(i) console.


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Sep 10, 2009 9:21 AM Rob98  says:

Great Script, thank you. Though I am having some difficutly getting it to work properly while scheduled with cron.

Running ESXi 4.0 - duplicated on two different machines.

If I run the script manually, exaclty copying the command I have in the crontab, everything runs OK and completes OK.

However, when the job is run from cron, it fails to remove the snapshot and then of course subsequent jobs will not run. Also the backup folder is missing the --x naming and the old backups in the rotation are not deleted. The backup log for the job is question shows - "removing snapshot", and there is a large number of additional backup logs saying "snapshot found, backup will not take place".

If i go into the vSphere client the snapshot is not visible to delete until I restart the management services. Then the snapshot appears as "Consolidate Helper 0". When I delete the snapshot, the log changes to "Complete backing up...." with a duration of the time between the scheduled start and when I deleted the snapshot. Also the backup is then named with the --x and the rotation is completed.

So it looks like for some reason the process is unable to delete the snapshot and waits until it is manually deleted before finishing, though I don't know why the other logs are appearing.

Sep 11, 2009 2:13 AM cwkoh  says:

I need to only backup the first harddisk which has the OS using the ghettoVCB script. I read earlier version can do this. Is there any way to do the same with the current version of the script? Anybody can help?

Sep 11, 2009 3:00 AM vlho  says: in response to: Rob98

Hi all,
I have same problem as Rob98

Sep 11, 2009 8:25 AM thinami  says: in response to: lamw

Are the compressed backups not supposed to be overwritten after a certain number of days specified in the file? I have noticed that the compressed files just continue on.

Sep 11, 2009 8:51 AM lamw  says: in response to: cwkoh

Nope, you miss-read, this is not a supported feature.


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Sep 11, 2009 8:51 AM lamw  says: in response to: thinami

It should be rotating based on your rotation settings, default 3 backups before removing older backups.


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Sep 11, 2009 8:52 AM lamw  says: in response to: Rob98

Are you running the latest version of the script? If it works manually it should work, verify that your cronjob has been setup correctly.


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Sep 11, 2009 9:04 AM thinami  says: in response to: lamw

It is not working for compressed files. I have it set to 3 and I have 11 backups for one vm showing.

Sep 11, 2009 9:33 AM Rob98  says: in response to: lamw

AFAIK it is the latest version of the script. I downloaded it from the link on this page, thought the date at the top of the script is 11/01/2008.

My cronjob is as follows(minus the quotes):

"* 22 * * * /vmfs/volumes/datastore1/ghettoVCB.sh /vmfs/volumes/datastore1/ghettobackups > /vmfs/volumes/datastore1/ghettoVCB-bakcup-$(date +\%s).log"

Sep 11, 2009 10:44 AM lamw  says: in response to: thinami

I'm confused by your recent comment, your original post asked about 'compressed files' and now you're saying you're not using compression? Are you or are you not enabling compression on the backups? If the answer is no, then it should rotate properly. Also a note, if you try to manually delete backups, you could screw up the counters. I would suggest trying to a new backup and perhaps move the current backups to another folder and change the value of rotation to see if it's working properly.


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Sep 11, 2009 10:46 AM Rob98  says:

I've come acrros another issue as well. I have a newly createed linux VM, with a thin provisioned 40GB disk. Currently it is using 2.7 GB. When I run the script, with the option set to thin provisioned and backing up to a SFU 3.5 NFS server, the backup still comes out to 40GB.

Sep 11, 2009 11:14 AM thinami  says: in response to: lamw

Sorry. Bad use of words. I said it is not working FOR compressed files. I am not deleting files manually but will clear out the folder and start out with a fresh run.

Sep 11, 2009 1:59 PM lamw  says: in response to: Rob98

Please re-read this document and specifically the change log on Update (08/08/2009)


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Sep 13, 2009 11:21 AM winterg  says: in response to: Rob98

It depends on where you view the files as to whether you see the true size. I had the same problem, but I was looking at the files under the shell using ssh. The shell displays the size that it could expand to over time. If you browse the data store using the vSphere client, you will see the true size stored.

Sep 13, 2009 11:47 AM winterg  says: in response to: Rob98

So, I am having the same problem where a Snapshot gets stuck in the system using the cron job and fails every night. I can run the script manually and everything runs fine, but it only backs up once and then fails due to an existing snapshot. One thing I noticed was 60 log files for each day the cron job tried to run. The cron and crontab discussion above may be in error. If you want it to run once a day during the week at a certain time the entry above says:

"* 0 * * 1-5"

but in reality that means to run it every minute with an hour that equals 0. So it will run at 12:00, 12:01, 12:02, etc. I'm not positive, but I think the problem with the extra snapshot may be due to multiple instances running 60 seconds apart. Shouldn't it be:

"01 0 * * 1-5"

Which would run one time at 12:01 AM? I'll let you know if it resolves the snapshot issue I was having similar to Rob98.

Sep 13, 2009 1:44 PM vlho  says: in response to: winterg

Hi winterg,
yes, you're right, however I have setting the cron like this:
5 4 * * 2-6
and I have problem as Rob98 still.
I am not sure but i think that cron job worked without any problems if not exist previous backup directory...

Sep 13, 2009 4:18 PM Rob98  says: in response to: vlho

Yeah, I think vlho is on to something. I tried the cron with the minute specifed, but that didn't sovle the problem. Then I noticed that my file listing the vm's had a blank line in it. So I recreated the file making sure there where no blank lines. I thought this had fixed the problem as the first scheduled backup ran fine. However, subsequent ones failed and I beleive I changed the output format at the same time as I recreated the backup list, which would have caused it to start the backups fresh. So the first backup succeded, but everything since then has changed. I'll try changing the backup format again on one of my machines and see what the result is.

Sep 13, 2009 8:38 PM winterg  says: in response to: Rob98

So it still leaves the -delta and -00001 files behind in the consolidate-helper snapshot, preventing future backups. So, a little more about my set-up:

  • I'm running ESXi 4.0 free and backing up one Guest server running Windows 2000 server.

  • I converted from a thick to a thin provisioned disk on the VM guest after creation. So it is a thin provisioned disk that is backed up to a thin provisioned backup image stored on a locally attached datastore (External Sata drive).

  • I was backing up the Guest Windows 2000 server without shutting down the server.

  • I am not using compression, because it doesn't work for me under ESXi 4.0 (a separate issue).

I also have an NFS NAS and am working on setting that up now. I'm testing with the guest shutting down now and suspect it will work. I'm just curious why it will not work while running.

My testing did confirm that the crontab entry in the text near the top of this page needs corrected to include a number for the minute in the first column of the crontab entry, otherwise it will run on every minute in the selected hour.

Sep 14, 2009 6:21 AM vlho  says: in response to: winterg

Hi all,
one relevant thing

I see in my logs (/var/log/messages etc.) this records:
Sep 10 04:05:01 crond5319: USER root pid 3976380 cmd /vmfs/volumes/local/_prog/ghettoDS ...
Sep 10 04:05:01 crond5287: USER root pid 3980501 cmd /vmfs/volumes/local/_prog/ghettoDS ...

I don't see why job run twice but I'd say he that this is reason for described problem.
File /var/spool/cron/crontabs/root contains only this lines:
#syntax : minute hour day month dayofweek command
01 01 * * * /sbin/tmpwatch.sh
01 * * * * /sbin/auto-backup.sh #first minute of every hour (run every hour)
5 4 * * 2-6 /vmfs/volumes/local/_prog/ghettoDS ...

Any idea?
Thanks.

Sep 14, 2009 9:57 PM winterg  says: in response to: vlho

So, based on your reply, I checked the processes running via the ssh console using ps -c | grep crond. The output is:

5120 5120 busybox crond
5141 5141 busybox /bin/busybox crond -b

I think the rc.local entry above in the article might be in error. I don't think "crond -b" is accomplishing the intended goal. It appears to run a second copy of crond, which may be causing the problem. I'm testing again with only one copy runnning. I deleted the crond -b from the rc.local and instead did a kill -HUP (process id of crond) to re-read the crontab file. I'll let you know how it turns out.

Shutting down the guest O/S avoided the problems with the snapshot lingering, but I'd rather leave the guest running.

Sep 14, 2009 11:00 PM winterg  says: in response to: vlho

So, after manually killing both crond processes and starting only one copy seemed to work this time. If I didn't kill off both, the old crond did not re-read the crontab file into memory. So, how do we modify the /etc/rc.local entries above to adjust for this? One thought is to get rid of the crond -b in the rc.local and kill the original crond only to restart it immediately using the following in rc.local:

kill `cat /var/run/crond.pid` ; crond

I haven't tried this yet, but will add it in and see what happens tomorrow.

Sep 15, 2009 10:32 PM lamw  says: in response to: winterg

Thanks for all your investigations, been really busy these last few days. I think that definitely makes sense and you're right when you issue crond -b (-b runs in the background, which you probably want when restarting), creates another cron daemon process. Let me know what you end up finding out and I'll be more than happy to update the documentation.

The line you probably want to add at the end of rc.local including the cron job is:

kill $(cat /var/run/crond.pid)
crond -b


You can also probably just search for all crond running and kill those prior to restarting using ps ef, but assuming you're not manually touching the system, what you've provided should work.

Also here is a list of options to crond if you're not aware of already:

~ # busybox crond --help
BusyBox v1.9.1-VMware-visor-654 (2008-12-17 10:01:32 PST) multi-call binary

Usage: crond -d[#] -c crondir -f -b

        -d [#] -l [#] -S -L logfile -f -b -c dir
        -d num  Debug level
        -l num  Log level (8 - default)
        -S      Log to syslog (default)
        -L file Log to file
        -f      Run in foreground
        -b      Run in background (default)
        -c dir  Working dir


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Sep 16, 2009 1:09 AM vlho  says: in response to: winterg

Hi winterg
your solution is works (only ESXi 4), thanks !

For ESXi 3.5 you usage:

kill `pidof crond` ; crond -b

Sep 16, 2009 8:09 AM vlho  says: in response to: vlho

Hi all,
next option for restart crond

kill -HUP `pidof crond`
i.e. without crond -b

I think that this is better and cleaner than the last...

Sep 16, 2009 8:52 AM winterg  says: in response to: vlho

Either works fine to kill the running process, I'm just glad it works. It has run two nights in a row without fail. I restart crond without the -b for two reasons:

  • The -b is already the default behavior without the switch
  • the original process that is started doesn't use it and I wanted it to mirror what VMware was doing at start-up.

Hopefully lamw will update the article text for the crontab time entry (to include the minute) and the restart of crond so that others don't suffer the same issues.

Now on to my next issue... Does anyone have compression working on ESXi 4.0 free? It fails every time I enable compression. I haven't looked into it yet as I needed to fix the bigger problems first and wondered if anyone else had it working.

Sep 16, 2009 3:47 PM scowse  says: in response to: winterg

I can confirm that compression works without problems in esxi 4.0.0 181792 but I do not use it because of the extra time it adds to the backup process. You don't say what the error is?

Sep 16, 2009 3:56 PM lamw  says: in response to: winterg

winterg, thanks for all the feedback and work you've put in, I'll update the document tonight if I get some time.

Regarding compression, it should work, I know few people out there that are using it including my colleague in UCSB ;) What issues are you having? Can you elaborate?


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Sep 16, 2009 9:12 PM winterg  says: in response to: lamw

So every time I try to backup I get the following. There is plenty of storage available according to df -k.

"################ Taking backup snapshot for hostname.temp-dom.local ... ################"
Start time: Thu Sep 17 03:36:16 UTC 2009
Destination disk format: VMFS thin-provisioned
Cloning disk '/vmfs/volumes/SAS-Datastore1/hostname.temp-dom.local/hostname.temp-dom.local.vmdk'...
Clone: 100% done.
Removing snapshot from hostname.temp-dom.local ...
Compressing VM backup "/vmfs/volumes/External-eSata1/host-backups/hostname.temp-dom.local/hostname.temp-dom.local-2009-09-17.gz"...
tar: cannot store file 'hostname.temp-dom.local-2009-09-17/hostname.temp-dom.local-flat.vmdk' of size 107389255680, aborting
End time: Thu Sep 17 03:49:09 UTC 2009
"#################### Completed backup for hostname.temp-dom.local! ####################"

Start time: Thu Sep 17 03:36:13 UTC 2009
End time: Thu Sep 17 03:49:09 UTC 2009
Duration : 12.93 Minutes

Completed backing up specified Virtual Machines!

I cleaned out the destination directory to make sure no other backups where in the system.

Sep 16, 2009 9:13 PM lamw  says: in response to: winterg

I would suggest in the future if you post output to wrap it in code tags, makes it much more readable :)

Regarding thin provisioning, take a look at my response back on Aug 6:

I think there has been quite a bit of confusion on Thin Provisioning, not only with this script which has supported this feature for awhile but also in the general forums.

Within the guestOS, it may show free/unsused space but it does not mean that blocks have not been allocated in the past that could have used up more space than it's showing. Remember, when you delete something, you're just not referencing it anymore, it's still there. Blocks within the OS needs to be zeroed out and this is explained in detail from Mr. 007 himself Duncan Epping at: http://www.yellow-bricks.com/2009/07/31/storage-vmotion-and-moving-to-a-thin-provisioned-disk/

Thin provisioning does work using vmkfstools but you need to ensure you've zeroed out any unused blocks before actually see this when trying to backup or even convert a VMDK.

Hopefully this clears things up

Now onto the compression, it looks like the compression is in fact starting, but it fails to store the backup. If you still have the backup, can you see if you can manually compress it? I've not seen this error before but it may be complaining about the size of the file, perhaps a limitation in the version of tar in ESX (would not surprise me). Secondly, are you backing this up to a VMFS volume? What is the blocksize you've set, remember that blocksize on a given volume will dictate how a big a file can be and you want to make sure you're not exceeding any of those limits.

I should be updating the documentation regarding the cron information but unfortunately our development system is down at moment for some new hardware upgrades and I want to confirm a few things before posting the changes, depending if it's up later tonight, the post may be postponed till tomorrow.


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Sep 19, 2009 8:48 AM kanngoo  says: in response to: winterg

hello,

i use esxi 4.0 and want to set up the cronejob correct. when i use the script manual it woks fine.
when i make a cronjob now an then add the necessary lines in the /etc/rc.local is this example correct?

~ # cat /etc/rc.local
#! /bin/ash
export PATH=/sbin:/bin

log() {
echo "$1"
logger init "$1"
}

#execute all service retgistered in /etc/rc.local.d
if http:// -d /etc/rc.local.d; then
for filename in `find /etc/rc.local.d/ | sort`
do
if -f $filename && -x $filename ; then
log "running $filename"
$filename
fi
done
fi

/bin/echo "* 0 * * 1-5 /vmfs/volumes/simplejack-local-storage/ghettoVCB.sh /vmfs/volumes/simplejack-local-storage/backuplist > /vmfs/volumes/simplejack-local-storage/ghettoVCB-backup-\$(date +
%s).log" >> /var/spool/cron/crontabs/root
/bin/busybox crond -b

kill `cat /var/run/crond.pid` ; crond

Sep 19, 2009 9:46 AM lamw  says: in response to: kanngoo

Please always use code tags to wrap your console output, makes reading much easier.

I haven't had time to update the document with the latest changes mentioned in the last few replies, I'm currently out of town.

Regarding the changes for cron to work, you need to first kill the cron daemon first ... then issue the updates and restart (without -b)

kill $(cat /var/run/crond.pid)
/bin/echo "* 0 * * 1-5 /vmfs/volumes/simplejack-local-storage/ghettoVCB.sh /vmfs/volumes/simplejack-local-storage/backuplist > /vmfs/volumes/simplejack-local-storage/ghettoVCB-backup-\$(date +
%s).log" >> /var/spool/cron/crontabs/root
/bin/busybox crond 


You may also want to specify the full path to where kill is located it at, I believe it might be in /bin

=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Sep 21, 2009 8:59 PM chayawatv  says:

I try to use this scipt to do backup with compression enabled.
Howerver, I cannot uncompress "filename".gz as it show "tar: Invalid tar magic".

Currently, I use ESX 3.5i U4 free edition and backup it to local drive of ESX server itself.

Any thought about the issue?

Thank you

Sep 21, 2009 11:06 PM lamw  says: in response to: chayawatv

Can you please provide the full command you're using to uncompress the backup?


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Sep 21, 2009 11:26 PM chayawatv  says: in response to: lamw

1.) # gunzip < /vmfs/volumes/datastore1/backup/vm1/vm1-2009-09-22--1.gz | tar xvf - -C /vmfs/volumes/datastore1/restore

and

2.) # gunzip < /vmfs/volumes/nfs/backup/vm1/vm1-2009-09-22--1.gz | tar xvf - -C /vmfs/volumes/datastore

I try to backup and uncompress in 2 scenarios 1.) on local hard disk, 2.) on nfsshare
both give me "tar: Invalid tar magic"

Thank you

Sep 22, 2009 6:58 AM lamw  says: in response to: chayawatv

Perhaps tar changed between ESXi 3.5u4 and ESXi 4.0 .... I would need to replicate this in our dev environment and see what I get. I'll get back to you on this one, need to find some free cycles to test.

Thanks for reporting this.


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Sep 22, 2009 10:16 AM kanngoo  says: in response to: kanngoo

hi,

backup and cronjob with esxi 4.0 works great.

thanks
kanngoo

Sep 22, 2009 7:53 PM lamw  says: in response to: kanngoo

Thanks for the comments and glad it's working!


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Sep 22, 2009 9:48 PM lamw  says: in response to: chayawatv

Interesting, it works for me on ESXi 3.5u4

~ # vmware -v
VMware ESX Server 3i 3.5.0 build-153875

~ # gunzip < /vmfs/volumes/datastore1/WILLIAM_BACKUPS/test/test-2009-09-22--1.gz | tar xvf - -C /vmfs/volumes/datastore1/
test-2009-09-22/
test-2009-09-22/test.vmx
test-2009-09-22/test-flat.vmdk
test-2009-09-22/test.vmdk


I executed this at the root of Busybox and it works perfectly fine for me.

What version of gunzip and tar is displaying for your version of ESXi?

~ # gunzip -v
gunzip: invalid option -- v
BusyBox v1.2.1 (2008.06.26-17:58+0000) multi-call binary

Usage: gunzip [OPTION]... FILE

Uncompress FILE (or standard input if FILE is '-').

Options:
        -c      Write output to standard output
        -f      Force read when source is a terminal
        -t      Test compressed file integrity


~ # tar -v
BusyBox v1.2.1 (2008.06.26-17:58+0000) multi-call binary

Usage: tar -[czxtvO] [-f TARFILE] [-C DIR] [FILE(s)] ...

Create, extract, or list files from a tar file.

Options:
        c               create
        x               extract
        t               list

Archive format selection:
        z               Filter the archive through gzip

File selection:
        f               name of TARFILE or "-" for stdin
        O               extract to stdout
        C               change to directory DIR before operation
        v               verbosely list files processed


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Sep 23, 2009 8:41 AM Kabs123  says:

Hi William,

thank you for the nice script. There is just something wrong with my settings. Can you help me please?
I get the following message, what does it mean:

DEVEL_MODE=0

printUsage() {
SCRIPT_PATH=$(basename $0)
echo -e "\nUsage: ${SCRIPT_PATH} VM_FILE_INPUT\n"
/vmfs/volumes/4a3bec10-5b0ef122-e3cb-001777642eb1/backupscript # ./ghettoVCB.sh vmbackups
(vim.fault.AlreadyExists) {
dynamicType = <unset>,
faultCause = (vmodl.MethodFault) null,
name = "/vmfs/volumes/b22ca6b3-931cd49f",
msg = "The specified key, name, or identifier already exists.",
}
Snapshot found for xvm3_1, backup will not take place

Sep 23, 2009 1:43 PM lamw  says: in response to: Kabs123

It looks like the error is:

Snapshot found for xvm3_1, backup will not take place 


Please take a look at FAQ #10


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Sep 23, 2009 5:38 PM cookieme  says: in response to: lamw

Is it possible to remotely kick-off the script from an Ubuntu VM with vCLI installed instead of enabling SSH through the unsupported mode? The reason I'm asking is that with your ghettoVCBg2 script you are using the vMA which has vi-fastpass for authentication and so does not require SSH. So without vMA and fastpass is there a command in the vCLI that can run the script located on the local datastore or shared storage although it might prompt for credentials?

Thanks

Sep 23, 2009 7:27 PM chayawatv  says: in response to: lamw

Hi,

here is my VMWare Version
~ # vmware -v
VMware ESX Server 3i 3.5.0 build-153875

Here is my tar and gunzip version

~ # tar -v
BusyBox v1.2.1 (2008.06.26-17:58+0000) multi-call binary

Usage: tar -czxtvO -f TARFILE -C DIR FILE(s) ...

Create, extract, or list files from a tar file.

Options:
c create
x extract
t list

Archive format selection:
z Filter the archive through gzip

File selection:
f name of TARFILE or "-" for stdin
O extract to stdout
C change to directory DIR before operation
v verbosely list files processed

~ # gunzip -v
gunzip: invalid option -- v
BusyBox v1.2.1 (2008.06.26-17:58+0000) multi-call binary

Usage: gunzip OPTION... FILE

Uncompress FILE (or standard input if FILE is '-').

Options:
-c Write output to standard output
-f Force read when source is a terminal
-t Test compressed file integrity

This is error what I get:
~ # gunzip < /vmfs/volumes/datastore2/backup/vm01/vm01-2009-09-24--1.gz | tar xvf - -C /vmfs/volumes/datastore2/
vm01-2009-09-24/
vm01-2009-09-24/vm01.vmx
vm01-2009-09-24/vm01-0-flat.vmdk
tar: Invalid tar magic

I set disk format as "VMFS Thick". Not sure whether it relates to the issue.

Thank you very much for you time on this matter.

Sep 23, 2009 7:32 PM lamw  says:

Thought I share with everyone that ghettoVCB just hit 100,000+ views! Thanks to everyone for their contributions, comments and use of the script!

http://img44.imageshack.us/img44/1553/ghettovcb100k.png


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "he

Sep 23, 2009 10:11 PM lamw  says: in response to: cookieme

You're posting in the wrong forum, this is not ghettoVCBg2 forum and No you can not. The script is written specifically to work with vMA and vi-fastpass.


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Sep 23, 2009 10:23 PM lamw  says: in response to: chayawatv

Nope, the VMDK format does not matter with respect to extracting the contents. Curious, how big is the VM that you backed up and how big is the file after compression?

Not sure what to tell you, it works fine on our system ... the only thing I can think of is there might be a size limitation when trying to extract from within Busybox and it would not surprise me at all if this was a tar limitation within Busybox confines.


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Sep 23, 2009 10:28 PM chayawatv  says: in response to: lamw

tar size is 8 GB

backup size after compression is around 750 MB

Sep 23, 2009 10:35 PM lamw  says: in response to: chayawatv

Let me create a dummy VM that is 8GB using eagerzeroedthick and try backing it up with compression enabled and see if I run into the same issue. Post back shortly


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Sep 23, 2009 11:57 PM chayawatv  says: in response to: lamw

Hi,
I just recreate dummy VM with 2 GB size do backup with compression. it is running smooth without a problem. So, I think the problem as you mentioned about tar file size limitation.

I will try to find server to put VMWare ESX 4 and try whether will give me the same issue. And, will let you know the result.

Thank you very much for your assistance.

Sep 24, 2009 5:12 AM Kabs123  says:

Unfortunately the backup does not work properly for me.
The only file that gets copied by backup process is the *.vmx file.
The second problem is, that there will no further backup take place when there already exists one *.vmx copy.
The error message i get:

Error: failed to lookup testvm!

It would be great if you could help me.

Sep 24, 2009 6:58 AM lamw  says: in response to: Kabs123

Please take a look at FAQ #9 and also edit the script and look for the variable DEVEL_MODE and change that from 0 to a 1 and provide the output and remember to wrap the output from the console using code tags to make it readable.


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Sep 24, 2009 8:10 AM Kabs123  says:

(vim.fault.DuplicateName) {
dynamicType = <unset>,
faultCause = (vmodl.MethodFault) null,
name = "nfs1-vol1",
object = 'vim.Datastore:nfs1.cad:/vol/vol1/data/esx-datastore',
msg = "The name 'nfs1-vol1' already exists.",
}
##########################################
Virtual Machine: testvm
VM_ID: 80
VMX_PATH: /vmfs/volumes/datastore2/testvm/testvm.vmx
VMX_DIR: /vmfs/volumes/datastore2/testvm
VMX_CONF: testvm/testvm.vmx
VMFS_VOLUME: datastore2
##########################################

Start time: Thu Sep 24 16:57:42 UTC 2009
End time: Thu Sep 24 16:57:43 UTC 2009
Duration : 1 Seconds

Completed backing up specified Virtual Machines!

Sep 24, 2009 2:06 PM ralfoertner  says:

Excuse me if that isn't the right way to ask such a simple question but I did not find another way.
The only downloadable version of ghettovcb on this page is dated on 11/01/2008.
Is that truely the latest version esx-i 4?
I've been searching high and but could not find an newer one to download.
Once again I hope tah this was the right place to ask such a question

Sincerely
Ralf Oertner

Sep 24, 2009 2:08 PM DSTAVERT  says: in response to: ralfoertner

The download link is for the latest version.

Sep 24, 2009 2:34 PM ralfoertner  says: in response to: DSTAVERT

Thank you for your quick reply.
The link is located before the known issues section.
Underneath the "Attachment" Section.
Is that the right link?

Sorry my question may sound stupid but I am truely confused about that.

Ralf Oertner

Sep 24, 2009 2:37 PM DSTAVERT  says: in response to: ralfoertner

There is only one download link.

Sep 24, 2009 8:22 PM lamw  says: in response to: Kabs123

So nothing from the output is showing me there were any errors and if you look at the duration it was pretty quick to finish and I can see that all the params were validated. So, my question, is there an actual VMDK that is valid and attached to this VM?

Also when I mentioned code tags, there were specific ones for the Jive forums, take a look at this page: http://communities.vmware.com/markuphelpfull.jspa


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Sep 25, 2009 5:42 AM Kabs123  says:

Problem cleared, i have deleted accidently a " in the source code and a part of the script has been commented out.
Thank you for support.

Sep 25, 2009 12:54 PM DSTAVERT  says: in response to: Kabs123

I think I have found an issue with huge notes in Annotations. I downloaded the ntop appliance and the output from vim-cmd vmsvc/getallvms generates a bunch of junk lines. I haven't been able to test the script and it may not affect anything. The output looks like:


"112";"ntop";"[storage]";"ntop/ntop.vmx"
"       VirtualAppliances.net NTOP Appliance for realtime network monitoring.";"";""
"       To monitor your network's traffic usage, simply start this appliance.";"";""
"       It will automatically begin collecting traffic statistics from your";"";""
"       network.  To view statistics, simply use your web browser to visit";"";""
"       the NTOP interface at http://ntop.local.:3000 or the IP Address given";"";""
"       on the console.  NTOP is excellent for collecting statistics for ";"";""
"       trouble shooting your network as well as longer range monitoring and";"";""
"       planning activities.  Visit http://ntop.org for more information about";"";""
"       the ntop application. Community support available at http://forums.virtualappliances.net ";"";""

Sep 25, 2009 9:54 PM lamw  says: in response to: DSTAVERT

Yes, annotations with the VM will cause the input to be captured when dumping out all VM(s), it'll pretty much fail on the lines where it contains the annotation since each line is suppose to represent a VM entry.


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Sep 26, 2009 8:19 AM DSTAVERT  says: in response to: lamw

Did finally get to test it and at least in my test environment it doesn't appear to affect anything. Screen output doesn't seem to be affected either. Sorry to have caused unnecessary concern.

Sep 27, 2009 3:11 AM gbras  says:

Hi,
I need to do a small modification to the script, to skip both virtual and Physical RDMs (I need the VM backed up but not the RDMs).

I'm going to change this bit of code:
\{code\}
#support for vRDM and deny pRDM
grep "vmfsPassthroughRawDeviceMap" "${SOURCE_VMDK}" > /dev/null 2>&1
\{code\}

with this:
\{code\}
#support for vRDM and deny pRDM
grep "RawDeviceMap" "${SOURCE_VMDK}" > /dev/null 2>&1
\{code\}

Is this OK?

Thank you
Guido

Sep 27, 2009 12:32 PM lamw  says: in response to: gbras

You can do that OR you can just deny both types of RDMs: physical and virtual by doing the following:

grep -E '(vmfsPassthroughRawDeviceMap|RawDeviceMap)' "${SOURCE_VMDK}" > /dev/null 2>&1


This is an extended grep which allows you to use an OR type statement to look for multiple strings and in this case, you want to deny any disks that are pRDM or vRDM.

When you display code on the forums, you don't need to escape the "{" when wrapping your output using the code tags.

=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Sep 27, 2009 8:32 PM chayawatv  says: in response to: chayawatv

run backup with this script on ESX 4.0.
Have no problme so far.

Thanks

Sep 28, 2009 1:41 PM ralfoertner  says: in response to: chayawatv

Dear GhettoVCBackup Experts,

First of all many thanks for the excellent script!
I have a few questions regarding ghettoVCB on ESX-I 3.5 and ESX-I 4.0 both used with the "free" license.
I use the script with the "plink-method" but I am having trouble with the log file. I am using the following commnandline to start the script:
c:\programme\putty\plink.exe root@192.168.110.3 -pw password "cd /vmfs/volumes/store-VMs/ && ./ghettoVCB.sh servers > ghettobackup-server.log &"
The log file is created as expected but sometimes lines are missing or the logging stops before the scriptrun has ended. For that reason I am often unsure if the script is still running or not.
Is there any way to make sure the script is finished or not? How can I fix the "logging-problem"? Is the plink-method the best way or is it better to use crontab (maybe logging works better that way)? When I look at the backup-destination during the script is runnning the file sizes are not changing. They are set to the file size of the original vmdk as soon as the script is running. What happens if the script ist failing in the middle of the copy process. Do I end with a copy of a vmdk which is just "halffull" and the other half is filled probably with zeros.

A lot of questions I hope you can help and many thanks once again!

Sep 28, 2009 1:45 PM davidpyper  says:

Hi William,

My client has 3 ESXi machines hosting 19 virtual servers, all Windows XP or 2003 machines. The ghettoVCB.sh script runs on the 3 ESXi machines and backs-up the 19 servers to one large NFS share.

The script regularly hangs while removing snapshots. The symptom of the problem is that the last line of the logfile reads "Removing snapshot from " (vnname) followed by no further activity. The manual workaround involves using vSphere to create then remove a snapshot, at which point the script continues working its charm.

The problem apparently stems from the following codeblock from ghettoVCB.sh (line numbers added for clarity):

385 #powered on VMs only w/snapshots
386 if [ ! ${POWER_VM_DOWN_BEFORE_BACKUP} -eq 1 ] && [; then
387 ${VMWARE_CMD} vmsvc/snapshot.remove ${VM_ID} > /dev/null 2>&1
388
389 #do not continue until all snapshots have been committed
390 echo "Removing snapshot from ${VM_NAME} ..."
391 while ls "${VMX_DIR}" | grep -q delta;
392 do
393 sleep 3
394 done
395 fi

As long as there are delta files in the VM's directory, lines 392 to 394 loop perpetually. My contribution to your excellent script is to suggest a modification to line 387 to use vmsvc's snapshot.removeall command instead of snashot.remove. Line 387 would then look like this:

387 ${VMWARE_CMD} vmsvc/snapshot.removeall ${VM_ID} > /dev/null 2>&1

This enhancement removes all snapshots in the form of delta files, and allows the script to continue its work.

Cheers!

Dave

Sep 28, 2009 10:21 PM lamw  says: in response to: ralfoertner

Not sure about the plink solution, I don't use that personally with ghettoVCB, I know it works great for others. You also have another logging possiblity as you've mentioned is to setup a cronjob and have it log locally, take a look at Advanced Logging setup in this document.

Regarding your destination disk, you'll want to take a look at your *-flat.vmdk and not your .vmdk as that is just the descriptor and not the actual disk and the final output will also be determined based on how you're backing up your VM, whether that is thin/thick or any other supported format. If something were to error, you'll see something logged and you'll end up with a bad backup.

=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Sep 28, 2009 10:26 PM lamw  says: in response to: davidpyper

Thanks for the comments, unfortunately your solution is not a valid work around. The script does not support any VM(s) with snapshots, but I also do not make the assumption that a user may or may not modify the script. Having said that, I will only remove the most recent snapshot which should have been generated by my script only and hence it will continue to loop to ensure that the *-delta-XXXXX.vmdk are gone. The other thing that I'm not 100% sure is if snapshot.removeall is a blocking function because snapshot.remove is not and you could run into a situation where you'll have multiple backups completing and committing multiple snapshots which could hinder performance. This will guarantee that each VM is back into a consistent state before moving onto the next VM if something were to go wrong.

I've not heard others having issues with removing the snapshots.


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Oct 1, 2009 6:44 AM SirGuun  says:

Hi Everybody,

Lamw, I like your script! Great work!
I am backing up 5 VMs (on a ESXi 3.5u2 Free) to a Windows NFS Store. Works great.
Now I want to use a NAS-Box (QNAP 509 pro) as a NFS Storage. Connected allright. First 3 Backups ok, but the time it comes to deleting files we have a Problem:

                                1. Taking backup snapshot for VM_MONTASWWW ... ################
Destination disk format: VMFS thick
Cloning disk '/vmfs/volumes/ESXi2950_DS1/VM_MONTASWWW/VM_MONTASWWW.vmdk'...
Clone: 100% done.
Removing snapshot from VM_MONTASWWW ...
rm: unable to remove `/vmfs/volumes/NFS_NAS02/Backup/VM_MONTASWWW/VM_MONTASWWW-2
009-09-22--3/VM_MONTASWWW-flat.vmdk': Input/output error
rm: unable to stat `/vmfs/volumes/NFS_NAS02/Backup/VM_MONTASWWW/VM_MONTASWWW-200
9-09-22--3/VM_MONTASWWW.vmx': Input/output error
rm: unable to remove `/vmfs/volumes/NFS_NAS02/Backup/VM_MONTASWWW/VM_MONTASWWW-2
009-09-22--3': Input/output error
mv: unable to stat `/vmfs/volumes/NFS_NAS02/Backup/VM_MONTASWWW/VM_MONTASWWW-200
9-09-30--3': Input/output error
mv: unable to stat `/vmfs/volumes/NFS_NAS02/Backup/VM_MONTASWWW/VM_MONTASWWW-200
9-09-30--2': Input/output error
rm: unable to stat `/vmfs/volumes/NFS_NAS02/Backup/VM_MONTASWWW/VM_MONTASWWW-200
9-09-16--3': Input/output error
mv: unable to stat `/vmfs/volumes/NFS_NAS02/Backup/VM_MONTASWWW/VM_MONTASWWW-200
9-09-30--1': Input/output error
                                        1. Completed backup for VM_MONTASWWW! ####################

Start time: Wed Sep 30 14:34:34 UTC 2009
End time: Wed Sep 30 15:07:57 UTC 2009
Duration : 33.38 Minutes

Completed backing up specified Virtual Machines!

The speed ist OK (80 GB in about 30 Minutes), but the QNAP-NAS takes over 40 Sek. to delete a large file and so the ESXi gets a timeout. When deleting a large file on the Windows NFS you get the response instantly.
QNAP told me that they will improve the NFS Performance later this year.

Is there a chance to make the script wait for the NFS-Store to send the OK without timeout e.g. an increased period of time?

By the way:
If you a starting the script with plink from windows the log-File doesnt show the Input/Output error, but ends with ...Removing snapshot from VM_MONTASWWW ...

Hope to hear from you
Gunter

Oct 4, 2009 11:50 AM ibhp  says:

Hello

I am backing up my VM's since a few months with ghettoVCB.sh. It is great. Since yesterday I got a problem: The script runs without errors, but no VM's are backed-up anymore. I am running ESXi v3.5 build: 153840.

Until yesterday my log looked like this:
*****************************************
VM is still on - Iteration: 0 - waiting 3secs
VM is off
Starting backup for khtsbs01 ...
Destination disk format: VMFS thick
Cloning disk '/vmfs/volumes/4895d67c-fc7a4da0-09b6-00215ad1fa42/khtsbs01_1/khtsbs01_1_1.vmdk'...
Clone: 0% done.Clone: 1% done... Clone: 99% done.Clone: 100% done.
Destination disk format: VMFS thick
Cloning disk '/vmfs/volumes/R3_KHTSBS01/khtsbs01/khtsbs01_2.vmdk'...
Clone: 0% done.Clone: 1% done...Clone: 99% done.Clone: 100% done.
Destination disk format: VMFS thick
Cloning disk '/vmfs/volumes/R3_KHTSBS01/khtsbs01/khtsbs01_1.vmdk'...
Clone: 0% done.Clone: 1% done....Clone: 99% done.Clone: 100% done.
Destination disk format: VMFS thick
Cloning disk '/vmfs/volumes/R3_KHTSBS01/khtsbs01/khtsbs01.vmdk'...
Clone: 0% done.Clone: 1% done...Clone: 99% done.Clone: 100% done.
Powering back on khtsbs01
Completed backup for khtsbs01!
*******************************

And since today it is only this (VMs are not backuped):
********************************
VM is still on - Iteration: 0 - waiting 3secs
VM is off
Starting backup for khtts01 ...
Destination disk format: VMFS thick
Cloning disk '/vmfs/volumes/4895d67c-fc7a4da0-09b6-00215ad1fa42/khtts01/khtts01_1.vmdk'...
Destination disk format: VMFS thick
Cloning disk '/vmfs/volumes/R2_KHTTS01/khtts01/khtts01.vmdk'...
Powering back on khtts01
Completed backup for khtts01!
*******************************

Any ideas what could cause this problem?

Thank you very much,

ibhp

Oct 4, 2009 11:53 AM lamw  says: in response to: SirGuun

This sounds like an issue with your NFS server...you could add an additional wait by inserting a sleep(XX) into the script before it gets to the rotation code. This value may just be some arbitrary number since different size VM(s) will probably delete faster or slower based on their size.

Good luck


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Oct 4, 2009 11:55 AM lamw  says: in response to: ibhp

If things have been working for a few months, then I would start looking at the changes that could have occurred in your environment, if the script has changed, then it's probably something else. Make sure no changes were done or if any of the virtual disks have been removed from the VM, etc,etc. You will need to do some troubleshooting


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Oct 5, 2009 11:25 AM someone908  says: in response to: lamw

Hi,

first thanks for this great script, seems to be the only alternative for using VCB on Windows.
One small question / feature request:
Would it not minize the downtime if the script shuts down a VM, take the snapshot, Power the VM back on again, clone the disk and then remove the snapshot ? So the downtime would be time requied for shutting down, take Sanpshot and start again. No matter how big the disks are.

Thanks in advantage.

Oct 6, 2009 7:00 AM hburroughs  says: in response to: someone908

I second the request to shut down the VM, take a snapshot, power the VM back up, while cloning the disk and remove the snapshot afterwards. I have modified the scripts in the past to get close to this functionality, but of course I have to re-edit them anytime the upstream GhettoVCB is modified. I feel more confident when I can do pristine copies of the VMs, but it is inconvenient for the downtime required. Maybe a new toggle in the script file? The one problem with this behavior would be if you provided a list of VMs..... do you cycle each off, snapshot, power back on, backup, remove snapshot, THEN do the next for the next VM or do you take snapshots of ALL the VMs you listed first, THEN backup each one and delete the snapshot before moving to the next vm, backup then delete snapshot, etc..... I understand there would be performance impacts due to more than one snapshot in play... but that would be the user's responsibility. They still could pass a single VM to the script (my favorite is echo "vmname" | sh ghettoVCB.sh - ) which reads the VM from the command line vs a config file.

Oct 6, 2009 8:06 AM hburroughs  says: in response to: hburroughs

I've made the changes with about 10 lines of code. (one if statement needs a condition added as well) The evolution of ghetoVCB has actually made it easier to implement part of this. Right now the behavior works best with one VM at a time. If you are backing up multiple VMs, it will wait till the last backup is done, then power that VM off, snapshot, power back on (waiting x seconds), then backup/clone, then delete snapshot. It would take a good deal of rewriting the ghettoVCB flow to handle snapshots first for all VMs. I'll post my changes as soon as I run a few more tests.

Oct 6, 2009 8:48 AM banthorpe  says: in response to: hburroughs

Guys – got a problem with the ghetto backup script. It runs OK for a few backups then complains that it cannot create the directory /vmfs/volumes/BACKUP (see below).

In the script I define:

VM_BACKUP_VOLUME=/vmfs/volumes/BACKUP/ESXIDMZ01

BACKUP is an NFS share mounted as a datastore on the ESXi server. This is actually drive F: on the backup server and on that drive I have pre-created the ESXIDMZ01 folder. I have tried also pre-creating the VM folder below that “OCSEDGE” but it fails with or without that directory existing. There seems to be no consistency.

I also see that “ls” error at the end of the backing up of EXCHEDGE01 (below)

Any ideas?

/vmfs/volumes/49303d2e-240b718c-15f5-00226409b2b0 # ./ghettoVCB.sh ./vmbackups

                                1. Taking backup snapshot for C2C ... ################
Start time: Tue Oct 6 14:02:20 UTC 2009
Destination disk format: VMFS thin-provisioned
Cloning disk '/vmfs/volumes/ESXIDMZ01_1/C2C/C2C.vmdk'...
Clone: 100% done.
Removing snapshot from C2C ...
End time: Tue Oct 6 14:17:33 UTC 2009
                                        1. Completed backup for C2C! ####################

                                1. Taking backup snapshot for EXCHEDGE01 ... ################
Start time: Tue Oct 6 14:17:35 UTC 2009
Destination disk format: VMFS thin-provisioned
Cloning disk '/vmfs/volumes/ESXIDMZ01_1/EXCHEDGE01/EXCHEDGE01.vmdk'...
Clone: 100% done.
Removing snapshot from EXCHEDGE01 ...
ls: /vmfs/volumes/BACKUP/ESXIDMZ01/EXCHEDGE01: Input/output error
End time: Tue Oct 6 14:56:00 UTC 2009
                                        1. Completed backup for EXCHEDGE01! ####################

mkdir: Cannot create directory `/vmfs/volumes/BACKUP/': Input/output error
Unable to create "/vmfs/volumes/BACKUP/ESXIDMZ01/OCSEDGE"! - Ensure VM_BACKUP_VOLUME was defined correctly

Oct 6, 2009 10:09 AM hburroughs  says: in response to: hburroughs

Follow these steps to modify the current ghettoVCB.sh to support what was discussed above: (I just fixed a minor issue if you run the script with this enabled and the VM off... it wouldn't be able to startup since the disk would be locked)

1. Add the following code at the top of the program before the # DO NOT MODIFY LINE

# 1=on, 0 = off
POWER_OFF_SNAPSHOT_ON=1

# Time to wait after powering on the VM before starting the backup/clone process
POWER_ON_WAIT=120

2. Next, replace the if statement directly following "#section that will power down a VM prior to taking a snapshot and backup and power it back on" with this:
if [[ ${POWER_VM_DOWN_BEFORE_BACKUP} -eq 1 ]] || [[ ${POWER_OFF_SNAPSHOT_ON} -eq 1 ]]; then

3. Add this code directly after the section for

#If we need to power the VM back on before backup (POWER_OFF_SNAPSHOT_ON = 1)
if [[${POWER_OFF_SNAPSHOT_ON} -eq 1 ]] && [[ "${ORGINAL_VM_POWER_STATE}" != "Powered off" ]]; then
echo "Powering back on ${VM_NAME} before backing up (waiting ${POWER_ON_WAIT} seconds before copying)"
${VMWARE_CMD} vmsvc/power.on ${VM_ID} > /dev/null
sleep ${POWER_ON_WAIT}
fi

That is it! I've tested this on a only a non-critical system, and since you are modifying your existing ghettoVCB.sh script, please be careful and test completely before using in production.

Oct 6, 2009 7:56 PM lamw  says: in response to: someone908

I'm not sure which use case you're trying to accomplish with the suggested solution.

I see basically 2:

A) Backup while the VM is online
B) Backup while the VM is offline

The solutions to the following are:

A) Take a snapshot while the VM is running, backup the disk and commit the snapshot (no downtime)
B) Power down the VM, no snapshot is needed and backup the disk and power VM

I'm assuming you're referring to case B, you may minimize the actual downtime of the VM by doing an offline snapshot but unfortunately you introduce a snapshot which needs to be committed which turns out to be a similar use case as A, so why not just backup the VM while it's running?


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Oct 7, 2009 12:36 AM fqu89  says: in response to: lamw

I've had the same request than someone98 a few weeks ago...

The reason of this request is :

-It's safer to make a backup of a VM while it's off because databases are closed, files are closed, nothing is in the memory of the VM and in fact you are sure that you won't have any surprise (database inconsistency, files truncated, and so on) when you will use this backup.
-In this case, if you power down a VM and wait until the backup is done before powering it on, it can take HOURS to complete (lots of gigs to transfer)
-so it would be nice to have the ability to shutdown a VM, take a snapshot, power it on, make the backup and delete the snapshot.

Oct 7, 2009 1:44 AM banthorpe  says: in response to: fqu89

problem I have does not seem to be with taking the online snapshot etc. The problem seems to be with the target datastore where the files get moved to. For some reason I fails after backing up 1 or 2 VMs OK saying that it can't create a specific directory for the next VM. However, it managed to do it fine for the first 2 so why fail now?

Oct 7, 2009 2:47 AM aliog  says:

Hi,

for reference when setting up a persistent cron job in ESXi 3.5 update 4 i had to use the following commands to stop and restart crond in my /etc/rc.local

kill $(pidof crond)
crond

not

busybox crond

as mentioned in the help. Other than that all working great.

Oct 7, 2009 7:00 AM lamw  says: in response to: fqu89

Definitely understandable with databases, but that's why VMware has the option of quiescing the filesystem to have all it's data flushed to disk prior to taking a snapshot. The only requirement is to have the latest version of VMware Tools running and when a snapshot is taken, there is a few options to include memory and also to quiesce the fileystem.

[root@himalaya ~]# vmware-vim-cmd vmsvc/snapshot.create
Insufficient arguments.
Usage: snapshot.create vmid [snapshotName] [snapshotDescription] [includeMemory] [quiesced]

Creates a snapshot for the vm.


I do have to admit, in the current version, this is not being utilized and I don't have options to enable this but this is just a boolean of 0 or 1 which can be modified in the script. The reason we have not provided this additional functionality is we don't backup any databases for our dev environment nor any systems that are sensitive that require their filesystem to be flushed to disk.

I don't think suggested solution really saves much more time and you do incur more time to power down and power on the system and you're still working with a snapshot. I do agree, that you do need to take into consideration about backing up databases and even with VMware's product and others, there are things like VSS and quiescing VM/etc.

You can definitely test with the params and see if it helps, else the code that has been provided by others can be used but will not be part of ghettoVCB.

Thanks again for your comments


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Oct 7, 2009 7:04 AM lamw  says: in response to: banthorpe

What are the differences between the first 2 VMs and the third? I've seen this issue once or twice in the forums and it all goes back to the NFS server as you've mentioned with the timeout. I would say that either the size of the VM differs significantly or the snapshot is much larger than the first two and hence it's failing. Also is the link to your NFS server being saturated, are there other data going through it? 1gb link to NFS server vs 10gb link vs 4/8gb FC link will all act very different and also the storage on the backend and how many spindles/disk are being accessed.

This is more of an environmental issue than with the script, we've backed up VMs in the hundreds of gig without any issue against an NFS.


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Oct 7, 2009 7:05 AM lamw  says: in response to: aliog

Thanks for the information, I'll update the document tonight with the correct params.


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Oct 8, 2009 1:35 PM mcunningham44  says:

Has anybody encountered the following error when running the script?

mkdir: cannot create directory `/vmfs/volumes/nfs_storage_backup': Operation not permitted

Oct 8, 2009 1:42 PM DSTAVERT  says: in response to: mcunningham44

what do you have for the VM_BACKUP_VOLUME=

The backup volume must point to a mounted datastore (unless you are using non persistent storage) and the path must exist.

Oct 8, 2009 1:57 PM mcunningham44  says: in response to: DSTAVERT

Well, the script was working fine then I changed the NFS share name. I am using non persistent storage. This is going to a VMWare Cluster and I noticed that on 3 of the hosts now, it was mounting to nfs_storage_backup and now its going to nfs_storage_backup (1). Because of the (1) the path wasn't working for the compression. So I removed the nfs_storage_backup (1)...now when I go to run the script i get the above error. Any suggestions? Thanks!

Oct 8, 2009 2:03 PM DSTAVERT  says: in response to: mcunningham44

NO spaces in the path. or special caharacters.

Oct 8, 2009 2:06 PM DSTAVERT  says: in response to: DSTAVERT

Can you mount that datastore?

Oct 8, 2009 2:06 PM mcunningham44  says: in response to: DSTAVERT

The system created the nfs_storage_backup (1) on its own... i don't know why it used that when its defined as NFS_LOCAL_NAME=nfs_storage_backup in the script.

Oct 8, 2009 2:22 PM DSTAVERT  says: in response to: mcunningham44

Can you mount that share on your ESXi host as you have it listed in the script under persistent.

Oct 8, 2009 2:37 PM mcunningham44  says: in response to: DSTAVERT

I'm not sure. All I know was the script was working fine on each host in the cluster and for some reason it stopped with the Operation Not Permitted Error. I would like to know what caused this error to occur. Is it plausible that only 1 HOST in the cluster can be mounted to the NFS share at a time? Because currently there is 1 of the 4 HOSTS in the Cluster that work fine and mount to this location without a problem and STILL works fine.

Oct 8, 2009 3:45 PM DSTAVERT  says: in response to: mcunningham44

As long as there are fewer than 8 NFS shares on a host (the default but can have been changed) an NFS share can be be add to as many ESXi hosts as you have. When you say that the system made the change what do you mean "what system?". Is the NFS share already present on the host? Again I ask can you mount the share as is is under the non persistent settings of the script. If it can't then the script won't either. You did say that it was working and then you changed something. Check your editing.

Oct 8, 2009 7:49 PM lamw  says: in response to: mcunningham44

I believe someone here or in the general forums ran into something similar when using vimsh to mount an NFS datastore, it seems to remember the original label, hence when you try to re-mount as something else it'll think it already exists. I think the user had to manually re-add with the same name, delete the NFS datastore and then manually re-mount using the new name.

=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Oct 9, 2009 5:50 AM mcunningham44  says: in response to: lamw

Would this also eliminate the mkdir: cannot create directory `/vmfs/volumes/nfs_storage_backup': Operation not permitted, that I've been starting to get? I never got this error before, and for some reason I started getting it today and I'm not sure whats causing it?

Also,

When I goto mount it manually via "/usr/bin/vmware-vim-cmd hostsvc/datastore/nas_create nfs_storage_backup x.x.x.x /NFS_SHARE 0" I get a message saying this already exists below:

(vim.fault.AlreadyExists) {
dynamicType = <unset>,
name = "",
msg = "The specified key, name, or identifier already exists."
}

Oct 9, 2009 11:16 AM mpaytonnj  says: in response to: lamw

First, thanks for this awesome script and for updating/answering questions. We have Enterprise licensing, including the "official" VCB, but were looking for something simpler than a VCB proxy setup for our ESXi servers. This fits the bill perfectly.

Second, rather than using a manually maintained list of machines to include in a backup we do something a little different and I figured I'd offer to share it in case anyone finds it interesting...

Due to various factors ( vmotion, VMs added/removed, VMs moved from dev to production, new hosts added/removed etc. ) our inventory is constantly changing on all hosts and manually updating a list of VMs to backup in multiple locations got to be a bit much.
Therefore we found it easier to maintain a single file of machines to exclude from backup, rather than multiple files of VMs to include.
Basically, we assume the VM should be backed up unless it's specifically excluded.

To accomplish this on ESX using vcbMounter, I get the VM names from /etc/vmware/hostd/vmInventory.xml ignoring any that are listed in a specified "exclude" file and passing the rest to vcbMounter to be backed up.
I modified this for ESXi/ghettoVCB.sh to write the VM name(s) to the file used as the argument to ghettoVCB.sh.
It still requires maintaining the exclude list, so it's possible to miss something. But in our environment this has proven to be easier/more effective, and all ESX(i) machines in our environment look at the same exclude file. Or if you don't want to exclude any VMs, leaving the exclude file blank means you no longer have to manually maintain any files.

So, if anyone is interested, I can post what passes for my "code".

Disclaimer...I am not a shell programmer. I know there are cleaner/more graceful ways of doing this than the hack I threw together. real programmers will probably laugh or throw rocks at me. But it works for us, it's only a few lines and it is probably easy to clean up/condense by someone with more experience.

Oct 12, 2009 11:15 AM mcunningham44  says: in response to: lamw

Thanks for your help and the script!!

Oct 14, 2009 9:20 PM lamw  says:

Hi everyone,

I'm currently in development (as time permits) on some new features for the ghettoVCB script and I'm looking for some individuals that may be interested in taking part in a BETA. The requirement is pretty simple, willing to help test and provide feedback on the next version of the script (remember to test on non-production VMs) ;)

If you're interested, please PM on VTMN with your email address and the script you would like to take part in and I'll be selecting a group users and send out email notification in the coming weeks.

Thanks

=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Oct 14, 2009 11:23 PM DSTAVERT  says: in response to: lamw

I would dearly love to participate but fundamentally refuse to use twitter or expose an email address to it.

Oct 14, 2009 11:49 PM voro  says: in response to: lamw

I can help if you want. I have a spare R200 with latest ESXi 3.5 and a V4 Essential license for it.
Oh, I can't DM you on twitter, probably cause you're not following me :)

Oct 15, 2009 6:59 AM lamw  says: in response to: DSTAVERT

Drop me your email via PM on VMTN.


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Oct 15, 2009 6:59 AM lamw  says: in response to: voro

Drop me your email via PM on VMTN.


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Oct 16, 2009 1:54 AM goppi  says:

This is a really great extension to ESXi.
The only thing missing IMHO is the ability to exclude certain vmdks from backup.
You very often have setups where you only want to backup the system volumes of machines via image and not the datavolumes which are sometimes 100GB+ in size. These are most often beeing backed up by different systems with a more granular backup technology.

Oct 16, 2009 9:21 AM lamw  says: in response to: goppi

There is a BETA in the coming weeks, if you're interested drop me your email via VMTN PM


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Oct 18, 2009 10:28 AM S3BASTI3N  says: in response to: lamw

for pb with 100GB+ (for data volume) I use an independant disk (wich is not affected by snapshot) and I use a modified GhettoVCB script : I add a BACKUP_INDEPENDENT_DISK option and if set to 0 , I exclude "independent" disk when the script "browse" all vmdk
It works fine until a new version of GhettoVCB comes with this option ! :)

lamw, i'm interested by your beta ;)

Sebastien

Oct 18, 2009 5:50 PM lamw  says: in response to: S3BASTI3N

If you're interested in the BETA, please send me a PM on VMTN with your email.


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Oct 20, 2009 3:08 PM BasicVirtu  says: in response to: lamw

First off thank you, and great work on your scripts.

I recently upgraded to ESX4 and ESXi4 and would like to try using one of the scripts either ghettoVCB or ghettoVCB2 to copy vms from our ESX4 cluster to an ESXi server that has plenty of local storage. Would you recommend the newer script or the older script? I was hoping to use compression but did not see that feature in the new script. Also I would be willing to test any beta scripts since I am starting out with our test server. Thanks

Oct 20, 2009 7:48 PM lamw  says: in response to: BasicVirtu

ESX(i) 4.0 is supported by both ghettoVCB and ghettoVCBg2, please go over the documentation carefully and you'll see the use cases for each depending on the environment you're in. Compression is only available with ghettoVCB and it's not available for a certain reason in ghettoVCBg2.

Regarding the BETA, if you're interested please follow the directions in an earlier comment that specifies on how to apply.


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Oct 21, 2009 12:31 PM jberne74  says: in response to: lamw

Thanks a mill for this cost saving solution William. I have everything up on my ESXi host, tied my NFS datastore to it, edited the VM_BACKUP_VOLUME variable appropriately, created the vm list file and changed permissions on the ghettoVCB.sh all using Putty on my windows machine to ssh into the ESXi host. But when i try to run the script, i still get the:

-ash: ./ghettoVCB.sh: not found
error.Can i get any help here. Thnx so much.

Oct 21, 2009 9:10 PM lamw  says: in response to: jberne74

Make sure you're downloading the latest version which is attached to this VMTN document. Make sure you've edited the script directly on ESX(i) host (not with Windows system such as notepad). These are generally the issues people run into if they're hitting this error. How did you upload the script to your ESX(i) host?


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Oct 21, 2009 9:50 PM jberne74  says: in response to: lamw

I edited the script on the ESXi host using Putty.I uploaded the script to the ESXi host using WinSCP transfer(in text mode).I probably will go ahead and download the latest version attached to this VMTN document, edit and make the changes in the morning.I will let you know how this goes.Thanks a million again.

Oct 22, 2009 6:26 PM jberne74  says: in response to: lamw

Thanks William.Everything's on track now. Apparently the original download was corrupt.Thanks again.

Oct 22, 2009 9:26 PM lamw  says:

BETA email invitations will be going out this weekend ... keep an eye out :)


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Oct 23, 2009 3:12 PM DSTAVERT  says: in response to: lamw

Since we are getting close to Halloween walking around with an eye out won't be that noticeable. Good timing. ;)

Oct 23, 2009 4:45 PM stighenning  says: in response to: DSTAVERT

---

I found the ghettoVCB.sh to work great!

But how can I automaticlly generate the vm_backup_list.. so that the ghettoVCB.sh through cron will backup every vmware that is running on the VMWare ESXI 4.0 server ?

I tried using "cat /tmp/vms_list | grep vmware | sed ....something " > new_file_backup_list
(but I cant get this to work..)

---

Oct 23, 2009 9:03 PM DSTAVERT  says: in response to: stighenning

This code will generate a list of all VMs on the host.

vim-cmd vmsvc/getallvms | awk -F " " '{print $2}' | sed '1,1d' > /tmp/currentvms


You can create a script that includes that and add
ghettoVCB.sh /tmp/currentvms

You would need to add your paths etc and add your script to cron

Oct 24, 2009 7:39 AM stighenning  says: in response to: DSTAVERT

Hi,
Your command works perfect with the images-names that do not have spaces in the name.
But the images with spaces, i.e. "WIN 2K3 PRODUCTION" will not be in the list properly..

Is there a command that could cut out the "WIN 2K3 PRODUCTION" line in this /tmp/vms_list :

"";"";""
"Windows user/pass: administrator/<Blank>";" ";""
"576";"WIN 2K3 PRODUCTION";"vmware";"WIN 2K3 PRODUCTION/Win2k3 32 bit.vmx"
"";"";""

Oct 24, 2009 7:47 AM lamw  says: in response to: stighenning

The command provided by @DSTAVERT is not correct ... it's way more complicated than that when you have spaces/etc. that needs to be taken into consideration. The actual command is actually within the ghettoVCB script if anyone has taken a look at the source.

vmware-vim-cmd vmsvc/getallvms | sed 's/[[:blank:]]\{3,\}/   /g' | awk -F'   ' '{print "\""$1"\";\""$2"\";\""$3"\""}' |  sed 's/\] /\]\";\"/g' | sed '1,1d'


This will handle VM names that have spaces in their display name (a big no no in my books!)

Just substitute wither vmware-vim-cmd for classic ESX or vim-cmd for ESXi

=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Oct 24, 2009 7:54 AM DSTAVERT  says: in response to: lamw

stighenning
I am sorry. :( I keep forgetting that people do use spaces in names.

Oct 24, 2009 11:58 AM stighenning  says: in response to: lamw

This command feeds the /tmp/vms_list with data.
But this list is filled with lines like:

"16";"Windows XP";"vmware";"Windows XP/WindowsXP.vmx"

..so a command that pulls out the word(s) before ";"vmware and put this into a new file.

Oct 24, 2009 12:27 PM DSTAVERT  says: in response to: stighenning

replace the

{print "\""$1"\";\""$2"\";\""$3"\""} 

with
{print $2) 

Oct 24, 2009 1:13 PM stighenning  says: in response to: DSTAVERT

Aha.. made it ;)

1. touch /tmp/vm_backup_list (so the file actually exists!)
2. edit the ghettoVCB.sh and add this to the script:

  1. Author: william2003atgmaildotcom
  2. Date: 11/01/2008
#
  1. This script is cron'd everyday to run backups on certain set of VMs and will overwite the previous backup if exists

  1. ADD THESE LINES UNDER HERE:
  2. sed '1d' - removes the first line (which says Name, and we only want to list VMwares)
  3. sed '/^ *$/d' - removes empty lines and lines with only spaces
  4. awk... - gives us the vmwares that are inside the vSphere inventory
#
vim-cmd vmsvc/getallvms | sed 's/[[:blank:]]\{3,\}/   /g' | awk -F'   ' '{print $2}' | sed '/^ *$/d' | sed '1d' > /tmp/vm_backup_list


It will now backup all the vmwares I can see in the vSphere Client. (I have about 20 vmwares in the inventory list with and wihtout spaces in names)

..last part it to setup this with cron ;)

Thanx you for fast feedback to help me solve this issue!

Oct 24, 2009 1:17 PM stighenning  says: in response to: DSTAVERT

??

How can I paste "code" so that it does not edit the code ? (so you can read the code wihtout icon and blue letters)

??

Oct 24, 2009 1:29 PM DSTAVERT  says: in response to: stighenning

use {code} before and after your code.

not like html no / in the code tag

Oct 25, 2009 1:43 AM stighenning  says: in response to: DSTAVERT

..
..script been running good, backing up alot of my vmware that are stopped.. but when it came to an image that was running, it fails:

                                1. Taking backup snapshot for Wiki_ATG ... ################
Start time: Sun Oct 25 03:55:16 UTC 2009
Destination disk format: VMFS zeroedthick
Cloning disk '/vmfs/volumes/vmware/Wiki_ATG/Wiki_ATG.vmdk'...
Clone: 100% done.
Removing snapshot from Wiki_ATG ...
sh: /vmfs/volumes/nfs_storage_backup///Wiki_ATG/Wiki_ATG.vmsd: bad number
./ghettoVCB.sh: line 473: syntax error: /vmfs/volumes/nfs_storage_backup///Wiki_ATG/Wiki_ATG.vmsd+1

Oct 25, 2009 1:38 PM stighenning  says: in response to: stighenning

I found there where an old folder with the same name in the "target".
I deleted this folder on the target system, and ran the ghettoVCB.sh vm_backup_list again.. and this time it worked. :)

Oct 28, 2009 8:50 AM xavier@lynk.c…  says:

I just downloaded the script to test it and cannot run. I get this message

root@esx01 ghettovcb# ./ghettoVCB.sh backuplist
-bash: ./ghettoVCB.sh: /bin/bash^M: bad interpreter: No such file or directory

I am running VMware ESX 4.0.0 build-164009

Oct 28, 2009 11:24 AM lamw  says: in response to: xavier@lynk.c…

Did you edit the script in any way/shape or form on a Windows system? That is why you're seeing the ^M character when using something like a notepad program. Re-download and upload the script directly to the ESX(i) host and make your edits using VI


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Oct 28, 2009 12:21 PM xavier@lynk.c…  says: in response to: lamw

I downloaded it to a windows PC. I then used vSphere client to upload it to a datastore.
I ssh to the esx server and edited the file via VI.
I did open it using notepad to see the text but did not save anything I simply closed it.

I will try again. Thanks

Oct 28, 2009 12:42 PM jberne74  says: in response to: xavier@lynk.c…

I suggest uploading the file with WinSCP as text and editing in using the vi editor in Putty.

Oct 29, 2009 2:34 AM stighenning  says: in response to: xavier@lynk.c…

To remove the ^M from the file, do this;

sed 's/.$//' ghettoVBC.sh > NewghettoVCB.sh

..it will work :)

Oct 29, 2009 5:40 AM xavier@lynk.c…  says: in response to: stighenning

Thank you guys for your suggestions, they were very helpful.
The script now runs and works great however I get this message below. Is this something that I can fix?

DiskLib_Check() failed for source disk The system cannot find the file specified (25).

Oct 29, 2009 7:31 PM cwkoh  says: in response to: S3BASTI3N

Hi S3BAST13N. I am also looking to exclude backup od "independent" disk. Can you share with us how to modify the script to do so. Thanks.

Oct 29, 2009 7:51 PM lamw  says: in response to: cwkoh

FYI - Independent disk logic will be added to the next release of ghettoVCB :)


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Getting Started with the vMA (tips/tricks)
Getting Started with the vSphere SDK for Perl
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Oct 29, 2009 8:08 PM cwkoh  says: in response to: lamw

Great. Is this also in the beta. Can I have a copy to test. Thx.

Oct 29, 2009 8:10 PM lamw  says: in response to: cwkoh

Yea that'll be in the next release and sorry the BETA is closed. I should have a new release of the script soon enough ;)


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Getting Started with the vMA (tips/tricks)
Getting Started with the vSphere SDK for Perl
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Oct 29, 2009 8:39 PM cwkoh  says: in response to: lamw

OK I'll wait for the release then

Oct 30, 2009 4:54 AM lukechip  says:

Hi,

How is ghettoVCB supposed to handle VMs that are in a suspended state ? I'm just starting to play around with ghettoVCB now, and I'm finding that when ghettoVCB hits a machine which:

1/ is suspended, and
2/ has no snapshots

It takes snapshot, backs it up, but DOES NOT delete the snapshot it took as part of the backup.

Consequently, next time I try to backup the machine, when it is in a powered on state, the backup fails since there is a pre-existing snapshot (called vcb_snap).

Am I missing something ?

Oct 30, 2009 6:48 AM lamw  says: in response to: lukechip

Yep, the logic when taking the snapshot is correct, but upon removal it only checks for "Powered On" VMs only, this has been fixed and will be ported to the next release of the script. In the meantime, if you would like to update the script just search for the section where the snapshot is removed and add and "OR" statement that says:

 \[\[ "${ORGINAL_VM_POWER_STATE}" == "Suspended" \]\]


This will solve the problem.

Thanks for the comments


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Getting Started with the vMA (tips/tricks)
Getting Started with the vSphere SDK for Perl
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Oct 30, 2009 7:26 AM xavier@lynk.c…  says: in response to: lamw

I have been testing the script for a couple days, and it seems to work fine. I have a couple questions:

1) Should the nvram and log files be also backed up? I only see the .vmx and .vmdk files
2) In some VMs I get this message but the backup still works
DiskLib_Check() failed for source disk The system cannot find the file specified (25).

Thanks

Oct 30, 2009 10:00 AM lamw  says: in response to: xavier@lynk.c…

1) No, these files are not explicitly required (nvram will be generated upon boot up if not there) The logs may or may not be useful, depends on what you'll use them for and you could have quit a few logs. This can easily be added as a additional files but won't be part of this script

2) Can you provide more information about the environment, the VMDK(s) you're trying to backup? There's probably something going on with the disk it's trying to clone either at the source or destination. Would be helpful to provide some output from your run, as your error is vague in general. Remember to wrap all output in {code} tags


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Getting Started with the vMA (tips/tricks)
Getting Started with the vSphere SDK for Perl
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Oct 31, 2009 3:45 AM lukechip  says:

My backups only contain the .vmdk and .vmx files. Consequently, when I restore the machine using vmkfstools, the resultant machine is in a powered off state. This took me a little by surprise, since the machine was powered on when the backup was taken, and I'd expected it to be restored in exactly the same state.

As a result, my questions are:

1/ is this the intended behaviour
2/ is there any risk of memory resident or cached data that has not been written to the VMs disk being lost ? For example, an unsaved file that is open when the backup is taken, or data that has been saved but is in the VMs operating system cache, and not actually written to the VMs disk ?

Thanks.

Oct 31, 2009 11:37 AM lamw  says: in response to: lukechip

1) Yes that is the intended behavior as stated in the previous reply
2) Using the quiesce option would solve this problem, take a look here for more details: http://virtualizationreview.com/Blogs/Everyday-Virtualization/2009/08/Quiesced-Snapshots.aspx

As of today, this is disabled by default but in the next release of the script, a user can configure both the quiesce and memory option of a VM when specifying a backup snapshot prior to backup. You can manually change the value in the script but it'll be a manual process.


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Getting Started with the vMA (tips/tricks)
Getting Started with the vSphere SDK for Perl
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Oct 31, 2009 7:43 PM lukechip  says: in response to: lamw

Regarding "If you find this information useful, please award points for "correct" or "helpful"."...

How do I do this ?

I'd like to, but can't see where to do it !

Nov 2, 2009 7:54 AM xavier@lynk.c…  says: in response to: lamw

Will,
1) Thanks for your responses. Agreed. nvram and log files may not be useful. If I wanted to copy the log files and nvram I could only add 2 lines in your script after line 266 correct?

 cp "${VMX_PATH}" "${VM_BACKUP_DIR}" 

to something like

cp ${VMX_DIR}/*.log ${VM_BACKUP_DIR}

cp ${VMX_DIR}/*.nvram ${VM_BACKUP_DIR}


2) I could not replicate the error "DiskLib_Check() failed for source disk The system cannot find the file specified (25)" anymore, I do not know what I did different with the test VM I have. I will post what I can if it happens again.

3) I noted that in your script, line 227 you have a check for existing snapshots and if found the backup is not performed. Do you do that for a special reason? wouldn't the script take a new snapshot (vcb_snap) below the other ones and remove it at the end? is this supported?

Nov 2, 2009 9:41 AM lamw  says: in response to: xavier@lynk.c…

1) That should work, you'll want to test and verify.

3) Snapshots are not meant to be kept for long durations of time, there is a miss-conceptions on what snapashots are used for. They should be short lived and hence I will ignore any VMs with prior snapshots, you're more than welcome to modify the script to support this, but I will provide 0 support on this type of configuration.


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Getting Started with the vMA (tips/tricks)
Getting Started with the vSphere SDK for Perl
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Nov 3, 2009 10:21 AM xavier@lynk.c…  says: in response to: lamw

1) After line 266

cp "${VMX_PATH}" "${VM_BACKUP_DIR}"


I added these 2 lines to also copy the nvram and log files

cp ${VMX_DIR}/*.log ${VM_BACKUP_DIR}

cp ${VMX_DIR}/*.nvram ${VM_BACKUP_DIR}


3) Agreed. VMware snapshots should be short lived, however on testing/prestaging VMs sometimes you need to keep a snapshot for 24 hours or so.

I tested the script with more than 1 snapshot and I think I understand why it won't support more than 1 snapshot because it will only remove 1 snapshot, the vcb_snap snapshot taken for the backup. If I’m not wrong this is in line 384

${VMWARE_CMD} vmsvc/snapshot.remove ${VM_ID} > /dev/null 2>&1


It's very tricky trying to remove a specific snapshot due to the levels and indexes for snapshots. If VMware could have a way to delete a snapshot based on the name of the snapshot that would eliminate many caveats.

I'm adapting the script to our environment. So I am doing these other changes/additions:

a) Allow the backup to proceed if snapshots are found and remove all snapshots (I chose I prefer a backup over a previous snapshot). So I commented out the snapshot check and modified the script in line 384 to this:

${VMWARE_CMD} vmsvc/snapshot.removeall ${VM_ID} > /dev/null 2>&1


b) A boolean (true/false) variable/parameter to also snap the memory when creating the snapshot. Example below
${VMWARE_CMD} vmsvc/snapshot.create ${VM_ID} vcb_snap VCB_BACKUP_${VM_NAME}_`date +%F` ${SNAP_MEMORY} > /dev/null 2>&1


c) I added a line at the end of the script to add permissions at my backup dir specified (openfiler SMB/NFS share)in the VM_BACKUP_VOLUME parameter.
chmod -R +rw ${VM_BACKUP_VOLUME}

I noticed that the files/folder created by the script had root permissions only so when the backup software tried to access the files to back them up it failed.

d) I also added a notification procedure at the end of the script to email the log created

I tested the script with my modifications/additions and works fine in our environment

Thanks Will for providing this script as it's a great contribution and useful tool and other people can also contribute to your work.
Can't wait to see the next release that will contain the independent disk logic and quiesce memory option of a VM (and more perharps?)

Nov 3, 2009 8:20 PM lamw  says: in response to: xavier@lynk.c…

There are actually 2 reasons why I don't support backup of VMs w/snapshots
1) Reason from previous reply
2) It's not easy using vimsh ... having said that, it's stupid simple using the official VI/vSphere API's which allows you to remove a snapshot based on a name. This can be seen with ghettoVCBg2 - Free alternative for backing up VMs in ESX(i) 3.5 and 4.x (no SSH console required!) if you take a look at the code, but again even with this version I do not support backups of a VMs with snapshots (going back to reason #1)

Having said all that, it's definitely possible with vimsh but you just have to figure out the index/child values which I thought I had figured out but it's really not worth it and again goes back to my reason #1

Glad the script is working out for you and the customization you're implementing for your specific environment.

Definitely keep an eye out in next few weeks for the next release, it'll be introducing some nice features ;)

--William


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
vGhetto Script Repository
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity
Getting Started with the vMA (tips/tricks)
Getting Started with the vSphere SDK for Perl
Twitter: @lamw

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Nov 5, 2009 3:20 AM kerozen  says:

Hi,

thanks a lot for this script.
It's working fine in our environnment but it take so long to backup.

In fact, i backup vms to an nfs share on a little nas (iomega storcenter pro ix4-100) which is very slow for read and write (even in ftp or smb mode).

so i realize that ghettoVCB.sh does the backup directly to this share and then compress the vm on the share (when i enable compress of course).

Is it possible to do the snapshot locally, compress the backup and then send it to share (then delete the local compressed backup). In this order, i will gain some time to backup vms.
The only thing i need is enough space for locally backing up the biggest vm.

thanks by advance.

ben

Nov 5, 2009 3:35 AM voro  says: in response to: kerozen

I've used a Iom200rl in the past and their NFS performance is not great. You should check how fast it transfers from the esx console (without using the script). Also you can tweak nas' exports config (async, no_wdelay, etc, but be careful with this, use at you own risk!) or try using jumbo frames, if your hardware supports it. I've experienced a huge increase of transfer rate with these.

Nov 5, 2009 3:41 AM kerozen  says: in response to: voro

Hi,

the transfer rate is not really a problem. The real problem of the iomega is the I/O of the disks.

The best solution will be to compress before send the backup to the nas. (if space is available of course)

with this, less data to send to the nas, less time to send it.

i will look for jumbo frame too (the esxi nic, the switch and the nas have to support it)

Nov 5, 2009 4:47 AM voro  says: in response to: kerozen

When I said transfer rate I didn't mean "network bandwidth". Jumbo frames can improve the situation if its related to network. Poor NFS performance can be related to network and to storage I/O; async and no_wdelay can improve the NFS performance when saving data.
To see which one you have to tweak you could do some testing with cat or dd with /dev/zero and /dev/null with ssh without compression and nfs. If it's fast (well, fast enough for a storcenter) then the bottleneck it's the NFS saving data and then those params I said above can make things a little better.

I think your proposal would require a major overhaul of the script. Meanwhile, if you have enough local space, you can set a local dir as VM_BACKUP_VOLUME, and after the script has ended, move the backups to the storcenter with a different script (quite easy to code because you can copy the rotation procedure from the original script).

Nov 5, 2009 7:12 AM kerozen  says: in response to: voro

thanks.

i will look deep in this jumbo frame. easy on the iomega (just one click to activate jumbo frame support), i've read that i need to create a new virtual switch on esxi and define the mtu size for frame. sounds a bit more complex.

i've just ended trying to backup four vms to the little nas, compressing each one.

i got a big vmdk that was not stored in the gzipped file, the script return this error: tar: cannot store file 'XXXXXXX/xxxx-flat.vmdk' of size 107374182400, aborting.

so i ended with a gzipped file of 104 Bytes.

i will look into the script to see how i can do a local save then copy over the nfs share, as you suggest.

Nov 10, 2009 2:11 AM CBrienen  says: in response to: lamw

Hi William,

I have the exact same problem as Davidpyper described in his post from 28 Sep 2009. I have been using your script for a while now and never had any problems. Since a couple of weeks the script sometimes "hangs" while removing a snapshot. If I look in VC I see a snapshot in the snapshot manager of that particulary date. If I remove the snapshot the script continues and starts snapshotting the upcoming VM's. Before the script starts there are NO snapshot present in VC. It is not consistent so I don't know where to look. Any idea where to look?

Thanks for the script.

Christian

Nov 11, 2009 9:19 AM lamw  says: in response to: CBrienen

I've not seen this issue from others and haven't been able to reproduce. Are there anything specific with this VM in particular or set of VMs? Have you tried to backup other VMs except for this one to see if it's only this VM?


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
Twitter: @lamw
vGhetto Script Repository
Getting Started with the vMA (tips/tricks)
Getting Started with the vSphere SDK for Perl
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Nov 12, 2009 11:15 AM banthorpe  says: in response to: lamw

Hmm - OK looking into this again. It always fails on the 3rd VM regardless of size of that VM or the preceeding VM.

Nov 16, 2009 7:45 PM cwhitmore  says:

I'm trying to backup one VM with two vmdk files. I've installed the latest GhettoVCB, but when I try to run "./GhettoVCB.sh serverlist" I get the following error:

/vmfs/volumes/48f62e13-c6958ca2-6bc2-0022198dec59 # ./ghettoVCB.sh serverlist
Skipping invalid VM '368'
Skipping invalid VM '384'
Skipping invalid VM '400'
Segmentation fault

                                1. Taking backup snapshot for Sharepoint2008x64 ... ################
Start time: Tue Nov 17 03:38:42 UTC 2009
Destination disk format: VMFS thick
Failed to open '/vmfs/volumes/BackupsStore/Sharepoint2008x64/Sharepoint2008x64_1.vmdk': Device or resource busy (1048585).
Destination disk format: VMFS thick
Failed to open '/vmfs/volumes/BackupsStore/Sharepoint2008x64/Sharepoint2008x64.vmdk': Device or resource busy (1048585).
Compressing VM backup "/vmfs/volumes/NFS/Sharepoint2008x64/Sharepoint2008x64-2009-11-17.gz"...
ash: /vmfs/volumes/NFS/Sharepoint2008x64/Sharepoint2008x64-2009-11-16: bad number
./ghettoVCB.sh: ./ghettoVCB.sh: 462: Syntax error: /vmfs/volumes/NFS/Sharepoint2008x64/Sharepoint2008x64-2009-11-16+1
/vmfs/volumes/48f62e13-c6958ca2-6bc2-0022198dec59 #

Nov 16, 2009 7:51 PM lamw  says: in response to: cwhitmore

1) Please wrap any output you have in code tags, makes it much more readable on the forums. Please refer to this document if you have any questions: http://communities.vmware.com/markuphelpfull.jspa

2) How many VMs do you have on this host?

3) Is this ESX(i) and what build/version?

4) Can you please run the following command and paste the results:

ESX

vmware-vim-cmd vmsvc/getallvms


ESXi
vim-cmd vmsvc/getallvms


It looks like when it's querying for certain VMs, they're considered 'invalid' for some reason and probably why you're getting the initial dump.

=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
Twitter: @lamw
vGhetto Script Repository
Getting Started with the vMA (tips/tricks)
Getting Started with the vSphere SDK for Perl
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Nov 17, 2009 6:25 AM cwhitmore  says: in response to: lamw

Hopefully this paste works better:

/vmfs/volumes/48f62e13-c6958ca2-6bc2-0022198dec59 # ./ghettoVCB.sh serverlist
Skipping invalid VM '368'
Skipping invalid VM '384'
Skipping invalid VM '400'
Segmentation fault
                                1. Taking backup snapshot for Sharepoint2008x64 ... ################
Start time: Tue Nov 17 13:41:20 UTC 2009
Destination disk format: VMFS thick
Failed to open '/vmfs/volumes/BackupsStore/Sharepoint2008x64/Sharepoint2008x64_1.vmdk': Device or resource busy (1048585).
Destination disk format: VMFS thick
Failed to open '/vmfs/volumes/BackupsStore/Sharepoint2008x64/Sharepoint2008x64.vmdk': Device or resource busy (1048585).
Compressing VM backup "/vmfs/volumes/NFS/Sharepoint2008x64/Sharepoint2008x64-2009-11-17.gz"...
End time: Tue Nov 17 13:41:20 UTC 2009
                                        1. Completed backup for Sharepoint2008x64! ####################

Start time: Tue Nov 17 13:41:10 UTC 2009
End time: Tue Nov 17 13:41:20 UTC 2009
Duration : 10 Seconds

Completed backing up specified Virtual Machines!

/vmfs/volumes/48f62e13-c6958ca2-6bc2-0022198dec59 #


I have six guests installed, ESXi version is 3.5.0

~ # vim-cmd vmsvc/getallvms
Vmid Name File Guest OS Version Annotation
112 vmXP BackupsStore vmXP/vmXP.vmx winXPProGuest vmx-04
208 FreeBSD71 BackupsStore vmFreeBSDx64/vmFreeBSDx64.vmx otherLinuxGuest vmx-04
416 ArchiveManager2003 BackupsStore ArchiveManager2003/ArchiveManager2003.vmx winNetEnterpriseGuest vmx-04
432 Sharepoint2008x64 BackupsStore Sharepoint2008x64/Sharepoint2008x64.vmx winLonghorn64Guest vmx-04
448 LegalFiles BackupsStore LegalFiles/LegalFiles.vmx winLonghorn64Guest vmx-04
96 vmBackup2003x64 datastore2 vmBackup2003x64/vmBackup2003x64.vmx winNetStandard64Guest vmx-04
~ #

I'm only trying to backup one of the VM's (Sharepoint2008x64). It runs with errors if I shutdown the VM.

Nov 17, 2009 7:38 AM goppi  says:

Great that policy based backup has been added.

The only thing still missing IMHO is the possibility to take a snapshort in powerdown state before backup. Depending on guest OS and running apps this is the only way to get a reliable backup. How about an additional setting TAKE_SNAPSHOT_ON_POWER_DOWN=1. Then the sequence would be as follows:

Power machine down,
Take snapshot,
Power up,
Take backup,
Remove snapshot

Taking a backup only with the setting POWER_VM_DOWN_BEFORE_BACKUP=1 can be quite time consuming and is not always an option.

IIRC this feature has been requested by two others. So how about?

Thanks again for that great software.

Nov 17, 2009 9:43 AM lamw  says: in response to: cwhitmore

I've just released a new version of the script, please download this version and go over the documentation as there have been some changes on using the script. There were some issues that may have been fixed which might help resolve the issue you're running.

If you're still seeing the issue, please provide an execution run on the vm that is failing with both dryrun and debug mode.

Thanks


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
Twitter: @lamw
vGhetto Script Repository
Getting Started with the vMA (tips/tricks)
Getting Started with the vSphere SDK for Perl
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Nov 17, 2009 9:48 AM lamw  says: in response to: goppi

Sorry this feature will not be supported as mentioned in the past, there are no significant advantages to this and I'm not exactly sure what you're deeming "reliable backup". You're more than welcome to look at other Enterprise ready solutions if you need something more reliable ... and of course you're more than welcome to edit the script to fit your environment.

Thanks


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
Twitter: @lamw
vGhetto Script Repository
Getting Started with the vMA (tips/tricks)
Getting Started with the vSphere SDK for Perl
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Nov 17, 2009 10:53 AM goppi  says: in response to: lamw

I did not realize that it was mentioned in the past that it will not be supported, so I'm sorry for missing that. With "reliable backup" I don't want to say that ghettoVCB is not reliable, so don't feel offended. However depending on the apps and the os you are running you cannot always be sure that you have a consitent state on disk when taking a snapshot while the machine is running.

This is a similar thing like with VSS on MS Windows. Without apropriate VSS writer for certain apps you are running you cannot be sure that a consitent state is written on disk when you take a snapshot. As this mechanism (IPC between app, os and vmware) is missing on VMware (or at least I'm not aware of it) with certain apps (e.g. dbms) a snapshot will have a good chance to be corrupt on application level (on filesystem level it will be intact of course).

If I'm missing anything obvious please let me know.

Regards

Nov 17, 2009 12:03 PM lamw  says: in response to: goppi

I agree, but that's where enabling the quiesce of the snapshot comes into play and of course this is also OS dependent and if you have VMware Tools installed. You'll either use the default filesystem sync driver or VSS if you're on a Windows OS. Even with using other solutions like Veeam or vDR, you're still using a snapshot like solution and they also rely on quiescing the filesystem to ensure that you have a consistent backup.

Hope this helps


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
Twitter: @lamw
vGhetto Script Repository
Getting Started with the vMA (tips/tricks)
Getting Started with the vSphere SDK for Perl
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Nov 17, 2009 12:44 PM goppi  says: in response to: lamw

Ok not sure how exactly quiesce works with VMware. From what I found so far it seems that it triggers all VSS writers and so tries to ensure all data is written to disk before taking the snapshot. So if you have a system with VSS writers for all apps properly set up this should work. I will make some tests with that option to see if it works reliable. However I thik I will modify the scripts to support taking snapshots on power down state just to be on the safe side. Seems to be possible without big changes. IMHO this is still a good option as it ensures integrity and dramatically reduces downtime compared to taking a backup in power down state.

Thanks again for developing ghettoVCB and sharing it with the community.

Regards,
goppi.

Nov 18, 2009 6:59 AM cwhitmore  says: in response to: lamw

That did it. I'm backing it up now. Thanks for your help on this and the new features.
I haven't tried the snapshot quiesce or snapshot memory, but if I'm running MS-SQL on this server is there a reason why I wouldn't use it? ( I already have VSS turned on)

Oh, one minor typo I found in the ghettVCB.sh file. You have "VMDK_FILES_TO_BACKUP=" inside the area that says not to edit below this line. No big deal, just thought you might want to know.

I work for a non-profit so we have little funds for IT. Your script has allowed us to evaluate Vmware and virtualization options. Thanks again.

Nov 18, 2009 7:05 AM lamw  says: in response to: cwhitmore

Glad to hear the new release fixed the issues.

I would definitely do some research on backing up any database systems, but there shouldn't be any reason why it won't work and I'm sure others have done it. If you already have VMware Tools installed and have VSS enabled, then yes you should be using snapshot quiesce option, the memory really is more for testing purposes and since the .vmsd and .vmss is not backed up as it only pertains to the snaspshot created.

For a deep dive on how VMware snapshots works, take a look at this VMware KB: http://kb.vmware.com/kb/1015180

Regarding the variable, I meant to put it there ;)

The reason is by default if you don't use individual VM backup policy, it'll backup all "valid" VMDK(s) ... there is no concept of an exclusion/inclusion list as that is only supported with backup policy for each VM.

=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
Twitter: @lamw
vGhetto Script Repository
Getting Started with the vMA (tips/tricks)
Getting Started with the vSphere SDK for Perl
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Nov 18, 2009 1:17 PM scowse  says: in response to: lamw

The new script is very slick - thanks very much.

Just curious about these two lines from std out:

sleep: Interrupted system call
wc: standard input: Interrupted system call

Edit: I also note that the cron faq has not been updated to the new syntax e.g. "ghettoVCB.sh -f vmlist"

Nov 18, 2009 7:43 PM lamw  says: in response to: scowse

Glad to hear you're enjoying the new features of the script!

Regarding the output, I'm not sure where thats coming from ... sounds like something might have interrupted the syscall and hence the output. Could you provide more details about your environment, ESX(i) host, version, etc...? Are you able to consistently reproduce, without reproducibility, it'll be very hard for me to help troubleshoot.

Thanks for the doc info, I'll get that updated as soon as I get a chance.

=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
Twitter: @lamw
vGhetto Script Repository
Getting Started with the vMA (tips/tricks)
Getting Started with the vSphere SDK for Perl
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Nov 18, 2009 10:16 PM scowse  says: in response to: lamw

I can reproduce my stupidity at will ;)

As you can see below setting quiesce for a vm that is not enabled will give that type of output.

Not sure why it is a bit different to the original post.

Perhaps the script could read:

  1. Quiesce VM when taking snapshot (requires VMware Tools and VSS to be installed)?

/vmfs/volumes/4a7bc59f-d1dd8294-90ca-0019d1010534/tools # ./ghettoVCB.sh -f vms 2009-11-19 05:38:51 -- info: ============================== ghettoVCB LOG START ==============================

2009-11-19 05:38:51 -- info: CONFIG - VM_BACKUP_VOLUME = /vmfs/volumes/msc009ds
2009-11-19 05:38:51 -- info: CONFIG - VM_BACKUP_ROTATION_COUNT = 1
2009-11-19 05:38:51 -- info: CONFIG - DISK_BACKUP_FORMAT = zeroedthick
2009-11-19 05:38:51 -- info: CONFIG - ADAPTER_FORMAT = lsilogic
2009-11-19 05:38:51 -- info: CONFIG - POWER_VM_DOWN_BEFORE_BACKUP = 0
2009-11-19 05:38:51 -- info: CONFIG - ENABLE_HARD_POWER_OFF = 0
2009-11-19 05:38:51 -- info: CONFIG - ITER_TO_WAIT_SHUTDOWN = 3
2009-11-19 05:38:51 -- info: CONFIG - POWER_DOWN_TIMEOUT = 5
2009-11-19 05:38:51 -- info: CONFIG - SNAPSHOT_TIMEOUT = 15
2009-11-19 05:38:51 -- info: CONFIG - LOG_LEVEL = info
2009-11-19 05:38:51 -- info: CONFIG - BACKUP_LOG_OUTPUT = stdout
2009-11-19 05:38:51 -- info: CONFIG - VM_SNAPSHOT_MEMORY = 1
2009-11-19 05:38:51 -- info: CONFIG - VM_SNAPSHOT_QUIESCE = 1
2009-11-19 05:38:51 -- info: CONFIG - VMDK_FILES_TO_BACKUP = all

2009-11-19 05:38:54 -- info: Initiate backup for PMOSTEST
2009-11-19 05:38:54 -- info: Creating Snapshot "ghettoVCB-snapshot-2009-11-19" f or PMOSTEST
sleep: Interrupted system call
sleep: Interrupted system call
Destination disk format: VMFS zeroedthick
Cloning disk '/vmfs/volumes/mnc053datastore/PMOSTEST/PMOS.vmdk'...
Clone: 100% done.
2009-11-19 05:47:28 -- info: Removing snapshot from PMOSTEST ...
2009-11-19 05:47:31 -- info: Backup Duration: 8.62 Minutes
2009-11-19 05:47:32 -- info: Successfully completed backup for PMOSTEST!

2009-11-19 05:47:32 -- info: ============================== ghettoVCB LOG END ================================

/vmfs/volumes/4a7bc59f-d1dd8294-90ca-0019d1010534/tools # ./ghettoVCB.sh -f vms
2009-11-19 05:49:11 -- info: ============================== ghettoVCB LOG START ==============================

2009-11-19 05:49:11 -- info: CONFIG - VM_BACKUP_VOLUME = /vmfs/volumes/msc009ds
2009-11-19 05:49:11 -- info: CONFIG - VM_BACKUP_ROTATION_COUNT = 1
2009-11-19 05:49:11 -- info: CONFIG - DISK_BACKUP_FORMAT = zeroedthick
2009-11-19 05:49:11 -- info: CONFIG - ADAPTER_FORMAT = lsilogic
2009-11-19 05:49:11 -- info: CONFIG - POWER_VM_DOWN_BEFORE_BACKUP = 0
2009-11-19 05:49:11 -- info: CONFIG - ENABLE_HARD_POWER_OFF = 0
2009-11-19 05:49:11 -- info: CONFIG - ITER_TO_WAIT_SHUTDOWN = 3
2009-11-19 05:49:11 -- info: CONFIG - POWER_DOWN_TIMEOUT = 5
2009-11-19 05:49:11 -- info: CONFIG - SNAPSHOT_TIMEOUT = 15
2009-11-19 05:49:11 -- info: CONFIG - LOG_LEVEL = info
2009-11-19 05:49:11 -- info: CONFIG - BACKUP_LOG_OUTPUT = stdout
2009-11-19 05:49:11 -- info: CONFIG - VM_SNAPSHOT_MEMORY = 1
2009-11-19 05:49:11 -- info: CONFIG - VM_SNAPSHOT_QUIESCE = 0
2009-11-19 05:49:11 -- info: CONFIG - VMDK_FILES_TO_BACKUP = all

2009-11-19 05:49:14 -- info: Initiate backup for PMOSTEST
2009-11-19 05:49:14 -- info: Creating Snapshot "ghettoVCB-snapshot-2009-11-19" for PMOSTEST
Destination disk format: VMFS zeroedthick
Cloning disk '/vmfs/volumes/mnc053datastore/PMOSTEST/PMOS.vmdk'...
Clone: 100% done.
2009-11-19 05:58:39 -- info: Removing snapshot from PMOSTEST ...
2009-11-19 05:58:42 -- info: Backup Duration: 9.47 Minutes
2009-11-19 05:58:42 -- info: Successfully completed backup for PMOSTEST!

2009-11-19 05:58:42 -- info: ============================== ghettoVCB LOG END ================================

Nov 18, 2009 11:05 PM lamw  says: in response to: scowse

Quiesce snapshot option and the method in which the flushing occurs is dependent on OS and whether or not you have VMware Tools installed. There's actually 3 methods and VSS is Windows only, for a deep dive on how VMware snapshots works, take a look at this VMware KB: http://kb.vmware.com/kb/1015180

The interrupt you're seeing is within the busybox console (unspported shell). Have you tried disable VM_SNAPSHOT_MEMORY and just enabling VM_SNAPSHOT_QUIESCE?

Note: VM_SNAPSHOT_MEMORY will dump the VMs state at the time of the snapshot but is not used for the backup, this is primarily for testing purposes and with this option enabled your snapshot takes longer to create + additional room for the memory state file. Generally you'll just enable VM_SNAPSHOT_QUIESCE

Is this occurring with only this VM or others? How large is the VM and what is it's OS?

=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
Twitter: @lamw
vGhetto Script Repository
Getting Started with the vMA (tips/tricks)
Getting Started with the vSphere SDK for Perl
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

Nov 19, 2009 3:33 PM scowse  says: in response to: lamw

Here is the test run as you suggested - memory snap=off and quiesce =on

This is a centos 5.3 x86_64 approx 10GB - Vmware tools installed but not sync driver (i have to find out what that is ;)

As you said it is quite a bit quicker with memory_snap off

esxi logs show:

Nov 19 21:50:15 Hostd: 2009-11-19 21:50:15.497 116C0B90 info 'vm:/vmfs/volumes/4a7bc59f-d1dd8294-90ca-0019d1010534/PMOSTEST/PMOS.vmx' Trying quiesced snapshot via SYNC driver...
Nov 19 21:50:15 Hostd: 2009-11-19 21:50:15.498 116C0B90 info 'DictionaryOptionsProvider(Config.GlobalSettings.)' Set called with key 'Config.GlobalSettings.guest.commands.sharedPolicyRefCount' value '1'
Nov 19 21:50:15 Hostd: 2009-11-19 21:50:15.514 116C0B90 verbose 'vm:/vmfs/volumes/4a7bc59f-d1dd8294-90ca-0019d1010534/PMOSTEST/PMOS.vmx' Logging into guest.
Nov 19 21:50:15 Hostd: 2009-11-19 21:50:15.516 11701B90 verbose 'vm:/vmfs/volumes/4a7bc59f-d1dd8294-90ca-0019d1010534/PMOSTEST/PMOS.vmx' Dummy foundry callback #0
Nov 19 21:50:15 Hostd: 2009-11-19 21:50:15.516 116C0B90 verbose 'vm:/vmfs/volumes/4a7bc59f-d1dd8294-90ca-0019d1010534/PMOSTEST/PMOS.vmx' About to run script: /usr/sbin/pre-freeze-script all
Nov 19 21:50:15 Hostd: 2009-11-19 21:50:15.520 2D3C2B90 verbose 'vm:/vmfs/volumes/4a7bc59f-d1dd8294-90ca-0019d1010534/PMOSTEST/PMOS.vmx' Dummy foundry callback #1
Nov 19 21:50:15 Hostd: 2009-11-19 21:50:15.520 116C0B90 info 'vm:/vmfs/volumes/4a7bc59f-d1dd8294-90ca-0019d1010534/PMOSTEST/PMOS.vmx' Script /usr/sbin/pre-freeze-script not found in VM.
Nov 19 21:50:15 Hostd: 2009-11-19 21:50:15.530 11701B90 verbose 'vm:/vmfs/volumes/4a7bc59f-d1dd8294-90ca-0019d1010534/PMOSTEST/PMOS.vmx' Dummy foundry callback #2
Nov 19 21:50:15 Hostd: 2009-11-19 21:50:15.530 116C0B90 info 'vm:/vmfs/volumes/4a7bc59f-d1dd8294-90ca-0019d1010534/PMOSTEST/PMOS.vmx' About to engage SYNC driver, freeze Timeout 15 sec.
Nov 19 21:50:15 Hostd: 2009-11-19 21:50:15.540 11701B90 verbose 'vm:/vmfs/volumes/4a7bc59f-d1dd8294-90ca-0019d1010534/PMOSTEST/PMOS.vmx' Dummy foundry callback #3
Nov 19 21:50:15 Hostd: 2009-11-19 21:50:15.540 116C0B90 info 'vm:/vmfs/volumes/4a7bc59f-d1dd8294-90ca-0019d1010534/PMOSTEST/PMOS.vmx' Sync driver not installed or not supported in guest.
Nov 19 21:50:15 Hostd: 2009-11-19 21:50:15.541 116C0B90 info 'vm:/vmfs/volumes/4a7bc59f-d1dd8294-90ca-0019d1010534/PMOSTEST/PMOS.vmx' Starting to snapshot VM.

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

/vmfs/volumes/4a7bc59f-d1dd8294-90ca-0019d1010534/tools # ./ghettoVCB.sh -f vms
2009-11-19 21:50:10 -- info: ============================== ghettoVCB LOG START ==============================

2009-11-19 21:50:10 -- info: CONFIG - VM_BACKUP_VOLUME = /vmfs/volumes/msc009ds
2009-11-19 21:50:10 -- info: CONFIG - VM_BACKUP_ROTATION_COUNT = 1
2009-11-19 21:50:10 -- info: CONFIG - DISK_BACKUP_FORMAT = zeroedthick
2009-11-19 21:50:10 -- info: CONFIG - ADAPTER_FORMAT = lsilogic
2009-11-19 21:50:10 -- info: CONFIG - POWER_VM_DOWN_BEFORE_BACKUP = 0
2009-11-19 21:50:10 -- info: CONFIG - ENABLE_HARD_POWER_OFF = 0
2009-11-19 21:50:10 -- info: CONFIG - ITER_TO_WAIT_SHUTDOWN = 3
2009-11-19 21:50:10 -- info: CONFIG - POWER_DOWN_TIMEOUT = 5
2009-11-19 21:50:10 -- info: CONFIG - SNAPSHOT_TIMEOUT = 15
2009-11-19 21:50:10 -- info: CONFIG - LOG_LEVEL = info
2009-11-19 21:50:10 -- info: CONFIG - BACKUP_LOG_OUTPUT = stdout
2009-11-19 21:50:10 -- info: CONFIG - VM_SNAPSHOT_MEMORY = 0
2009-11-19 21:50:10 -- info: CONFIG - VM_SNAPSHOT_QUIESCE = 1
2009-11-19 21:50:10 -- info: CONFIG - VMDK_FILES_TO_BACKUP = all

2009-11-19 21:50:14 -- info: Initiate backup for PMOSTEST
2009-11-19 21:50:14 -- info: Creating Snapshot "ghettoVCB-snapshot-2009-11-19" for PMOSTEST
Destination disk format: VMFS zeroedthick
Cloning disk '/vmfs/volumes/mnc053datastore/PMOSTEST/PMOS.vmdk'...
Clone: 100% done.
2009-11-19 21:56:33 -- info: Removing snapshot from PMOSTEST ...
2009-11-19 21:56:37 -- info: Backup Duration: 6.38 Minutes
2009-11-19 21:56:37 -- info: Successfully completed backup for PMOSTEST!

2009-11-19 21:56:37 -- info: ============================== ghettoVCB LOG END ================================

Nov 19, 2009 4:51 PM lamw  says: in response to: scowse

Yea when using the quiesce, it'll definitely be OS dependent. Look like in this case it was not able to use any of the drivers ...


=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
Twitter: @lamw
vGhetto Script Repository
Getting Started with the vMA (tips/tricks)
Getting Started with the vSphere SDK for Perl
VMware Code Central - Scripts/Sample code for Developers and Administrators
VMware Developer Comuunity

http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg

If you find this information useful, please award points for "correct" or "helpful".

VMware Developer

SDKs, APIs, Videos, Learn and much more in the Developer community.

Learn More

Developer Sample Code

Increase your developer productivity with VMware API sample code.

Learn More

VMworld Sessions & Labs

Online access to the latest VMworld Sessions & Labs and online services.

Learn more

Purchase PSO Credits Online

Purchase credits to redeem training and consulting services online.

Buy Now

Community Hardware Software

View reported configurations or report your own.

Learn More

VMware vSphere

Come witness the next giant leap in virtualization.

Register Today

Communities