Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After help text is displayed, exit. Spaces in the end of lines were remo... #50

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
28 changes: 23 additions & 5 deletions README
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
Author: William Lam
Website: http://www.virtuallyghetto.com/
# ghettoVCB

ghettoVCB Documentation - http://communities.vmware.com/docs/DOC-8760
ghettoVCB VMTN Group - http://communities.vmware.com/groups/ghettovcb
ghettoVCB Restore Documentation - http://communities.vmware.com/docs/DOC-10595
### Description

The ghettoVCB script performs backups of virtual machines residing on ESX(i) 3.x, 4.x, 5.x & 6.x servers using methodology similar to VMware's VCB tool. The script takes snapshots of live running 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 ESXi Shell running the backups as opposed to following the traditional method of offloading virtual machine backups through a VCB proxy.

### How to install

You can quickly install ghettoVCB by downloading and install either the VIB or offline bundle using the following commands:

Install VIB
```
esxcli software vib install -v /vghetto-ghettoVCB.vib -f
```

Install offline bundle
```
esxcli software vib install -d /vghetto-ghettoVCB-offline-bundle.zip -f
```

### Additional Documentation & Resources
- [ghettoVCB Documentation](http://communities.vmware.com/docs/DOC-8760)
- [ghettoVCB VMTN Group](http://communities.vmware.com/groups/ghettovcb)
- [ghettoVCB Restore Documentation](http://communities.vmware.com/docs/DOC-10595)
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
ghettoVCB
===
This modified bundle is based on fork of lamw/ghettoVCB master branch.

Author: William Lam
Website: http://www.virtuallyghetto.com/

ghettoVCB Documentation - http://communities.vmware.com/docs/DOC-8760
ghettoVCB VMTN Group - http://communities.vmware.com/groups/ghettovcb
ghettoVCB Restore Documentation - http://communities.vmware.com/docs/DOC-10595

-----------
**NOTE!**

> You will use this bundle in your environment at your own risk. The authors of this package can not be held responsible for any issues this bundle may cause in your system.

================

History of modifications:
===

- 11.11.15 Merged modifications of lamw/ghettoVCB until 07.11.2015 into this bundle. Additional fixes and modifications listed below are included in this bundle.

- 06.11.15 Merged modifications of lamw/ghettoVCB until 05.11.2015 into this bundle.

- 23.10.14 Fixed value displayed as "DST_DATASTORE_FREE" in debug mode. Fixed message when faulty backup is deleted to match situation where nothing is deleted (VM_BACKUP_ROTATION_COUNT). Do not continue backup of vm if backup of vmdk's of it has failed for some reason.

- 22.10.14 Fixed value displayed as "SRC_DATASTORE_FREE" in debug mode. Command'.. | grep -i "capacity" ..' returned two values in VMware 5.5.0: "maxVirtualDiskCapacity" and "capacity" => parameter -i removed.

- 17.10.14 Fixed errors with optional pause: do not pause after last vmdk of vm. Added more debug messages.

- 16.10.14 Fixed message "Succesfully removed lock directory" of debug mode. In case backup of any vmdk's of vm fails, make backup of vm fail too: do not compress faulty backup if compress is enabled (ENABLE_COMPRESSION), instead delete this faulty backup (in checkVMBackupRotation). Prev. is fix for symlink creation too because it has not been created in this case while backups were anyway rotated (RSYNC_LINK,SYMLINK_SRC). Changed location of compress and rsync blocks. Optional pause between backup of vmdk's (debug "file already exist" errors).

- 01.10.14 Added VMKFSTOOLS_CMD_OPTIONS for VMKFSTOOLS_CMD command (f.ex VMKFSTOOLS_CMD_OPTIONS="-v 10")

- 05.09.14 In ghettoVCB.sh fixed typo indepdenent => independent.

- 29.08.14 Fixed handling of "-w" parameter, it does not have to be located before parameters -a and -m on command line anymore.
Trap settings for removing workdir modified in case WORKDIR_DEBUG=1,
also fixed call of reConfigureGhettoVCBConfiguration which was placed too late inside sanityCheck.
NOTE! Remember to use own ghettoVCB specific temp directory for WORKDIR, it may be removed in the end of script.
In ghettoVCB-restore.sh fixed one typo.

- 27.08.14 Fixed status messages of dryrun.
Fixed "Final status" message when VM has independant VMDKs and at least one normal VMDK.

- 23.08.14 Forked from https://github.com/lamw/ghettoVCB.git.
After help text is displayed, exit.
Spaces in the end of lines were removed by editor. Real modifications have been marked with dates.


========================
26 changes: 16 additions & 10 deletions ghettoVCB-restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

###### DO NOT EDIT PASS THIS LINE ######

LAST_MODIFIED_DATE=2013_01_11
VERSION=0
LAST_MODIFIED_DATE=2015_04_04
VERSION=1
VERSION_STRING=${LAST_MODIFIED_DATE}_${VERSION}

printUsage() {
echo "###############################################################################"
echo "#"
echo "# ghettoVCB-restore for ESX/ESXi 3.5, 4.x and 5.x"
echo "# ghettoVCB-restore for ESX/ESXi 3.5, 4.x, 5.x & 6.x"
echo "# Author: William Lam"
echo "# http://www.virtuallyghetto.com/"
echo "# Documentation: http://communities.vmware.com/docs/DOC-8760"
Expand Down Expand Up @@ -85,18 +85,19 @@ sanityCheck() {
VMWARE_CMD=/bin/vim-cmd
VMKFSTOOLS_CMD=/sbin/vmkfstools
else
logger "ERROR: Unable to locate *vimsh*! You're not running ESX(i) 3.5+, 4.x, 5.x!"
echo "ERROR: Unable to locate *vimsh*! You're not running ESX(i) 3.5+, 4.x, 5.x!"
logger "ERROR: Unable to locate *vimsh*! You're not running ESX(i) 3.5+, 4.x+, 5.x+ or 6.x!"
echo "ERROR: Unable to locate *vimsh*! You're not running ESX(i) 3.5+, 4.x+, 5.x+ or 6.x!"
exit
fi

ESX_VERSION=$(vmware -v | awk '{print $3}')

case "${ESX_VERSION}" in
6.0.0) VER=6; break;;
5.0.0|5.1.0|5.5.0) VER=5; break;;
4.0.0|4.1.0) VER=4; break;;
3.5.0|3i) VER=3; break;;
*) echo "You're not running ESX(i) 3.5, 4.x, 5.x!"; exit 1; break;;
*) echo "You're not running ESX(i) 3.5, 4.x, 5.x & 6.x!"; exit 1; break;;
esac

TAR="tar"
Expand Down Expand Up @@ -159,11 +160,16 @@ ghettoVCBrestore() {
fi

#supports DIR or .TGZ from ghettoVCB.sh ONLY!
if [ ${VM_TO_RESTORE##*.} == 'gz' ]; then
logger "GZ found, extracting ..."
${TAR} -xzf $VM_TO_RESTORE -C `dirname $VM_TO_RESTORE`
VM_TO_RESTORE=${VM_TO_RESTORE%.*}
fi
if [ -d "${VM_TO_RESTORE}" ]; then
#figure out the contents of the directory (*.vmdk,*-flat.vmdk,*.vmx)
VM_ORIG_VMX=$(ls "${VM_TO_RESTORE}" | grep ".vmx")
VM_VMDK_DESCRS=$(ls "${VM_TO_RESTORE}" | grep ".vmdk" | grep -v "\-flat.vmdk")
VMDKS_FOUND=$(grep -iE '(scsi|ide)' "${VM_TO_RESTORE}/${VM_ORIG_VMX}" | grep -i fileName | awk -F " " '{print $1}')
VMDKS_FOUND=$(grep -iE '(scsi|ide|sata)' "${VM_TO_RESTORE}/${VM_ORIG_VMX}" | grep -i fileName | awk -F " " '{print $1}')
VM_FOLDER_NAME=$(echo "${VM_TO_RESTORE##*/}")

# Default to original VM Display Name if custom name is not specified
Expand Down Expand Up @@ -248,7 +254,7 @@ if [ ! "${IS_TGZ}" == "1" ]; then
else
#validates the datastore to restore is valid and available
if [ ! -d "${DATASTORE_TO_RESTORE_TO}" ]; then
logger "ERROR: Unable to verify datastore locateion: \"${DATASTORE_TO_RESTORE_TO}\"! Ensure this exists"
logger "ERROR: Unable to verify datastore location: \"${DATASTORE_TO_RESTORE_TO}\"! Ensure this exists"
#validates that all 4 required variables are defined before continuing

elif [[ -z "${VM_RESTORE_VMX}" ]] && [[ -z "${VM_VMDK_DESCRS}" ]] && [[ -z "${VM_DISPLAY_NAME}" ]] && [[ -z "${VM_RESTORE_FOLDER_NAME}" ]]; then
Expand Down Expand Up @@ -319,7 +325,7 @@ if [ ! "${IS_TGZ}" == "1" ]; then
ADAPTER_FORMAT=$(grep -i "ddb.adapterType" "${SOURCE_VMDK}" | awk -F "=" '{print $2}' | sed -e 's/^[[:blank:]]*//;s/[[:blank:]]*$//;s/"//g')

if [ ${RESTORE_DISK_FORMAT} -eq 1 ]; then
if [[ "${VER}" == "4" ]] || [[ "${VER}" == "5" ]]; then
if [[ "${VER}" == "4" ]] || [[ "${VER}" == "5" ]] || [[ "${VER}" == "6" ]] ; then
${VMKFSTOOLS_CMD} -i "${SOURCE_VMDK}" -a "${ADAPTER_FORMAT}" -d zeroedthick "${DESTINATION_VMDK}" 2>&1 | tee "${REDIRECT}"
else
${VMKFSTOOLS_CMD} -i "${SOURCE_VMDK}" -a "${ADAPTER_FORMAT}" "${DESTINATION_VMDK}" 2>&1 | tee "${REDIRECT}"
Expand All @@ -332,7 +338,7 @@ if [ ! "${IS_TGZ}" == "1" ]; then
${VMKFSTOOLS_CMD} -i "${SOURCE_VMDK}" -a "${ADAPTER_FORMAT}" -d thin "${DESTINATION_VMDK}" 2>&1 | tee "${REDIRECT}"

elif [ ${RESTORE_DISK_FORMAT} -eq 4 ]; then
if [[ "${VER}" == "4" ]] || [[ "${VER}" == "5" ]]; then
if [[ "${VER}" == "4" ]] || [[ "${VER}" == "5" ]] || [[ "${VER}" == "6" ]] ; then
${VMKFSTOOLS_CMD} -i "${SOURCE_VMDK}" -a "${ADAPTER_FORMAT}" -d eagerzeroedthick "${DESTINATION_VMDK}" 2>&1 | tee "${REDIRECT}"
else
${VMKFSTOOLS_CMD} -i "${SOURCE_VMDK}" -a "${ADAPTER_FORMAT}" "${DESTINATION_VMDK}" 2>&1 | tee "${REDIRECT}"
Expand Down
2 changes: 2 additions & 0 deletions ghettoVCB.conf
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ NFS_MOUNT=/nfsshare
NFS_LOCAL_NAME=nfs_storage_backup
NFS_VM_BACKUP_DIR=mybackups
SNAPSHOT_TIMEOUT=15
EMAIL_ALERT=0
EMAIL_LOG=0
EMAIL_SERVER=auroa.primp-industries.com
EMAIL_SERVER_PORT=25
EMAIL_DELAY_INTERVAL=1
EMAIL_TO=auroa@primp-industries.com
EMAIL_ERRORS_TO=
EMAIL_FROM=root@ghettoVCB
WORKDIR_DEBUG=0
VM_SHUTDOWN_ORDER=
Expand Down
Loading