live backup under vmware ESXi

| January 16th, 2009

backup a virtual machine running on an ESXi host.

Let’s assume we’re backing up a virtual machine called ubuntu:

1. first let’s find its VM id:

vmid=`vim-cmd vmsvc/getallvms | grep ubuntu | awk ‘{print $2}’`

2. now we have to snapshot this machine so VMware can release the lock on the virtual HDD file:

vim-cmd vmsvc/snapshot.create $vmid snapshot1 backupsnaphot

3. now we can copy the contents of the virtual machine’s directory. it will live somewhere under /vmfs/volumes/. In my case I created it in datastore1, so the full path is: /vmfs/volumes/datastore1/ubuntu. The whole directory can be copied as it is, of course, the locked files won’t be copied, but those are only snapshot related files, so no worries those are not needed anyway.

4. now we can delete the snapshot

vim-cmd vmsvc/snapshot.removeall

depending on how long it took to copy the data and how busy the virtual machine was during that time it can take some time for the data from the snapshot to be merged with the main disk and memory files.

Leave a Reply

You must be logged in to post a comment.