Etcd: `etcdctl ls --recursive` does not show values for keys

Created on 26 Feb 2015  路  6Comments  路  Source: etcd-io/etcd

The help for etcdctl ls says:

bash-3.2$ etcdctl help ls
NAME:
   ls - retrieve a directory

USAGE:
   command ls [command options] [arguments...]

DESCRIPTION:


OPTIONS:
   --recursive  returns all values for key and child keys

But when I use it:

bash-3.2$ etcdctl ls --recursive  /
/vulcand
/vulcand/hosts
/vulcand/hosts/1.2.3.4
/vulcand/hosts/1.2.3.4/host
/vulcand/backends
/vulcand/backends/foobar
/vulcand/backends/foobar/servers
/vulcand/backends/foobar/servers/y54wt53swt4s3rt4
/vulcand/backends/foobar/backend
/vulcand/frontends
/vulcand/frontends/baz
/vulcand/frontends/baz/frontend
/vulcand/listeners
/vulcand/listeners/http
/vulcand/listeners/https
bash-3.2$

These are just keys, but the documentation for --recursive says that it should also print the values. Am I misunderstanding something?

Most helpful comment

I came up with this hack for leveraging ls --recursive and xargs to dump all keys and values:

etcdctl ls --recursive -p | grep -v '/$' | xargs -n 1 -I% sh -c 'echo -n %:; etcdctl get %;'

This prints out keys and values one per line with a colon delimiter.

If there is some more straightforward way to do this with etcdctl, it has eluded me. NB: this does not dump empty folders.

All 6 comments

@jhftrifork I think this is a documentation bug. The ls command is supposed to list the keys, and the get command is used to get the value. /cc @xiang90

I came up with this hack for leveraging ls --recursive and xargs to dump all keys and values:

etcdctl ls --recursive -p | grep -v '/$' | xargs -n 1 -I% sh -c 'echo -n %:; etcdctl get %;'

This prints out keys and values one per line with a colon delimiter.

If there is some more straightforward way to do this with etcdctl, it has eluded me. NB: this does not dump empty folders.

etcdctl ls --recursive -p | grep -v '/$' | xargs -n 1 -I% sh -c 'echo -n %:; etcdctl get %;'

how to restore from this data?

@tomj74 Your trick is nice. Let me make it look nicer: bin/etcdctl ls -p --recursive | grep -v '/$' | xargs -n 1 -I% sh -c 'echo -en "\033[34m%\033[0m -> "; bin/etcdctl get %;'

I came up with this hack for leveraging ls --recursive and xargs to dump all keys and values:

etcdctl ls --recursive -p | grep -v '/$' | xargs -n 1 -I% sh -c 'echo -n %:; etcdctl get %;'

This prints out keys and values one per line with a colon delimiter.

If there is some more straightforward way to do this with etcdctl, it has eluded me. NB: this does not dump empty folders.

i have --endpoint ,what i should do?

v2 commands for etcdctl (and etcd2) is out of the support window. Please use etcd3 and ETCDCTL_API=3 etcdctl.

Was this page helpful?
0 / 5 - 0 ratings