VMware Cloud Community
kevinberry70
Contributor
Contributor

Cloning a VM FROM a snapshot

Anyone ever done this?   Is there anyway?   Been looking for a simple method to do this......

10 Replies
weinstein5
Immortal
Immortal

Welcome to the Community - Remember a snapshot is not a copy of the VM but appoint log recording the changes to the VM disk form that point - so you could return to the point when the snapshot was taken and clone the VM -

If you find this or any other answer useful please consider awarding points by marking the answer correct or helpful
kevinberry70
Contributor
Contributor

Thanks. Yes, but here is the scenario we are working with, as we are a development environment:

1. We have a VM named "dragon" that is running.

2. Take a snapshot of "dragon", which records it's now current state.

3. "dragon" continues to be used, and it's state is changed as a developer uses it.

4. Now, we have an original state, and an altered state, that is merely a recording of what actually changed (the snapshot itself).

5. NOW, while keeping the original "dragon" 'HOT" and running, we would like to clone the snapshot to a new name.

6. End result: 2 vm's. One an original, second with original content + what has changed.

Likewise, perhaps we start with "dragon" and take 4 snapshots over time, and wish to clone each one, for three new vm's with different name. All of which is done WITHOUT effecting the "hot" still running original VM.

Reply
0 Kudos
unsichtbare
Expert
Expert

If you want to create a clone of the VM the way it is right now, just right-click on it and select: Clone.

There will be a new, temporary, snapshot (delta.vmdk) created while the clone is made, then you have 2 VM's! It works perfectly. You can even clone Linked-Clones to fully-provisioned VMs.

If you want to create a clone of the VM as it was before the "snapshot," the answer is a little more complicated, but just as fun! Here's how I would do it:

  1. Power-off the VM and connect to the host using SSH.
  2. Browse to the datastore where the VM exists: cd /vmfs/volumes/datastorename
  3. Create a folder for the new VM: mkdir newvmname
  4. Cd into the old VM folder: cd oldvmname
  5. List files: ls
  6. Run the command: vmkfstools -i oldvmname.vmdk ../newvmname/newvmname.vmdk
    1. This would have to be run once for each source disk, for VMs with more than one disk.
    2. Lots of docs online, or I can provide an illustrated procedure
  7. Now you will have to create a new VM, matching the settings of the original one except:
    1. Custom configuration only
    2. Use an unique name
    3. Use an existing disk, then browse to the disk you made with vmkfstools
    4. Finish

Done!

+The Invisible Admin+ If you find me useful, follow my blog: http://johnborhek.com/
Reply
0 Kudos
kevinberry70
Contributor
Contributor

http://www.jonathanmedd.net/2013/07/clone-a-vm-from-a-snapshot-using-powercli.html

Maybe my original request was unclear.

1. I know I can just right click on a vm and clone it.

2. I know I can also create a copy of the original vmdk files and put them elsewhere with a new name if desired.

What I "want" to find a solution to is this:

I want to have a running vm POWERED ON, say, on a Monday.

I want to take a snapshot of the VM, say, on Tuesday.

I want to take another snapshot, say, on Wednesday.

I want to then continue to use and make changes to said VM, on Thursday - no new snapshot.

I want to THEN, while that VM is still powered on and running, use it Friday AM, make several changes, and then CLONE the existing, latest snapshot (from Wednesday), (which is a different state) and provide a new name for it.

This gives my developers the ability to actually have several different vm's that then they can also snapshot and revert if needed. If the process is repeated, you end up with perhaps vm1, vm2, vm3 all of similarity, but each may also have there own set of additional snapshots, should they be taken, in the future.

The key here, is to be able to CLONE a snapshot, while without powering off the original VM, and supply a NEW name to distinguish it separately.

This is the closest thing I've found to this, but have no knowledge of PowerCLI

http://www.jonathanmedd.net/2013/07/clone-a-vm-from-a-snapshot-using-powercli.html

Reply
0 Kudos
weinstein5
Immortal
Immortal

Using your example you want clone of the VM's 'Friday' state? If so than just right click and select clone and a new VM will be created with a single VMDK that will match the 'Friday' state of the original VM with no snapshots

If you want to clone 'Wednesday" you will have to revert back to that clone discarding you changes or do the above and you will still maintain 'Friday' and then be able to revert the original vm back to 'Wednesday'

If you find this or any other answer useful please consider awarding points by marking the answer correct or helpful
Reply
0 Kudos
NavalgundRaj
Enthusiast
Enthusiast

Hi Kevib,

Correct answers are

Anyone ever done this? 

Ans: No

Is there anyway?

Ans:No

Been looking for a simple method to do this......

Ans:There is no way and if there is no way how we find simple way.

Note: If you found this correct or answer useful please consider the use of the Correct buttons to award points. Regards Basavaraj.R Navalgund
j_ervolino
Contributor
Contributor

There actually is an answer to this once you actually "read" what you want to do. However there is a caveat, ESXi and virtual center cannot do this, you would need to import the vm into vmware workstation which does allow you to clone a vm from a snapshot independent of the state the machine is in.  Sorry it took someone almost three years to actually answer and address your question instead of telling you to right-click clone 4 times.

unsichtbare
Expert
Expert

An arrogant and dismissive response YEARS LATER (as if none of us ever considered the original question in detail) is not the solution to anyone's problem. Especially considering the fact you, apparently did not read the question yourself. The original question is: how to clone from a previous snapshot state of a powered-on VM?

Migrating to VMware Workstation is much further from the "solution" than any of the other well-considered answered answers in this thread.

+The Invisible Admin+ If you find me useful, follow my blog: http://johnborhek.com/
Tags (1)
Reply
0 Kudos
raghushetty
Enthusiast
Enthusiast

This is Cool ..but the problem is Snapshot is not recommended to keep for the longer days"VIMP"

there is a dependence of primary snapshot when you want takes the second copy of snapshot .. As soon as a snapshot is created, the newly produced Delta files grow dynamically with the activity in the guest, and every modification on the hard drive thus leads to an increase of the Delta-hard drive file. This relates to every modification, from copying a file via secure formatting of the hard drive with zeros all the way to deleting files. The drive space need is never reduced. However, a Delta file can never become larger than its original file, as all memory blocks were copied 1:1. If the same block is overwritten a hundred times, this does not change the size of the Delta file. As soon as a new block is written, the Delta file grows along with it in steps of at least 15 MB.

Thus it is important to understand that after creating the snapshot, the additional memory requirement may be doubled at most, but this is applicable to every snapshot; meaning if the Delta file is 5 GB in size after the first snapshot and a second snapshot is created, the Delta files add up on the datastore. This is why you need to watch the number of snapshots as well as their size.

By the way, snapshots are almost always used by backup products to secure active virtual machines from the outside (not via agent in the guest, but VCB). This is due to the fact that the hard drive files of a VM have exclusive read/write access through the VMkernel until a VM snapshot is created. At this point in time, the original hard drive files are readable, and the last Delta file has exclusive write/read access through the VMkernel. The table illustrates the technical process of a snapshot.

Best practices for using snapshots

VMware Knowledge Base

JJamison1
Contributor
Contributor

Normally I wouldn't revive a long dead thread, but its somehow one of the top results when searching for how to clone a snapshot.

However, now, (as in a long time after the original question) there is an available option:

- Linked clones.

A linked clone allows you to select a snapshot, and create a clone of a VM from that snapshot.  

The only caveat is that the clone cannot be performed from the GUI (which is strange considering vmware workstation can)

Look for the "-linkedclone" and "-referencesnapshot" arguments to the PowerCLI "New-VM" command.

get-help new-vm -full

 

As an aside, the snapshot must live as long as the clone. If you delete the snapshot, it will be hidden from view, but not actually removed until the clone is deleted, and the original VM is consolidated.

As a consequence, If the clone needs to live longer than a day or two, I generally recommend making a full clone of the linked clone, and deleting the linked clone.