Skip to content

Backup vSphere Cluster with ghettoVCB

The ghettoVCB script is a well known free backup solution for standalone ESXi Hosts created by William Lam. The script works with ESXi 3.x up to ESXi 6.7. It does not support vCenter or cluster backups out of the box but with a little workaround, you can backup virtual machines in a DRS enabled cluster. I'm using this type of backup for a couple of months without issues.

Download and prepare the ghettoVCB script. Instead of using the vib package, I'm just placing the script into my backup datastore, which is already mounted to all ESXi hosts. This allows me to configure and change everything in a central place.

SSH to the first ESXi host and run the following commands:

# cd /vmfs/volumes/backupDatastore
# mkdir ghettoVCB
# cd ghettoVCB/
# mkdir logs
# mkdir backups
# wget https://github.com/lamw/ghettoVCB/archive/master.zip
# unzip master.zip

The directory structure should look like this:

The ghettoVCB Script needs two configurations, the main config (ghettoVCB.conf) and a list of virtual machines to be included in the backup (vmlist.conf). Configuration files are located in the ghettoVCB-master directory. Configure both files to match your environment:

ghettoVCB.conf
In my configuration, I've only changed VM_BACKUP_VOLUME and VM_BACKUP_ROTATION_COUNT. For more information about configuration options, check the official documentation.

VM_BACKUP_VOLUME=/vmfs/volumes/backupDatastore/ghettoVCB/backups
DISK_BACKUP_FORMAT=thin
VM_BACKUP_ROTATION_COUNT=2
POWER_VM_DOWN_BEFORE_BACKUP=0
ENABLE_HARD_POWER_OFF=0
ITER_TO_WAIT_SHUTDOWN=3
POWER_DOWN_TIMEOUT=5
ENABLE_COMPRESSION=0
VM_SNAPSHOT_MEMORY=0
VM_SNAPSHOT_QUIESCE=0
ALLOW_VMS_WITH_SNAPSHOTS_TO_BE_BACKEDUP=0
ENABLE_NON_PERSISTENT_NFS=0
UNMOUNT_NFS=0
NFS_SERVER=
NFS_VERSION=nfs
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=0
EMAIL_SERVER_PORT=25
EMAIL_DELAY_INTERVAL=1
EMAIL_USER_NAME=
EMAIL_USER_PASSWORD=
EMAIL_TO=0
EMAIL_ERRORS_TO=
EMAIL_FROM=0
WORKDIR_DEBUG=0
VM_SHUTDOWN_ORDER=
VM_STARTUP_ORDER=

vmlist.conf
A plain list of virtual machine display names to be included in the backup.

vc.virten.lab
nsx-mgt.virten.lab
db01.virten.lab

Verify that the configuration is working by running a manual backup:

# /vmfs/volumes/backupDatastore/ghettoVCB/ghettoVCB-master/ghettoVCB.sh -f /vmfs/volumes/backupDatastore/ghettoVCB/ghettoVCB-master/vmlist.conf -g /vmfs/volumes/backupDatastore/ghettoVCB/ghettoVCB-master/ghettoVCB.conf

Please keep in mind that ghettoVCB can only backup virtual machines that are running on the ESXi host where the script has been started. The following error message is displayed when VMs are running on another ESXi host:

info: ERROR: failed to locate and extract VM_ID for db01.virten.lab!

A successful backup should look like this:

info: Initiate backup for vc.virten.lab
info: Creating Snapshot "ghettoVCB-snapshot-2020-02-08" for vc.virten.lab
Option --adaptertype is deprecated and hence will be ignored
Destination disk format: VMFS thin-provisioned
Cloning disk '/vmfs/volumes/ds2/vc.virten.lab/vc.virten.lab.vmdk'...
Clone: 100% done.

info: Removing snapshot from vc.virten.lab ...
info: Slept 1 seconds to work around NFS I/O error
info: Backup Duration: 37 Seconds
info: Successfully completed backup for vc.virten.lab!

At this point, you should be able to run manual backups from each ESXi in the cluster. The next step is to create a cronjob at an external Linux server to start the backup on all ESXi hosts one by one automatically.

  1. SSH to your Linux machine. In this example, I'm using a Debian 10.
  2. Create a user that runs the ghettoVCB Script.
    # adduser ghettoVCB
  3. Become the ghettoVCB user.
    # su - ghettovcb
  4. Create an ssh key. Make sure that you do not set a passphrase.
    # ssh-keygen
    Generating public/private rsa key pair.
    Enter file in which to save the key (/home/ghettovcb/.ssh/id_rsa):
    Created directory '/home/ghettovcb/.ssh'.
    Enter passphrase (empty for no passphrase):
    Enter same passphrase again:
    Your identification has been saved in /home/ghettovcb/.ssh/id_rsa.
    Your public key has been saved in /home/ghettovcb/.ssh/id_rsa.pub.
  5. Copy the public key.
    # cat .ssh/id_rsa.pub
    
    ssh-rsa AAAAB3NzaC[...]1yc2EAAAADA ghettovcb
  6. SSH to each ESXi Host and add the public key to root users authorized_keys.
    # echo "ssh-rsa AAAAB3NzaC[...]1yc2EAAAADA ghettovcb" >> /etc/ssh/keys-root/authorized_keys
  7. Back to your Linux host, verify that it can connect to ESXi Hosts without a password. This step is mandatory for all ESXi hosts as you have to accept each host's fingerprint manually once.
    # ssh root@esx1.virten.lab 'hostname'
    The authenticity of host 'esx1.virten.lab' can't be established.
    ECDSA key fingerprint is SHA256:7nJ[...]
    Are you sure you want to continue connecting (yes/no)? yes
    # ssh root@esx2.virten.lab 'hostname'
    The authenticity of host 'esx2.virten.lab' can't be established.
    ECDSA key fingerprint is SHA256:DmC[...]
    Are you sure you want to continue connecting (yes/no)? yes
  8. Create a script (remoteGhettoVCB.sh) with the following content. Make sure to configure datastore path and ESXi hostnames to match your environment:
    #!/bin/bash
    
    GHETTOPATH=/vmfs/volumes/backupDatastore/ghettoVCB/ghettoVCB-master
    GHETTOLOGDIR=/vmfs/volumes/backupDatastore/ghettoVCB/logs
    
    for i in esx1.virten.lab esx2.virten.lab esx3.virten.lab
    do
     echo Starting Backup on Host $i
     /usr/bin/ssh root@$i "$GHETTOPATH/ghettoVCB.sh -f $GHETTOPATH/vmlist.conf -g $GHETTOPATH/ghettoVCB.conf -l $GHETTOLOGDIR/$i-$(date +%Y-%m-%d-%H%M).log"
    done
    
    
  9. Make the script executable
    # chmod +x remoteGhettoVCB.sh
  10. Create a cronjob that runs the backup job daily at 2:30 AM (or whenever you want to start the backup):
    # crontab -e
    
    30 2 * * * /home/ghettovcb/remoteGhettoVCB.sh >> /var/log/ghettovcb.log
  11. That's it. You can run the remoteGhettoVCB.sh script once to verify that it runs successfully.

To verify that backups are created without errors, check the /var/log/ghettovcb.log file on the Linux machine, or individual backup job logs at /vmfs/volumes/backupDatastore/ghettoVCB/logs/

6 thoughts on “Backup vSphere Cluster with ghettoVCB”

  1. Good stuff, for "anonymous"dont use esxi 7.0.Good that you explaind GhettoVCB because afte i installed the .vib, I could not modify the .sh.
    Had to move it like you describe to another location, then customize, then chmod, then i could run it.

Leave a Reply to Anonymous Cancel reply

Your email address will not be published. Required fields are marked *