VMware Cloud Community
eager2learnn
Contributor
Contributor

Cloning a VM along with it's Snapshot

Hi there

My use case is as follows :

I have a set of VM's on which I have some snapshots, these snapshots are meant for lab purpose for students to rollback and move forward.

Now I want to create multiple such set of VM's, for which I thought let me clone, but the moment I clone all the snapshots on the new VM's are gone and disks are consolidated. So is there any way to retain the Snapshots on the new VM while copying/cloning.

Any pointers on the above will be much appreciated. Thanks

Regards,

Born2Learn

0 Kudos
28 Replies
daphnissov
Immortal
Immortal

This is an interesting one provided your use case. I don't know of any advanced setting that will allow snapshots to be preserved upon a clone operation. What you may end up having to do is basically a file copy and modification, then register the VMX as a new VM. I'd look into automating that with PowerCLI because there are several steps you would want to do. These are the ones that come immediately to mind:

  1. Shut down source VM (with snapshots)
  2. Create directory with new VM name at target
  3. Copy all files from source dir to target dir
  4. Iteratively change names of all files to match new VM name.
  5. Update VMDK descriptor with new name
  6. Update VMX with new names
  7. Generate new UUID for new VM
  8. Register new VM in inventory

I'm sure there are others, but these would be the major steps involved.

0 Kudos
eager2learnn
Contributor
Contributor

Thanks daphinssov for the swift response.

I will surely try this and let you know the outcome. I suspect that I may get a warning like VM disk consolidation is required.

Also, if you already have some similar powercli script that will be helpful.. I will customize as per the requirement.

Regards,

born2learn

0 Kudos
daphnissov
Immortal
Immortal

If the snapshot descriptor file is updated, you shouldn't get that warning about consolidation needed. Also, remember I only took a "swag" at the steps involved. I'm sure there are others but I've not gone through this process before. Ensure you test in a lab environment before trying to roll that out into production.

0 Kudos
eager2learnn
Contributor
Contributor

Hi daphnissov

I have edited the disk descriptor, .vmsd and .vmx files with the new names. I got a new UUID also for the VM while registering to inventory.

VM is able to get powered and is reflecting all the snapshots in the snapshot manager but when I try to revert or goto any snapshot I get the attached error.

"An error occurred while reverting to a snapshot: msg.snapshot.error-NOTFOUND."

Now that makes me to believe that either the chain of snapshots is broken or the integrity of snapshots is corrupted, not sure how to fix this. Kindly advise.

0 Kudos
daphnissov
Immortal
Immortal

You may need to update the VMX file or the snapshot metadata descriptor file so the chain is valid.

0 Kudos
eager2learnn
Contributor
Contributor

As I mentioned in my previous post, I have amended the following files :

.vmdk

.vmx

.vmsd

Is there anything else, which needs to be amended or any specific setting should be checked.

Appreciate your help.

0 Kudos
daphnissov
Immortal
Immortal

I'll have to test and see since I've not gone through this process myself.

0 Kudos
eager2learnn
Contributor
Contributor

Okay.. please give it a try with multiple snapshots.

Will be waiting for your valuable revert.

Thanks.

0 Kudos
sandu
Enthusiast
Enthusiast

Hi,

I don't think this is a supported scenario. Even if you manually copy the contents to a new destination, you will encounter problems with mac address conflict, UID etc when you revert snapshot.

Thanks

Sandeep

0 Kudos
eager2learnn
Contributor
Contributor

Those things will be taken care by VMWARE only, as I said I am able to poweron the new VM as it automatically changes to a new UUID and assigns a new MacAddress. The problem is when I try to revert to a particular snapshot.

0 Kudos
sandu
Enthusiast
Enthusiast

Hi,

That was exactly my point. When you revert the snapshot after manually copying the entire folder to another vsphere machine, you will experience MAC conflict and UID conflicts when you revert the snapshot.

-Sandeep

0 Kudos
eager2learnn
Contributor
Contributor

So are you saying that with every snapshot we take, even the configs like MAC address and UUID are also stored?? I thought it was only data which is being snapped.

0 Kudos
sandu
Enthusiast
Enthusiast

Since these are in-memory data, all these information also will be saved with VM memory.

-Sandeep

0 Kudos
eager2learnn
Contributor
Contributor

ohhkk.. but I have not checked the memory box while taking snapshot.

0 Kudos
sandu
Enthusiast
Enthusiast

In that case you can try the following:

1. Power of the VM

2. Copy the entire VM folder to your new host

3. Browse to the datastore from vCenter or host client and locate the .vmx file

4. Right click and say, "Add to Inventory".

5. Provide a name for VM and add to inventory.

6. Power on VM.

7. When the client asks you how you moved the files, select the option "Copied it"

Hope this works :smileysilly:

Thanks,

Sandeep

0 Kudos
eager2learnn
Contributor
Contributor

Still the same error Smiley Sad

0 Kudos
eager2learnn
Contributor
Contributor

Hi daphnissov

Did you get a chance to try this.LucDdaphnissov

Appreciate your help. Thanks.

0 Kudos
daphnissov
Immortal
Immortal

So I just went through these steps in my lab. I started with a powered-off VM. I took a snapshot of that VM. I then cloned all its files to a new directory on the same datastore. I renamed all the files once at the destination. I then edited every text file to update the names including the VMX file where I changed the MAC and all the UUIDs by incrementing their values by one (hex or decimal). I then registered the VM in inventory and selected "I copied it". I powered on the VM and saw it boot fine. Once booted, I reverted the snapshot to the one in the descriptor which, since it was powered off, returned it to a powered off state. I was successful in both reverting it and powering it back on from that state.

0 Kudos
eager2learnn
Contributor
Contributor

Thanks daphnissov

Can you please highlight the files which you edited for the MAC address and UUID stuff.

Regards,

born2learnn

0 Kudos