From 8cde048ed0a322f9fabc75cbde56e2a2fd42a220 Mon Sep 17 00:00:00 2001 From: Johan K Date: Mon, 15 Mar 2021 10:53:30 +0100 Subject: [PATCH 1/3] fix #157 and #83 (and situation when good VMs name is a substring of a PROBLEM_VM) --- ghettoVCB-VMDKexclude.sh | 2 +- ghettoVCB.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ghettoVCB-VMDKexclude.sh b/ghettoVCB-VMDKexclude.sh index 8259f38..66e1888 100644 --- a/ghettoVCB-VMDKexclude.sh +++ b/ghettoVCB-VMDKexclude.sh @@ -223,7 +223,7 @@ logger() { LOG_TYPE=$1 MSG=$2 - if [[ "${LOG_LEVEL}" == "debug" ]] && [[ "${LOG_TYPE}" == "debug" ]] || [[ "${LOG_TYPE}" == "info" ]] || [[ "${LOG_TYPE}" == "dryrun" ]]; then + if [[ "${LOG_LEVEL}" == "debug" ]] && [[ "${LOG_TYPE}" == "debug" ]] || [[ "${LOG_TYPE}" == "info" ]] || [[ "${LOG_TYPE}" == "error" ]] ||[[ "${LOG_TYPE}" == "dryrun" ]]; then TIME=$(date +%F" "%H:%M:%S) if [[ "${LOG_TO_STDOUT}" -eq 1 ]] ; then echo -e "${TIME} -- ${LOG_TYPE}: ${MSG}" diff --git a/ghettoVCB.sh b/ghettoVCB.sh index c33c336..18cef88 100755 --- a/ghettoVCB.sh +++ b/ghettoVCB.sh @@ -8,7 +8,7 @@ # User Definable Parameters ################################################################## -LAST_MODIFIED_DATE=2020_12_28 +LAST_MODIFIED_DATE=2021_03_15 VERSION=1 # directory that all VM backups should go (e.g. /vmfs/volumes/SAN_LUN1/mybackupdir) @@ -958,7 +958,7 @@ ghettoVCB() { fi if [[ "${IGNORE_VM}" -eq 0 ]] && [[ -n "${PROBLEM_VMS}" ]] ; then - if [[ "$(echo $PROBLEM_VMS | sed "s@$VM_NAME@@")" != "$PROBLEM_VMS" ]] ; then + if [[ " ${PROBLEM_VMS} " == *" ${VM_NAME} "* ]] ; then logger "info" "Ignoring ${VM_NAME} as a problem VM\n" IGNORE_VM=1 #A VM ignored due to a problem, should be treated as a failure From d6a43be90bf71df640860aae80a70c7ace7a438a Mon Sep 17 00:00:00 2001 From: Johan K Date: Mon, 15 Mar 2021 10:59:26 +0100 Subject: [PATCH 2/3] use integer comparisons --- ghettoVCB.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ghettoVCB.sh b/ghettoVCB.sh index 18cef88..37ad9ea 100755 --- a/ghettoVCB.sh +++ b/ghettoVCB.sh @@ -1260,7 +1260,7 @@ ghettoVCB() { echo rm "${VMDK_OUTPUT}" - if [[ "${VMDK_EXIT_CODE}" != 0 ]] ; then + if [[ "${VMDK_EXIT_CODE}" -ne 0 ]] ; then logger "info" "ERROR: error in backing up of \"${SOURCE_VMDK}\" for ${VM_NAME}" VM_VMDK_FAILED=1 fi @@ -1436,31 +1436,31 @@ getFinalStatus() { FINAL_STATUS="###### Final status: OK, only a dryrun. ######" LOG_STATUS="OK" EXIT=0 - elif [[ $VM_OK == 1 ]] && [[ $VM_FAILED == 0 ]] && [[ $VMDK_FAILED == 0 ]]; then + elif [[ $VM_OK -eq 1 ]] && [[ $VM_FAILED -eq 0 ]] && [[ $VMDK_FAILED -eq 0 ]]; then FINAL_STATUS="###### Final status: All VMs backed up OK! ######" LOG_STATUS="OK" EXIT=0 - elif [[ $VM_OK == 1 ]] && [[ $VM_FAILED == 0 ]] && [[ $VMDK_FAILED == 1 ]]; then + elif [[ $VM_OK -eq 1 ]] && [[ $VM_FAILED -eq 0 ]] && [[ $VMDK_FAILED -eq 1 ]]; then FINAL_STATUS="###### Final status: WARNING: All VMs backed up, but some disk(s) failed! ######" LOG_STATUS="WARNING" EXIT=3 - elif [[ $VM_OK == 1 ]] && [[ $VM_FAILED == 1 ]] && [[ $VMDK_FAILED == 0 ]]; then + elif [[ $VM_OK -eq 1 ]] && [[ $VM_FAILED -eq 1 ]] && [[ $VMDK_FAILED -eq 0 ]]; then FINAL_STATUS="###### Final status: ERROR: Only some of the VMs backed up! ######" LOG_STATUS="ERROR" EXIT=4 - elif [[ $VM_OK == 1 ]] && [[ $VM_FAILED == 1 ]] && [[ $VMDK_FAILED == 1 ]]; then + elif [[ $VM_OK -eq 1 ]] && [[ $VM_FAILED -eq 1 ]] && [[ $VMDK_FAILED -eq 1 ]]; then FINAL_STATUS="###### Final status: ERROR: Only some of the VMs backed up, and some disk(s) failed! ######" LOG_STATUS="ERROR" EXIT=5 - elif [[ $VM_OK == 0 ]] && [[ $VM_FAILED == 1 ]]; then # $VMDK_FAILED doesn't matter in this case + elif [[ $VM_OK -eq 0 ]] && [[ $VM_FAILED -eq 1 ]]; then # $VMDK_FAILED doesn't matter in this case FINAL_STATUS="###### Final status: ERROR: All VMs failed! ######" LOG_STATUS="ERROR" EXIT=6 - elif [[ $VM_OK == 0 ]] && [[ $VM_FAILED == 0 ]] && [[ $VMDK_FAILED == 0 ]]; then + elif [[ $VM_OK -eq 0 ]] && [[ $VM_FAILED -eq 0 ]] && [[ $VMDK_FAILED -eq 0 ]]; then FINAL_STATUS="###### Final status: ERROR: No VMs backed up! ######" LOG_STATUS="ERROR" EXIT=7 - elif [[ $VM_OK == 0 ]] && [[ $VM_FAILED == 0 ]] && [[ $VMDK_FAILED == 1 ]]; then + elif [[ $VM_OK -eq 0 ]] && [[ $VM_FAILED -eq 0 ]] && [[ $VMDK_FAILED -eq 1 ]]; then FINAL_STATUS="###### Final status: ERROR: All VMs experienced at least a partial failure! ######" LOG_STATUS="ERROR" EXIT=8 From 532dee5120979cb9150133e91a2f56dedd27fd46 Mon Sep 17 00:00:00 2001 From: jokjr <69192941+jokjr@users.noreply.github.com> Date: Mon, 15 Mar 2021 11:04:34 +0100 Subject: [PATCH 3/3] Update ghettoVCB-VMDKexclude.sh Missing space --- ghettoVCB-VMDKexclude.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ghettoVCB-VMDKexclude.sh b/ghettoVCB-VMDKexclude.sh index 66e1888..447e998 100644 --- a/ghettoVCB-VMDKexclude.sh +++ b/ghettoVCB-VMDKexclude.sh @@ -223,7 +223,7 @@ logger() { LOG_TYPE=$1 MSG=$2 - if [[ "${LOG_LEVEL}" == "debug" ]] && [[ "${LOG_TYPE}" == "debug" ]] || [[ "${LOG_TYPE}" == "info" ]] || [[ "${LOG_TYPE}" == "error" ]] ||[[ "${LOG_TYPE}" == "dryrun" ]]; then + if [[ "${LOG_LEVEL}" == "debug" ]] && [[ "${LOG_TYPE}" == "debug" ]] || [[ "${LOG_TYPE}" == "info" ]] || [[ "${LOG_TYPE}" == "error" ]] || [[ "${LOG_TYPE}" == "dryrun" ]]; then TIME=$(date +%F" "%H:%M:%S) if [[ "${LOG_TO_STDOUT}" -eq 1 ]] ; then echo -e "${TIME} -- ${LOG_TYPE}: ${MSG}"