VMware Cloud Community
teddyboy
Contributor
Contributor

vSphere Power CLI commiting a snapshot

trying to create a snaphot using powershell and powerCLI

connect-viserver -server 10.30.7.106 -user root -password password

$vm = Get-VM

New-Snapshot -Name Target-Snpsht -VM ($vm)

this works fine but I would like to be able to commit the snapshot from powerCLI?

Any ideas on the commands?

0 Kudos
7 Replies
LucD
Leadership
Leadership

If you mean reverting a guest to a snapshot, you can do this:

Set-VM -VM <VMname> -Snapshot (Get-Snapshot -VM <VMname> -Name <SnapshotName>) -confirm:$FALSE


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
teddyboy
Contributor
Contributor

So if I take a snapshot of a VM called snapshot1

Take a backup of the flat vdmk file to a new location

The I wont to commitee the snapshop against the original VM flat vdmk file to account for the changes since the snapshot was created.

I dont wont to loose the changes.

Example

connect-viserver -server 10.30.7.106 -user root -password password

$VMs = Get-VM -Location ( Get-ResourcePool pool1 )

foreach ( $vm in $VMs ) { Set-VM -VM $vm -Snapshot ( Get-Snapshot -VM $vm -Name Target-Snpsht ) }

0 Kudos
LucD
Leadership
Leadership

If I understand you correctly, you want to "commit" the snapshot you took before.

And all the changes made to the guest should be written to the disk.

In that case you could do

Get-Vm <VMname> | Get-Snapshot -Name <SnapshotName> | Remove-Snapshot -Confirm:$false


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
teddyboy
Contributor
Contributor

If I understand you correctly, you want to "commit" the snapshot you took before.

And all the changes made to the guest should be written to the disk.

In that case you could do

> Get-Vm <VMname> | Get-Snapshot -Name <SnapshotName> | Remove-Snapshot -Confirm:$false
> 

Pretty much yes.

Trying to create a cold disastery recovery for a client.

Simply need to take a snapshot of 1-6 VMs one at a time

then copy the vmdk-flat file to another backup datastore

Once the copy is completed commit the snapshot to ensure any change is written to the base vmdk file

Issue now is to copy via I guess ssh to another standalone vSphere server at a new location.

I am guessing I need to copy to a backup datastore to reduce the time the snapshot runs for.

Copying via ssh is slow to another datastor, is there a quicker way?

0 Kudos
LucD
Leadership
Leadership

See your other thread where I mentioned FastScp from Veeam.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
MaxwellSmart86
Contributor
Contributor

Hi LucD.

You were so very helpful with me on finding my issue on the Cloning Issue a while back, I wanted to ask if you could explain how to "Delete" a snapshot without having the changes move back to the parent.  I want to simply revert or go to the parent, then get rid of all the other snapshots.

Thanks.

Tim

Tim Pierson, President Data-Sentry, Inc. Contributing author to the book- "VMware vSphereTM and Virtual Infrastructure Security: Securing ESX and the Virtual Environment" ISBN-10: 0137158009 Pearson Publishing.
0 Kudos
LucD
Leadership
Leadership

To remove all snapshots without merging the snapshot data into the original VMDK, you can use the RemoveAllSnapshots_Task method.

The consolidate parameter allows you to define what needs to happen with the snapshot data.

In your case, you would use $false to avoid merging the snapshot data with the original VMDK.

$vm = Get-VM MyVM

$vm.ExtensionData.RemoveAllSnapshots($false)


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos