VMware Backups

Update: I have now written another backup script which is based on VMware Consolidated Backup (VCB) which you can download from VMware for Windows systems. It is about 10 times faster at backing up than JKFBackup.sh and will totally saturate a 1Gbps ethernet link. I can get networked backup speeds of 100Mbytes/second with it!

I have written my own script to backup VMware volumes. On a vSphere, it can mount all the datastores available on a node simply by running on that node. It backups to an NFS datastore which it will optionally mount and dismount for you. It will also optionally backup just VMs that are powered on, VMs that are powered off and templates, and compress the virtual hard disk files.

As far as I am aware it probably does not yet handle a VM that is spread across several datastores, it assumes the files are kept together in one directory for each VM.

It was written to suit our environment, and we don't spread a VM across several datastores. Happy

The usage is
JKFBackup.sh [ --off ] [ --on ] [ --compress ]
JKFBackup.sh --help
to get the command-line usage.

--off tells it to backup templates and VMs that are powered off.
--on tells it to backup VMs that are powered on.
--compress tells it to compress the virtual hard disk files of the VMs and templates that is backing up.
The 3 command line options may be specified in any order.

There are a few things you will need to set in your script to fit your local environment, these are documented at the top of the script so you can quickly get started. These defined the NFS datastore where you want all the backups to go, what backup rota you want, and what datastores to backup. It's all pretty obvious.

To get this onto your VMware server you will need to
enable ssh logins, and if you want it to run regularly then you will need to add it to your root crontab.

You can download version
1.00 of the script. Note that you should not try to edit it on Microsoft Windows systems, certainly not using Notepad, as it is a Unix text file and the line-ending characters are different so Windows will tend to screw the file completely. Learn the basics of using the "vi" text editor and edit it on your VMware server. You will need to edit it a little bit to set it appropriately for your VMware organisation.

Install the script within
/vmfs/volumes/*. In other words, it must be stored on one of your VMware datastores. Otherwise it will be automatically deleted every time your ESX/ESXi server boots as part of its house-keeping. If you store it in one of your datastores it will be left alone when the server boots up.

Don't forget to back up your backup scripts!

When you come to need to recover from a backup, copy the files back onto your VMware server using the "Browse datastore" functionality, then uncompress the
.vmdk.gz files if necessary using the "gunzip" command while logged into your ESX/ESXi server using ssh or PuTTY, then register the .vmx files by right-clicking on them in the "Browse datastore" function in the vSphere client. That will re-register your restored virtual machines.