vmware - revert to snapshot from within the GUEST?
Asked Answered
Z

1

5

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" ...

Zante answered 12/12, 2012 at 20:33 Comment(1)
did you find any solution ?Aground
W
10

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.
Womenfolk answered 13/12, 2012 at 12:12 Comment(3)
The solution certainly fulfills the requirement that: "i need to trigger "revert to snapshot" from inside the guest." as the Scheduled Task is being not only initiated, but also run from within the guest OS, which also fulfills your other requirement that " i really need to execute it from within the guest". Maybe I'm not completely clear on your requirements, but every one of the steps above (barring #1) should be executed on your guest VM or "from inside the VM" as you put it. Can you please explain how the solution above doesn't meet the requirement?Womenfolk
The VM itself is completely unaware that it is virtualized, so the VM cannot simply make a call to the ESX hypervisor to snapshot/revert itself. That's the whole premise of virtualization is that the virtual layer is transparent to the guest OS.Womenfolk
Opmet, I guess I don't see the difference between a scheduled task initiating a snapshot on the host or initiating it through vCenter. Maybe you're not running a vCenter server? The VMware Tools mainly provide performance and some manageability features; they don't unlock a special set of features (at least in terms of snapshots) that allow your VM to request a reversion (that would be bad for security). It does allow you to quiesce the VM's RAM during a snapshot though. Some 3rd party software allow you to use Microsoft VSS, so you might want to look at that.Womenfolk

© 2022 - 2024 — McMap. All rights reserved.