From ac7540e4af9f066df279f7f4acd304f10d6821c5 Mon Sep 17 00:00:00 2001 From: dcec Date: Fri, 10 May 2013 10:19:27 +0200 Subject: [PATCH] Fix problem when VM has snapshots Fix the problem when VM has snapshots and ALLOW_VMS_WITH_SNAPSHOTS_TO_BE_BACKEDUP=1 --- ghettoVCB.sh | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/ghettoVCB.sh b/ghettoVCB.sh index 81c3ddd..0d1fb92 100755 --- a/ghettoVCB.sh +++ b/ghettoVCB.sh @@ -823,7 +823,16 @@ ghettoVCB() { if [[ ! -z ${VM_ID} ]] && [[ "${LOG_LEVEL}" != "dryrun" ]]; then storageInfo "before" fi - + + #check if vms has snapshot + if ls "${VMX_DIR}" | grep -q "\-delta\.vmdk" > /dev/null 2>&1; then + VMS_WITH_SNAPSHOTS=1 + logger "debug" "Snapshot found for ${VM_NAME}.\n" + else + VMS_WITH_SNAPSHOTS=0 + logger "debug" "Snapshot not found for ${VM_NAME}.\n" + fi + #ignore VM as it's in the exclusion list if [[ "${IGNORE_VM}" -eq 1 ]] ; then logger "debug" "Ignoring ${VM_NAME} for backup since its located in exclusion list\n" @@ -888,13 +897,11 @@ ghettoVCB() { logger "dryrun" "###############################################\n" #checks to see if the VM has any snapshots to start with - elif ls "${VMX_DIR}" | grep -q "\-delta\.vmdk" > /dev/null 2>&1; then - if [ ${ALLOW_VMS_WITH_SNAPSHOTS_TO_BE_BACKEDUP} -eq 0 ]; then + elif [[ ${ALLOW_VMS_WITH_SNAPSHOTS_TO_BE_BACKEDUP} -eq 0 ]] && [[ $VMS_WITH_SNAPSHOTS -eq 1 ]]; then logger "info" "Snapshot found for ${VM_NAME}, backup will not take place\n" VM_FAILED=1 - fi elif [[ -f "${VMX_PATH}" ]] && [[ ! -z "${VMX_PATH}" ]]; then - if ls "${VMX_DIR}" | grep -q "\-delta\.vmdk" > /dev/null 2>&1; then + if [ $VMS_WITH_SNAPSHOTS -eq 1 ]; then if [ ${ALLOW_VMS_WITH_SNAPSHOTS_TO_BE_BACKEDUP} -eq 1 ]; then logger "info" "Snapshot found for ${VM_NAME}, consolidating ALL snapshots now (this can take awhile) ...\n" $VMWARE_CMD vmsvc/snapshot.removeall ${VM_ID} > /dev/null 2>&1