ESX Backup

Here you can find the latest version of my ESX backup script.

Latest version is 2.31 and can be downloaded below.
Attention, this version is outdated as by Feb. 2007! Ye be warned ;)

This script makes backing up VMs very easy, because you don’t have to mess around with vcbmounter. You only have to configure keywords in the VMs annotations to make it work.
If you set the annotations to be „This is a test machine ony. DO_BACKUP=DAILY“, then this script backups the VM on a daily basis and keeps the backup for as long as you set the grace period to be (default 7 days/weeks/months).

IMPORTANT – How to configure this script

  1. Create a SSH keypair without passphrase
  2. Copy the public key to the „/root/.ssh/authorized_keys“ file on every ESX host
  3. Try to login to every host (including the one you want to run this scrip on) and check if passless login works
  4. tar xvfz the script to /root.
  5. Open the backup script and set the IDFILE variable to point to the correct secret keyfile (defaults to „/root/.ssh/id_rsa“)
  6. Set PATH2LUNS to point to your datastores, normally you do not need to change this (defaults to „/vmfs/volumes“)
  7. Set BACKLUNID to contain some string that identifies you backup datastores (defaults to „BACK“). I recommend to name all your backup datastores to something sane like LUN0_BACK or LUN_SQL_BACK or WHATEVER_BACK.
  8. Set your ESX hosts using the ESX variable. This is a space separated list of all the ESX hosts this script hast to query for running machines. Use only resolvable names of the host, as the ssh logins depend on this.
  9. Set the grace times (in hours). This defaults to 7 days, 7 weeks, 7 months, which means you have backups for every DAILY VM of the last 7 days and so on.
  10. Set DEBUG variable to „1“.
  11. Safe and exit the script.
  12. Make it executable.
  13. On each of your backup LUNs create these directories: ONCE, DAILY, WEEKLY, MONTHLY. If these are not created or something goes wrong during datastore detection, the script aborts for security reasons.
  14. Start the script. It should be in DEBUG mode and not create/delete any files. If everthing seems clean, set the DEBUG variable to „0“ (zero).
  15. If you want to, edit „/etc/crontab“ to make the host start the script automatically: „0 0 * * * root /root/ 2>&1 >/tmp/backup.log“ will make it start every day of the week at midnight. The output will be written to „/tmp/backup.log“ for later examination or to be mailed to you using the helper files.

If you need notification via eMail, you have to modify the helper files and header.txt to fit your needs. This is easy and self-explaining.

Problems and Limitations

  1. So far, this script only supports the methods ONCE, DAILY, WEEKLY, MONTHLY.
  2. DO_BACKUP has to be the last entry in the annotations! The annotations must not contain special characters like „ö,ä,ß“ and others
  3. From v2.3 on, the Script has been tested with vSphere 4 and vSphere 4.1 only, but should work with ESX 3.5
  4. The host that runs this script should see all datastores of course.
  5. This script will NOT work with ESXi, because ESXi has no VCB tools installed.



option 1: only the pure backup AND restore script as tar.gz
option 2: with helper files for mail notification again as tar.gz

option 1: esxbackup-2.31.tar.gz
option 2: esxbackup-helpers-2.31.tar.gz

Please be aware, that these files are provided without ANY warranty. If you do not know how to configure the script correctly IT MIGHT BE POSSIBLE to destroy production VMs on your platform. Use with care and at your own risk!