I've only just realized that KVM snapshots default to being listed in alphabetical order, rather than chronological. This can be confusing if you sometimes use the command virsh snapshot-create-as $ID "$NAME" in order to create snapshots. This can result in output similar to below which is hard to find the latest snapshot from (especially if it's a long list):

 Name                 Creation Time             State                                                          │
------------------------------------------------------------                                                   │
 1474043443           2016-09-16 17:30:43 +0100 running                                                        │
 1476197777           2016-10-11 15:56:17 +0100 running                                                        │
 1476721835           2016-10-17 17:30:35 +0100 running                                                        │
 1476953503           2016-10-20 09:51:43 +0100 running                                                        │
 consolidated         2016-09-25 08:06:27 +0100 running                                                        │
 just installed mysql 5.6 2016-09-16 10:19:46 +0100 running                                                    │
 updated vars         2016-09-24 04:02:24 +0100 running

Is there a way to list the snapshots in chronological order? That way I can (or a script can be programmed to) just read the name from either the top or bottom of the list to grab the latest one. If not, is there a place I can raise this to put in a request for a --chronological parameter?

After reading the Redhat documentation on managing snapshots, I have found the --tree and --leaves options which are helpful to me in this specific case as --leaves gives me the latest snapshot which is what I'm after, but would probably list several if there were several "paths". I'm not sure if the last line in a --tree option would always give me the latest snapshot. It may depend on the alphabetical names of the "branches" when the splits were made. --current` does not work for me as I get the following error message:

error: Domain snapshot not found: the domain does not have a current snapshot

I am guessing this is because the virtual machine had its snapshot taken whilst it was running, and it is also currently still running.

I guess one could easily write a script to parse the Creation Time in the output to automatically fetch the name of the latest snapshot but it would be nice if this was somehow built-in.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.