Written on 13. July 2022

VMware ESXi free backup with ghettoVCB

For some servers, which run in a development enviromente on a free ESXi, I needed a solution to backup them daily. I deciced to do it with https://github.com/lamw/ghettoVCB, because it is easy to handle. Unfortunately it only takes full backups, which can be a problem in the duration of a very large vm, but for the development system it works perfectly.

Prerequisites

The ssh services needs to be permanently activated on the ESXi Server.

Installation

Download the latest .vib file from the mentioned github repository and place it on your ESXi datastore. Switch to the datastore and install it.

cd /vmfs/volumes/datastore1/ghettoVCB
esxcli software vib install -v /vghetto-ghettoVCB.vib -f

Now you should see a new folder structure /opt/ghettovcb.

Configuration

Switch to the /bin folder and open the ghettoVCB.sh.

cd bin
vi ghettoVCB.sh

In this file you can do some initial configuration. I configured the following parts:

  • VM_BACKUP_ROTATION_COUNT=2
  • POWER_VM_DOWN_BEFORE_BACKUP=0
  • ALLOW_VMS_WITH_SNAPSHOTS_TO_BE_BACKEDUP=0
  • ENABLE_NON_PERSISTENT_NFS=1
  • UNMOUNT_NFS=1
  • NFS_SERVER=192.168.178.200
  • NFS_VERSION=nfs
  • NFS_MOUNT=/backup
  • NFS_LOCAL_NAME=backup
  • NFS_VM_BACKUP_DIR=vm_backups

Also it’s very nice to receive an E-Mail about the backup status. You can configure the neccessary fiels in the EMAIL CONFIGURATIONS section:

  • EMAIL_ALERT=1
  • EMAIL_LOG=1
  • EMAIL_SERVER=192.168.178.254
  • EMAIL_SERVER_PORT=25
  • EMAIL_FROM=ghettoVCB@stangneth.com
  • EMAIL_TO=mailbox@stangneth.com

E-Mail Firewall rule

To allow E-Mail traffic on port 25 through the ESXi Firewall you need to create an firewall entry. Create a file called smtp.xml.

vi /etc/vmware/firewall/smtp.xml

File it with the following information.

<ConfigRoot>
  <service id='1010'>
    <id>SMTP-Client</id>
    <rule id='0000'>
      <direction>outbound</direction>
      <protocol>tcp</protocol>
      <porttype>dst</porttype>
      <port>25</port>
    </rule>
    <enabled>true</enabled>
    <required>false</required>
  </service>
</ConfigRoot>

Restart the firewall service.

esxcli network firewall refresh

These configuration is lost after a reboot. Copy the smtp.xml file to a datastore.

cp /etc/vmware/firewall/smtp.xml /vmfs/volumes/datastore1/ghettovcb/

In the section “Automation / cron” of this article you can find the config for recopying this file to the neccessary location.

Test

Now the initial configuration is done an we can check if we can backup a vm with the following command.

./ghettoVCB.sh -m VMNAME

If everything works you should see a new folder on your NFS store (or what you configured) with all VM-Files.

Automation / cron

If you just create a task in /var/spool/cron/crontabs/root you’ll lose the entries after a reboot of the ESXi server. To recreate the entry every startup to the following.

vi /etc/rc.local.d/local.sh

Here you can enter your backup command before the exit 0

### ghettoVCB Cronjob
/bin/kill $(cat /var/run/crond.pid)
/bin/echo "0 14 * * 1-5 /opt/ghettovcb/bin/ghettoVCB.sh -f /vmfs/volumes/datastore1/ghettoVCB/server.txt"
/usr/lib/vmware/busybox/bin/busybox crond
### SMTP Firewall rule
/bin/cp /vmfs/volumes/datastore1/ghettovcb/smtp.xml /etc/vmware/firewall
/bin/esxcli network firewall refresh

I used the -f command to attach a list of the vms which should be in the backup task instead of -m for every single vm.

Be sure to make a backup of ghettoVCB.sh on a persistent datastore so you won’t loose it due to an update.

cp -a /opt/ghettovcb/bin/ghettoVCB.sh /vmfs/volumes/datastore1/ghettovcb/ghettoVCB.sh

No Comments on VMware ESXi free backup with ghettoVCB

Leave a Reply

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