How to get revision ID of latest revision for a key, or last n revisions, with etcdctl

2.1k views Asked by At

Using etcdctl I can do get <key name> and retrieve the latest value. But, if I want to see previous values I need to add --rev=<some rev ID>.

How can I find out what the revID is for the latest value, so I can know what to put in to get --rev=<latest -1>

Alternatively, is there a way to get the last n revisions of a value?

Doing get --order=DESCEND --sort-by=MODIFY --limit=3 <key name> only returns a single value even though, in this case, --rev=785 returns the latest value, and --rev=784 returns the previous one.

Thanks, Paul

1

There are 1 answers

0
Ephemeral On

The standard output format does not give you the metadata information that you are looking for. It is there in the json version of the output. the following should get you the data, and use jq to extract the current revision.

etcdctl get -w json  mykey | jq -r '.header.revision'