Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vmware - revert to snapshot from within the GUEST?

i have virtual machines running on vmware ESXi and vmware workstation.
i need to execute "revert to snapshot" from inside the guest.

i have done so much searching, but all solutions proposed so far suggest doing it from "outside" - either some external machine or the host itself.
other workarounds suggest to enable automatic reverting to snapshot on power off event.

please do not suggest anything in that direction. i really need to execute it from within the guest. for example:

  • as scheduled task
  • as batch script (at the end of completing some other tasks)

edit:
this is the reason why i think there must be some way to achieve this: inside the guest there are "vmare tools" running as system service. so i would expect this component to also expose a functionality to trigger the host / hypervisor reverting the current VM to snapshot.
if this is not possible currently it should be implemented as new feature :)

in case it's currently not possible to execute it "from inside": that would also be an "answer" ...

like image 250
Opmet Avatar asked Dec 12 '12 20:12

Opmet


People also ask

When reverting a snapshot in VMware the following will occur?

Whenever you do a VMware revert to snapshot VMware will warn you that the current state of the VM will be lost unless you take a snapshot as shown in Fig. 7. If the memory option was selected when the snapshot was taken, you are then presented with the option to suspend the VM while it is being reverted.

Can you take a snapshot while the VM is running?

You can take a snapshot while a virtual machine is powered on, powered off, or suspended. ... but ... if a configuration requires you to use an independent disk, you must power off the virtual machine before you take a snapshot.

What occurs to the guest OS configuration when a virtual machine is reverted from its snapshot?

Reverting virtual machines to a snapshot causes all settings configured in the guest operating system since that snapshot to be reverted. The configuration which is reverted includes, but is not limited to, previous IP addresses, DNS names, UUIDs, guest OS patch versions, etc.


1 Answers

I've actually done this pretty recently, try this:

  1. Install VMware vSphere PowerCLI 5.1 (it's a command line scripting interface for ESX)
  2. Write a script (perhaps in Notepad) that contains the following code:

    Connect-VIServer <vCenter Server IP>
    Set-VM <VM name> -Snapshot <Snapshot name> -Confirm:$false
    

    This will connect to your vCenter server and revert your VM to the specified snapshot. Save the script as revert_snapshot.ps1 (PowerShell file extension)

  3. Using Windows Task Schedule, create a new tasks. The General and Triggers tabs are self explanatory, but the Actions tab is where you'll configure the scheduled tasks to launch your PowerShell script.
  4. For 'Action' select 'Start a Program'. Under 'Program/script', enter the following:

    C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe
    
  5. For the 'Add arguments' field, you'll specify the path of your PowerShell script:

    -psc "C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\vim.psc1" "<path to your script>"
    

note: vim.psc1 is not available in the latest version of PowerCLI.

  1. Save your task and run it manually as a test. Be patient as sometimes the cmdlet for logging into vCenter (Connect-VIServer) can take a few seconds to connect.
like image 187
jkovba Avatar answered Sep 30 '22 19:09

jkovba