Opmet
Opmet

Reputation: 1834

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:

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

Upvotes: 5

Views: 7371

Answers (1)

jkovba
jkovba

Reputation: 1259

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.

Upvotes: 10

Related Questions