Here you can find the latest version of my ESX backup script.
Latest version is 2.31 and can be downloaded below.
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
- Create a SSH keypair without passphrase
- Copy the public key to the “/root/.ssh/authorized_keys” file on every ESX host
- Try to login to every host (including the one you want to run this scrip on) and check if passless login works
- tar xvfz the script to /root.
- Open the backup script and set the IDFILE variable to point to the correct secret keyfile (defaults to “/root/.ssh/id_rsa”)
- Set PATH2LUNS to point to your datastores, normally you do not need to change this (defaults to “/vmfs/volumes”)
- 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.
- 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.
- 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.
- Set DEBUG variable to “1″.
- Safe and exit the script.
- Make it executable.
- 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.
- 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).
- If you want to, edit “/etc/crontab” to make the host start the script automatically: “0 0 * * * root /root/backup_v2.31.sh 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 sendmail.sh and header.txt to fit your needs. This is easy and self-explaining.
Problems and Limitations
- So far, this script only supports the methods ONCE, DAILY, WEEKLY, MONTHLY.
- DO_BACKUP has to be the last entry in the annotations! The annotations must not contain special characters like “ö,ä,ß” and others
- From v2.3 on, the Script has been tested with vSphere 4 and vSphere 4.1 only, but should work with ESX 3.5
- The host that runs this script should see all datastores of course.
- 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
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!