Taking a snapshot from the command line is trivial. Restoring the snapshot is not. From the XenCenter GUI application it’s easy of course, but sometimes you need to automate things. In this case I have an environment for testing which needs to be reverted to the same state after each test.
Each VM has only a single snapshot. Matching the snapshot UUID with the UUID of the virtual machine isn’t easy, but can be done by extracting the parameter called “children” from the snapshot.
To list the snapshots with their respective VM UUID’s, I use the following (i and j variables for snapshot UUID and VM UUID respectively):
To restore the snapshots:
NOTE: This works if there’s only ONE snapshot per VM and you want to restore them all. Otherwise more complex scripting is required to filter out the ones you need. It’s more than enough for our test systems though.