Wednesday, February 01, 2012

free vm disk clone/backup howto

Some of us, using free version of vmware esxi want to clone/backup vm with free tools, yes? :)
There a lot of products which are expensive, big, and they somehow work, but if you are some sort of g33k, here is a way to make backup of runing virtual machine. Lets look how it can be done:

Let's assume that we have virtual machine by name: testvm, it is runing from some sort of datastore named datastore (strange, yes?), so - you have already sitting, logged in via SSH to vmware esxi host, looking to the black screen and...

First of all we need to create snapshot of runing VM, we need this to remove lock of main vmdk file:

vmware-cmd /vmfs/volumes/datastore/testvm/testvm.vmx \
createsnapshot "test" "Backup of testvm on 2012-02-01" 1 1

after that, in some minutes, depending of the size of vm disk, we should see something like that:

createsnapshot(test, Backup of testvm on 2012-02-01, 1, 1) = 1

Then we create copy of the disk:

vmkfstools -i /vmfs/volumes/datastore/testvm/testvm.vmdk \
/path/to/backup/place/testvm_clone.vmdk

you should see some sort of text:

Destination disk format: VMFS zeroedthick
Cloning disk: /vmfs/volumes/datastore/testvm/testvm.vmdk 
Clone: 5% done.

yeah! now we have copy of a runing live VM!! But first we need to delete snapshot, we have created to unlock our vmdk file:

vmware-cmd /vmfs/volumes/datastore/testvm/testvm.vmx removesnapshots

That's all. We have vmdk file (the disk (with all the files:) of the virtual machine), the machine is runing fine. A little shell scripting, nfs or physical backup disks, gzip, crontab and we have free backup software :)

P.S. if the disks of virtual machines are persistent, then we can't create snapshots, and of course, can't backup with this scheme those machines.

Labels: , , , ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home