Automated Virtual Machine Backups

Jump to: navigation, search

The following guide can be used to automate virtual machine backups on ESXi 4.x and up.

Back to Main Page.



1. Create a 'BACKUPS' folder in your datastore. 2. Enable (SSH) in esxi firewall.

  • In your esxi cosole, navigate to the configuration tab and select the security profile menu item under 'Software'.
  • Click on 'Properties' to enable remote tech support mode.

3. Download the ghettoVCB files [1] and extract and upload to your ESXi system in /vmfs/volumes/datastore1/ (use WinSCP to transfer the file) 4. Re-name the directory to 'ghettoVCB'.

5. Set script to executable:
chmod 755 /vmfs/volumes/datastore1/ghettoVCB/


1. Edit the following in the /ghettoVCB/ file:

# directory that all VM backups should go (e.g. /vmfs/volumes/SAN_LUN1/mybackupdir)

2. Create a file in /ghettoVCB called vms_to_backup and insert the names of your virtual machines, each on a new line as they are listed in your console.

Sample Execution

1. In your terminal window enter (after the #):

~ # cd /vmfs/volumes/datastore1/ghettoVCB/
/vmfs/volumes/datastore1/ghettoVCB/ # ./ -f vms_to_backup -d dryrun
  • This will not backup anything. It will just create log as if it did.

2. Check the logs in the /tmp folder


1. Setup the cronjob by appending the following line to /var/spool/cron/crontabs/root:

0 1 * * 1-5  /vmfs/volumes/datastore1/ghettoVCB/ -f /vmfs/volumes/datastore1/ghettoVCB/vms_to_backup > /vmfs/volumes/datastore1/BACKUPS/ghettoVCB-backup-$(date +\%s).log
  • This will run the cronjob at 1am Monday to Friday.

2. For esxi 4.x - Kill the current crond (cron daemon) and then restart the crond for the changes to take affect:

~ # kill $(cat /var/run/
~ # busybox crond

OR for esxi 5.x and up:

~ # kill $(cat /var/run/
~ # /usr/lib/vmware/busybox/bin/busybox crond

3. For esxi 4.x - Now that the cronjob is ready to go, you need to ensure that this cronjob will persist through a reboot. You'll need to add the following lines to /etc/rc.local AFTER the last 'fi' line:

/bin/kill $(cat /var/run/
/bin/echo "0 1 * * 1-5  /vmfs/volumes/datastore1/ghettoVCB/ -f /vmfs/volumes/datastore1/ghettoVCB/vms_to_backup > /vmfs/volumes/datastore1/BACKUPS/ghettoVCB-backup-$(date +\%s).log" >> /var/spool/cron/crontabs/root
/bin/busybox crond

OR for esxi 5.x and up: you'll need to add the following lines to /etc/rc.local.d/ BEFORE the 'exit 0' line:

/bin/kill $(cat /var/run/
/bin/echo "0 1 * * 1-5  /vmfs/volumes/datastore1/ghettoVCB/ -f /vmfs/volumes/datastore1/ghettoVCB/vms_to_backup > /vmfs/volumes/datastore1/BACKUPS/ghettoVCB-backup-$(date +\%s).log" >> /var/spool/cron/crontabs/root
/usr/lib/vmware/busybox/bin/busybox crond

4. To ensure that this is saved in the ESXi configuration, we need to manually initiate the esxi backup schedule by running:

~ # /sbin/


Test the script by entering the following at the shell prompt:

~ #  /vmfs/volumes/datastore1/ghettoVCB/ -f /vmfs/volumes/datastore1/ghettoVCB/vms_to_backup > /vmfs/volumes/datastore1/BACKUPS/ghettoVCB-backup-$(date +\%s).log
Personal tools