VMWare ESX Backup Script
January 2nd, 2009 Category: VMWareThere is a simple method doing automated backups using VMWare Infrastructure 3. For this reason a command “vcbMounter” is included. Also the name of this command is confusing it can be used for doing backups of virtual machines.
Doing a backup of a virtual machine can be done using a single command line call:
vcbMounter -a name:"Virtual-Machine-1" -r "/path/to/backup/Virtual-Machine-1"
Ok, your vm named “Virtual-Machine-1″ will now be backuped to the given path. The directory is generated from vcbMounter. The next time you will run vcbMounter it will complain that the directory already exists, so you will have to delete the directory every time before you start the backup:
rm -rf "/path/to/backup/Virtual-Machine-1" vcbMounter -a name:"Virtual-Machine-1" -r "/path/to/backup/Virtual-Machine-1"
But there is another problem which will cause vcbMounter to complain: For every backup vcbMounter generates a snapshot and will not remove it after backup. What we need is to delete the snapshot before we backup:
vmware-cmd "/vmfs/volumes/storage1/Virtual-Machine-1.vmx" removesnapshots rm -rf "/path/to/backup/Virtual-Machine-1" vcbMounter -a name:"Virtual-Machine-1" -r "/path/to/backup/Virtual-Machine-1"
We delete the snapshots for a given virtual machine using “vmware-cmd” and removesnapshots. vmware-cmd needs the path to your .vmx file of the virtual machine. It’s usually stored in /vmfs/volumes/…
vcbMounter does not expect the path to the .vmx. It only needs the name of your virtual machine.
Doing the backup on a NFS mount is also possible. You need to deactive the VMWare ESX firewall and can mount e.g. using “mount -t smbfs”.