• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..24-Aug-2020-

ctlv2/H24-Aug-2020-2,7261,977

ctlv3/H24-Aug-2020-6,6075,091

doc/H24-Aug-2020-3022

README.mdH A D24-Aug-202042.1 KiB1,6881,105

READMEv2.mdH A D24-Aug-20207.7 KiB337245

main.goH A D24-Aug-20201.1 KiB4724

main_test.goH A D24-Aug-2020802 3012

README.md

1etcdctl
2========
3
4`etcdctl` is a command line client for [etcd][etcd].
5
6The v3 API is used by default on master branch. For the v2 API, make sure to set environment variable `ETCDCTL_API=2`. See also [READMEv2][READMEv2].
7
8If using released versions earlier than v3.4, set `ETCDCTL_API=3` to use v3 API.
9
10Global flags (e.g., `dial-timeout`, `--cacert`, `--cert`, `--key`) can be set with environment variables:
11
12```
13ETCDCTL_DIAL_TIMEOUT=3s
14ETCDCTL_CACERT=/tmp/ca.pem
15ETCDCTL_CERT=/tmp/cert.pem
16ETCDCTL_KEY=/tmp/key.pem
17```
18
19Prefix flag strings with `ETCDCTL_`, convert all letters to upper-case, and replace dash(`-`) with underscore(`_`).
20
21## Key-value commands
22
23### PUT [options] \<key\> \<value\>
24
25PUT assigns the specified value with the specified key. If key already holds a value, it is overwritten.
26
27RPC: Put
28
29#### Options
30
31- lease -- lease ID (in hexadecimal) to attach to the key.
32
33- prev-kv -- return the previous key-value pair before modification.
34
35- ignore-value -- updates the key using its current value.
36
37- ignore-lease -- updates the key using its current lease.
38
39#### Output
40
41`OK`
42
43#### Examples
44
45```bash
46./etcdctl put foo bar --lease=1234abcd
47# OK
48./etcdctl get foo
49# foo
50# bar
51./etcdctl put foo --ignore-value # to detache lease
52# OK
53```
54
55```bash
56./etcdctl put foo bar --lease=1234abcd
57# OK
58./etcdctl put foo bar1 --ignore-lease # to use existing lease 1234abcd
59# OK
60./etcdctl get foo
61# foo
62# bar1
63```
64
65```bash
66./etcdctl put foo bar1 --prev-kv
67# OK
68# foo
69# bar
70./etcdctl get foo
71# foo
72# bar1
73```
74
75#### Remarks
76
77If \<value\> isn't given as command line argument, this command tries to read the value from standard input.
78
79When \<value\> begins with '-', \<value\> is interpreted as a flag.
80Insert '--' for workaround:
81
82```bash
83./etcdctl put <key> -- <value>
84./etcdctl put -- <key> <value>
85```
86
87Providing \<value\> in a new line after using `carriage return` is not supported and etcdctl may hang in that case. For example, following case is not supported:
88
89```bash
90./etcdctl put <key>\r
91<value>
92```
93
94A \<value\> can have multiple lines or spaces but it must be provided with a double-quote as demonstrated below:
95
96```bash
97./etcdctl put foo "bar1 2 3"
98```
99
100### GET [options] \<key\> [range_end]
101
102GET gets the key or a range of keys [key, range_end) if range_end is given.
103
104RPC: Range
105
106#### Options
107
108- hex -- print out key and value as hex encode string
109
110- limit -- maximum number of results
111
112- prefix -- get keys by matching prefix
113
114- order -- order of results; ASCEND or DESCEND
115
116- sort-by -- sort target; CREATE, KEY, MODIFY, VALUE, or VERSION
117
118- rev -- specify the kv revision
119
120- print-value-only -- print only value when used with write-out=simple
121
122- consistency -- Linearizable(l) or Serializable(s)
123
124- from-key -- Get keys that are greater than or equal to the given key using byte compare
125
126- keys-only -- Get only the keys
127
128#### Output
129
130\<key\>\n\<value\>\n\<next_key\>\n\<next_value\>...
131
132#### Examples
133
134First, populate etcd with some keys:
135
136```bash
137./etcdctl put foo bar
138# OK
139./etcdctl put foo1 bar1
140# OK
141./etcdctl put foo2 bar2
142# OK
143./etcdctl put foo3 bar3
144# OK
145```
146
147Get the key named `foo`:
148
149```bash
150./etcdctl get foo
151# foo
152# bar
153```
154
155Get all keys:
156
157```bash
158./etcdctl get --from-key ''
159# foo
160# bar
161# foo1
162# bar1
163# foo2
164# foo2
165# foo3
166# bar3
167```
168
169Get all keys with names greater than or equal to `foo1`:
170
171```bash
172./etcdctl get --from-key foo1
173# foo1
174# bar1
175# foo2
176# bar2
177# foo3
178# bar3
179```
180
181Get keys with names greater than or equal to `foo1` and less than `foo3`:
182
183```bash
184./etcdctl get foo1 foo3
185# foo1
186# bar1
187# foo2
188# bar2
189```
190
191#### Remarks
192
193If any key or value contains non-printable characters or control characters, simple formatted output can be ambiguous due to new lines. To resolve this issue, set `--hex` to hex encode all strings.
194
195### DEL [options] \<key\> [range_end]
196
197Removes the specified key or range of keys [key, range_end) if range_end is given.
198
199RPC: DeleteRange
200
201#### Options
202
203- prefix -- delete keys by matching prefix
204
205- prev-kv -- return deleted key-value pairs
206
207- from-key -- delete keys that are greater than or equal to the given key using byte compare
208
209#### Output
210
211Prints the number of keys that were removed in decimal if DEL succeeded.
212
213#### Examples
214
215```bash
216./etcdctl put foo bar
217# OK
218./etcdctl del foo
219# 1
220./etcdctl get foo
221```
222
223```bash
224./etcdctl put key val
225# OK
226./etcdctl del --prev-kv key
227# 1
228# key
229# val
230./etcdctl get key
231```
232
233```bash
234./etcdctl put a 123
235# OK
236./etcdctl put b 456
237# OK
238./etcdctl put z 789
239# OK
240./etcdctl del --from-key a
241# 3
242./etcdctl get --from-key a
243```
244
245```bash
246./etcdctl put zoo val
247# OK
248./etcdctl put zoo1 val1
249# OK
250./etcdctl put zoo2 val2
251# OK
252./etcdctl del --prefix zoo
253# 3
254./etcdctl get zoo2
255```
256
257### TXN [options]
258
259TXN reads multiple etcd requests from standard input and applies them as a single atomic transaction.
260A transaction consists of list of conditions, a list of requests to apply if all the conditions are true, and a list of requests to apply if any condition is false.
261
262RPC: Txn
263
264#### Options
265
266- hex -- print out keys and values as hex encoded strings.
267
268- interactive -- input transaction with interactive prompting.
269
270#### Input Format
271```ebnf
272<Txn> ::= <CMP>* "\n" <THEN> "\n" <ELSE> "\n"
273<CMP> ::= (<CMPCREATE>|<CMPMOD>|<CMPVAL>|<CMPVER>|<CMPLEASE>) "\n"
274<CMPOP> ::= "<" | "=" | ">"
275<CMPCREATE> := ("c"|"create")"("<KEY>")" <CMPOP> <REVISION>
276<CMPMOD> ::= ("m"|"mod")"("<KEY>")" <CMPOP> <REVISION>
277<CMPVAL> ::= ("val"|"value")"("<KEY>")" <CMPOP> <VALUE>
278<CMPVER> ::= ("ver"|"version")"("<KEY>")" <CMPOP> <VERSION>
279<CMPLEASE> ::= "lease("<KEY>")" <CMPOP> <LEASE>
280<THEN> ::= <OP>*
281<ELSE> ::= <OP>*
282<OP> ::= ((see put, get, del etcdctl command syntax)) "\n"
283<KEY> ::= (%q formatted string)
284<VALUE> ::= (%q formatted string)
285<REVISION> ::= "\""[0-9]+"\""
286<VERSION> ::= "\""[0-9]+"\""
287<LEASE> ::= "\""[0-9]+\""
288```
289
290#### Output
291
292`SUCCESS` if etcd processed the transaction success list, `FAILURE` if etcd processed the transaction failure list. Prints the output for each command in the executed request list, each separated by a blank line.
293
294#### Examples
295
296txn in interactive mode:
297```bash
298./etcdctl txn -i
299# compares:
300mod("key1") > "0"
301
302# success requests (get, put, delete):
303put key1 "overwrote-key1"
304
305# failure requests (get, put, delete):
306put key1 "created-key1"
307put key2 "some extra key"
308
309# FAILURE
310
311# OK
312
313# OK
314```
315
316txn in non-interactive mode:
317```bash
318./etcdctl txn <<<'mod("key1") > "0"
319
320put key1 "overwrote-key1"
321
322put key1 "created-key1"
323put key2 "some extra key"
324
325'
326
327# FAILURE
328
329# OK
330
331# OK
332```
333
334#### Remarks
335
336When using multi-line values within a TXN command, newlines must be represented as `\n`. Literal newlines will cause parsing failures. This differs from other commands (such as PUT) where the shell will convert literal newlines for us. For example:
337
338```bash
339./etcdctl txn <<<'mod("key1") > "0"
340
341put key1 "overwrote-key1"
342
343put key1 "created-key1"
344put key2 "this is\na multi-line\nvalue"
345
346'
347
348# FAILURE
349
350# OK
351
352# OK
353```
354
355### COMPACTION [options] \<revision\>
356
357COMPACTION discards all etcd event history prior to a given revision. Since etcd uses a multiversion concurrency control
358model, it preserves all key updates as event history. When the event history up to some revision is no longer needed,
359all superseded keys may be compacted away to reclaim storage space in the etcd backend database.
360
361RPC: Compact
362
363#### Options
364
365- physical -- 'true' to wait for compaction to physically remove all old revisions
366
367#### Output
368
369Prints the compacted revision.
370
371#### Example
372```bash
373./etcdctl compaction 1234
374# compacted revision 1234
375```
376
377### WATCH [options] [key or prefix] [range_end] [--] [exec-command arg1 arg2 ...]
378
379Watch watches events stream on keys or prefixes, [key or prefix, range_end) if range_end is given. The watch command runs until it encounters an error or is terminated by the user.  If range_end is given, it must be lexicographically greater than key or "\x00".
380
381RPC: Watch
382
383#### Options
384
385- hex -- print out key and value as hex encode string
386
387- interactive -- begins an interactive watch session
388
389- prefix -- watch on a prefix if prefix is set.
390
391- prev-kv -- get the previous key-value pair before the event happens.
392
393- rev -- the revision to start watching. Specifying a revision is useful for observing past events.
394
395#### Input format
396
397Input is only accepted for interactive mode.
398
399```
400watch [options] <key or prefix>\n
401```
402
403#### Output
404
405\<event\>[\n\<old_key\>\n\<old_value\>]\n\<key\>\n\<value\>\n\<event\>\n\<next_key\>\n\<next_value\>\n...
406
407#### Examples
408
409##### Non-interactive
410
411```bash
412./etcdctl watch foo
413# PUT
414# foo
415# bar
416```
417
418```bash
419ETCDCTL_WATCH_KEY=foo ./etcdctl watch
420# PUT
421# foo
422# bar
423```
424
425Receive events and execute `echo watch event received`:
426
427```bash
428./etcdctl watch foo -- echo watch event received
429# PUT
430# foo
431# bar
432# watch event received
433```
434
435Watch response is set via `ETCD_WATCH_*` environmental variables:
436
437```bash
438./etcdctl watch foo -- sh -c "env | grep ETCD_WATCH_"
439
440# PUT
441# foo
442# bar
443# ETCD_WATCH_REVISION=11
444# ETCD_WATCH_KEY="foo"
445# ETCD_WATCH_EVENT_TYPE="PUT"
446# ETCD_WATCH_VALUE="bar"
447```
448
449Watch with environmental variables and execute `echo watch event received`:
450
451```bash
452export ETCDCTL_WATCH_KEY=foo
453./etcdctl watch -- echo watch event received
454# PUT
455# foo
456# bar
457# watch event received
458```
459
460```bash
461export ETCDCTL_WATCH_KEY=foo
462export ETCDCTL_WATCH_RANGE_END=foox
463./etcdctl watch -- echo watch event received
464# PUT
465# fob
466# bar
467# watch event received
468```
469
470##### Interactive
471
472```bash
473./etcdctl watch -i
474watch foo
475watch foo
476# PUT
477# foo
478# bar
479# PUT
480# foo
481# bar
482```
483
484Receive events and execute `echo watch event received`:
485
486```bash
487./etcdctl watch -i
488watch foo -- echo watch event received
489# PUT
490# foo
491# bar
492# watch event received
493```
494
495Watch with environmental variables and execute `echo watch event received`:
496
497```bash
498export ETCDCTL_WATCH_KEY=foo
499./etcdctl watch -i
500watch -- echo watch event received
501# PUT
502# foo
503# bar
504# watch event received
505```
506
507```bash
508export ETCDCTL_WATCH_KEY=foo
509export ETCDCTL_WATCH_RANGE_END=foox
510./etcdctl watch -i
511watch -- echo watch event received
512# PUT
513# fob
514# bar
515# watch event received
516```
517
518### LEASE \<subcommand\>
519
520LEASE provides commands for key lease management.
521
522### LEASE GRANT \<ttl\>
523
524LEASE GRANT creates a fresh lease with a server-selected time-to-live in seconds
525greater than or equal to the requested TTL value.
526
527RPC: LeaseGrant
528
529#### Output
530
531Prints a message with the granted lease ID.
532
533#### Example
534
535```bash
536./etcdctl lease grant 10
537# lease 32695410dcc0ca06 granted with TTL(10s)
538```
539
540### LEASE REVOKE \<leaseID\>
541
542LEASE REVOKE destroys a given lease, deleting all attached keys.
543
544RPC: LeaseRevoke
545
546#### Output
547
548Prints a message indicating the lease is revoked.
549
550#### Example
551
552```bash
553./etcdctl lease revoke 32695410dcc0ca06
554# lease 32695410dcc0ca06 revoked
555```
556
557### LEASE TIMETOLIVE \<leaseID\> [options]
558
559LEASE TIMETOLIVE retrieves the lease information with the given lease ID.
560
561RPC: LeaseTimeToLive
562
563#### Options
564
565- keys -- Get keys attached to this lease
566
567#### Output
568
569Prints lease information.
570
571#### Example
572
573```bash
574./etcdctl lease grant 500
575# lease 2d8257079fa1bc0c granted with TTL(500s)
576
577./etcdctl put foo1 bar --lease=2d8257079fa1bc0c
578# OK
579
580./etcdctl put foo2 bar --lease=2d8257079fa1bc0c
581# OK
582
583./etcdctl lease timetolive 2d8257079fa1bc0c
584# lease 2d8257079fa1bc0c granted with TTL(500s), remaining(481s)
585
586./etcdctl lease timetolive 2d8257079fa1bc0c --keys
587# lease 2d8257079fa1bc0c granted with TTL(500s), remaining(472s), attached keys([foo2 foo1])
588
589./etcdctl lease timetolive 2d8257079fa1bc0c --write-out=json
590# {"cluster_id":17186838941855831277,"member_id":4845372305070271874,"revision":3,"raft_term":2,"id":3279279168933706764,"ttl":465,"granted-ttl":500,"keys":null}
591
592./etcdctl lease timetolive 2d8257079fa1bc0c --write-out=json --keys
593# {"cluster_id":17186838941855831277,"member_id":4845372305070271874,"revision":3,"raft_term":2,"id":3279279168933706764,"ttl":459,"granted-ttl":500,"keys":["Zm9vMQ==","Zm9vMg=="]}
594
595./etcdctl lease timetolive 2d8257079fa1bc0c
596# lease 2d8257079fa1bc0c already expired
597```
598
599### LEASE LIST
600
601LEASE LIST lists all active leases.
602
603RPC: LeaseLeases
604
605#### Output
606
607Prints a message with a list of active leases.
608
609#### Example
610
611```bash
612./etcdctl lease grant 10
613# lease 32695410dcc0ca06 granted with TTL(10s)
614
615./etcdctl lease list
61632695410dcc0ca06
617```
618
619### LEASE KEEP-ALIVE \<leaseID\>
620
621LEASE KEEP-ALIVE periodically refreshes a lease so it does not expire.
622
623RPC: LeaseKeepAlive
624
625#### Output
626
627Prints a message for every keep alive sent or prints a message indicating the lease is gone.
628
629#### Example
630```bash
631./etcdctl lease keep-alive 32695410dcc0ca0
632# lease 32695410dcc0ca0 keepalived with TTL(100)
633# lease 32695410dcc0ca0 keepalived with TTL(100)
634# lease 32695410dcc0ca0 keepalived with TTL(100)
635...
636```
637
638## Cluster maintenance commands
639
640### MEMBER \<subcommand\>
641
642MEMBER provides commands for managing etcd cluster membership.
643
644### MEMBER ADD \<memberName\> [options]
645
646MEMBER ADD introduces a new member into the etcd cluster as a new peer.
647
648RPC: MemberAdd
649
650#### Options
651
652- peer-urls -- comma separated list of URLs to associate with the new member.
653
654#### Output
655
656Prints the member ID of the new member and the cluster ID.
657
658#### Example
659
660```bash
661./etcdctl member add newMember --peer-urls=https://127.0.0.1:12345
662
663Member ced000fda4d05edf added to cluster 8c4281cc65c7b112
664
665ETCD_NAME="newMember"
666ETCD_INITIAL_CLUSTER="newMember=https://127.0.0.1:12345,default=http://10.0.0.30:2380"
667ETCD_INITIAL_CLUSTER_STATE="existing"
668```
669
670### MEMBER UPDATE \<memberID\> [options]
671
672MEMBER UPDATE sets the peer URLs for an existing member in the etcd cluster.
673
674RPC: MemberUpdate
675
676#### Options
677
678- peer-urls -- comma separated list of URLs to associate with the updated member.
679
680#### Output
681
682Prints the member ID of the updated member and the cluster ID.
683
684#### Example
685
686```bash
687./etcdctl member update 2be1eb8f84b7f63e --peer-urls=https://127.0.0.1:11112
688# Member 2be1eb8f84b7f63e updated in cluster ef37ad9dc622a7c4
689```
690
691### MEMBER REMOVE \<memberID\>
692
693MEMBER REMOVE removes a member of an etcd cluster from participating in cluster consensus.
694
695RPC: MemberRemove
696
697#### Output
698
699Prints the member ID of the removed member and the cluster ID.
700
701#### Example
702
703```bash
704./etcdctl member remove 2be1eb8f84b7f63e
705# Member 2be1eb8f84b7f63e removed from cluster ef37ad9dc622a7c4
706```
707
708### MEMBER LIST
709
710MEMBER LIST prints the member details for all members associated with an etcd cluster.
711
712RPC: MemberList
713
714#### Output
715
716Prints a humanized table of the member IDs, statuses, names, peer addresses, and client addresses.
717
718#### Examples
719
720```bash
721./etcdctl member list
722# 8211f1d0f64f3269, started, infra1, http://127.0.0.1:12380, http://127.0.0.1:2379
723# 91bc3c398fb3c146, started, infra2, http://127.0.0.1:22380, http://127.0.0.1:22379
724# fd422379fda50e48, started, infra3, http://127.0.0.1:32380, http://127.0.0.1:32379
725```
726
727```bash
728./etcdctl -w json member list
729# {"header":{"cluster_id":17237436991929493444,"member_id":9372538179322589801,"raft_term":2},"members":[{"ID":9372538179322589801,"name":"infra1","peerURLs":["http://127.0.0.1:12380"],"clientURLs":["http://127.0.0.1:2379"]},{"ID":10501334649042878790,"name":"infra2","peerURLs":["http://127.0.0.1:22380"],"clientURLs":["http://127.0.0.1:22379"]},{"ID":18249187646912138824,"name":"infra3","peerURLs":["http://127.0.0.1:32380"],"clientURLs":["http://127.0.0.1:32379"]}]}
730```
731
732```bash
733./etcdctl -w table member list
734+------------------+---------+--------+------------------------+------------------------+
735|        ID        | STATUS  |  NAME  |       PEER ADDRS       |      CLIENT ADDRS      |
736+------------------+---------+--------+------------------------+------------------------+
737| 8211f1d0f64f3269 | started | infra1 | http://127.0.0.1:12380 | http://127.0.0.1:2379  |
738| 91bc3c398fb3c146 | started | infra2 | http://127.0.0.1:22380 | http://127.0.0.1:22379 |
739| fd422379fda50e48 | started | infra3 | http://127.0.0.1:32380 | http://127.0.0.1:32379 |
740+------------------+---------+--------+------------------------+------------------------+
741```
742
743### ENDPOINT \<subcommand\>
744
745ENDPOINT provides commands for querying individual endpoints.
746
747#### Options
748
749- cluster -- fetch and use all endpoints from the etcd cluster member list
750
751### ENDPOINT HEALTH
752
753ENDPOINT HEALTH checks the health of the list of endpoints with respect to cluster. An endpoint is unhealthy
754when it cannot participate in consensus with the rest of the cluster.
755
756#### Output
757
758If an endpoint can participate in consensus, prints a message indicating the endpoint is healthy. If an endpoint fails to participate in consensus, prints a message indicating the endpoint is unhealthy.
759
760#### Example
761
762Check the default endpoint's health:
763
764```bash
765./etcdctl endpoint health
766# 127.0.0.1:2379 is healthy: successfully committed proposal: took = 2.095242ms
767```
768
769Check all endpoints for the cluster associated with the default endpoint:
770
771```bash
772./etcdctl endpoint --cluster health
773# http://127.0.0.1:2379 is healthy: successfully committed proposal: took = 1.060091ms
774# http://127.0.0.1:22379 is healthy: successfully committed proposal: took = 903.138µs
775# http://127.0.0.1:32379 is healthy: successfully committed proposal: took = 1.113848ms
776```
777
778### ENDPOINT STATUS
779
780ENDPOINT STATUS queries the status of each endpoint in the given endpoint list.
781
782#### Output
783
784##### Simple format
785
786Prints a humanized table of each endpoint URL, ID, version, database size, leadership status, raft term, and raft status.
787
788##### JSON format
789
790Prints a line of JSON encoding each endpoint URL, ID, version, database size, leadership status, raft term, and raft status.
791
792#### Examples
793
794Get the status for the default endpoint:
795
796```bash
797./etcdctl endpoint status
798# 127.0.0.1:2379, 8211f1d0f64f3269, 3.0.0, 25 kB, false, 2, 63
799```
800
801Get the status for the default endpoint as JSON:
802
803```bash
804./etcdctl -w json endpoint status
805# [{"Endpoint":"127.0.0.1:2379","Status":{"header":{"cluster_id":17237436991929493444,"member_id":9372538179322589801,"revision":2,"raft_term":2},"version":"3.0.0","dbSize":24576,"leader":18249187646912138824,"raftIndex":32623,"raftTerm":2}}]
806```
807
808Get the status for all endpoints in the cluster associated with the default endpoint:
809
810```bash
811./etcdctl -w table endpoint --cluster status
812+------------------------+------------------+----------------+---------+-----------+-----------+------------+
813|        ENDPOINT        |        ID        |    VERSION     | DB SIZE | IS LEADER | RAFT TERM | RAFT INDEX |
814+------------------------+------------------+----------------+---------+-----------+-----------+------------+
815| http://127.0.0.1:2379  | 8211f1d0f64f3269 | 3.2.0-rc.1+git |   25 kB |     false |         2 |          8 |
816| http://127.0.0.1:22379 | 91bc3c398fb3c146 | 3.2.0-rc.1+git |   25 kB |     false |         2 |          8 |
817| http://127.0.0.1:32379 | fd422379fda50e48 | 3.2.0-rc.1+git |   25 kB |      true |         2 |          8 |
818+------------------------+------------------+----------------+---------+-----------+-----------+------------+
819```
820
821### ENDPOINT HASHKV
822
823ENDPOINT HASHKV fetches the hash of the key-value store of an endpoint.
824
825#### Output
826
827##### Simple format
828
829Prints a humanized table of each endpoint URL and KV history hash.
830
831##### JSON format
832
833Prints a line of JSON encoding each endpoint URL and KV history hash.
834
835#### Examples
836
837Get the hash for the default endpoint:
838
839```bash
840./etcdctl endpoint hashkv
841# 127.0.0.1:2379, 1084519789
842```
843
844Get the status for the default endpoint as JSON:
845
846```bash
847./etcdctl -w json endpoint hashkv
848# [{"Endpoint":"127.0.0.1:2379","Hash":{"header":{"cluster_id":14841639068965178418,"member_id":10276657743932975437,"revision":1,"raft_term":3},"hash":1084519789,"compact_revision":-1}}]
849```
850
851Get the status for all endpoints in the cluster associated with the default endpoint:
852
853```bash
854./etcdctl -w table endpoint --cluster hashkv
855+------------------------+------------+
856|        ENDPOINT        |    HASH    |
857+------------------------+------------+
858| http://127.0.0.1:2379  | 1084519789 |
859| http://127.0.0.1:22379 | 1084519789 |
860| http://127.0.0.1:32379 | 1084519789 |
861+------------------------+------------+
862```
863
864### ALARM \<subcommand\>
865
866Provides alarm related commands
867
868### ALARM DISARM
869
870`alarm disarm` Disarms all alarms
871
872RPC: Alarm
873
874#### Output
875
876`alarm:<alarm type>` if alarm is present and disarmed.
877
878#### Examples
879
880```bash
881./etcdctl alarm disarm
882```
883
884If NOSPACE alarm is present:
885
886```bash
887./etcdctl alarm disarm
888# alarm:NOSPACE
889```
890
891### ALARM LIST
892
893`alarm list` lists all alarms.
894
895RPC: Alarm
896
897#### Output
898
899`alarm:<alarm type>` if alarm is present, empty string if no alarms present.
900
901#### Examples
902
903```bash
904./etcdctl alarm list
905```
906
907If NOSPACE alarm is present:
908
909```bash
910./etcdctl alarm list
911# alarm:NOSPACE
912```
913
914### DEFRAG [options]
915
916DEFRAG defragments the backend database file for a set of given endpoints while etcd is running, or directly defragments an etcd data directory while etcd is not running. When an etcd member reclaims storage space from deleted and compacted keys, the space is kept in a free list and the database file remains the same size. By defragmenting the database, the etcd member releases this free space back to the file system.
917
918**Note that defragmentation to a live member blocks the system from reading and writing data while rebuilding its states.**
919
920**Note that defragmentation request does not get replicated over cluster. That is, the request is only applied to the local node. Specify all members in `--endpoints` flag or `--cluster` flag to automatically find all cluster members.**
921
922#### Options
923
924- data-dir -- Optional. If present, defragments a data directory not in use by etcd.
925
926#### Output
927
928For each endpoints, prints a message indicating whether the endpoint was successfully defragmented.
929
930#### Example
931
932```bash
933./etcdctl --endpoints=localhost:2379,badendpoint:2379 defrag
934# Finished defragmenting etcd member[localhost:2379]
935# Failed to defragment etcd member[badendpoint:2379] (grpc: timed out trying to connect)
936```
937
938Run defragment operations for all endpoints in the cluster associated with the default endpoint:
939
940```bash
941./etcdctl defrag --cluster
942Finished defragmenting etcd member[http://127.0.0.1:2379]
943Finished defragmenting etcd member[http://127.0.0.1:22379]
944Finished defragmenting etcd member[http://127.0.0.1:32379]
945```
946
947To defragment a data directory directly, use the `--data-dir` flag:
948
949``` bash
950# Defragment while etcd is not running
951./etcdctl defrag --data-dir default.etcd
952# success (exit status 0)
953# Error: cannot open database at default.etcd/member/snap/db
954```
955
956#### Remarks
957
958DEFRAG returns a zero exit code only if it succeeded defragmenting all given endpoints.
959
960### SNAPSHOT \<subcommand\>
961
962SNAPSHOT provides commands to restore a snapshot of a running etcd server into a fresh cluster.
963
964### SNAPSHOT SAVE \<filename\>
965
966SNAPSHOT SAVE writes a point-in-time snapshot of the etcd backend database to a file.
967
968#### Output
969
970The backend snapshot is written to the given file path.
971
972#### Example
973
974Save a snapshot to "snapshot.db":
975```
976./etcdctl snapshot save snapshot.db
977```
978
979### SNAPSHOT RESTORE [options] \<filename\>
980
981SNAPSHOT RESTORE creates an etcd data directory for an etcd cluster member from a backend database snapshot and a new cluster configuration. Restoring the snapshot into each member for a new cluster configuration will initialize a new etcd cluster preloaded by the snapshot data.
982
983#### Options
984
985The snapshot restore options closely resemble to those used in the `etcd` command for defining a cluster.
986
987- data-dir -- Path to the data directory. Uses \<name\>.etcd if none given.
988
989- wal-dir -- Path to the WAL directory. Uses data directory if none given.
990
991- initial-cluster -- The initial cluster configuration for the restored etcd cluster.
992
993- initial-cluster-token -- Initial cluster token for the restored etcd cluster.
994
995- initial-advertise-peer-urls -- List of peer URLs for the member being restored.
996
997- name -- Human-readable name for the etcd cluster member being restored.
998
999- skip-hash-check -- Ignore snapshot integrity hash value (required if copied from data directory)
1000
1001#### Output
1002
1003A new etcd data directory initialized with the snapshot.
1004
1005#### Example
1006
1007Save a snapshot, restore into a new 3 node cluster, and start the cluster:
1008```
1009./etcdctl snapshot save snapshot.db
1010
1011# restore members
1012bin/etcdctl snapshot restore snapshot.db --initial-cluster-token etcd-cluster-1 --initial-advertise-peer-urls http://127.0.0.1:12380  --name sshot1 --initial-cluster 'sshot1=http://127.0.0.1:12380,sshot2=http://127.0.0.1:22380,sshot3=http://127.0.0.1:32380'
1013bin/etcdctl snapshot restore snapshot.db --initial-cluster-token etcd-cluster-1 --initial-advertise-peer-urls http://127.0.0.1:22380  --name sshot2 --initial-cluster 'sshot1=http://127.0.0.1:12380,sshot2=http://127.0.0.1:22380,sshot3=http://127.0.0.1:32380'
1014bin/etcdctl snapshot restore snapshot.db --initial-cluster-token etcd-cluster-1 --initial-advertise-peer-urls http://127.0.0.1:32380  --name sshot3 --initial-cluster 'sshot1=http://127.0.0.1:12380,sshot2=http://127.0.0.1:22380,sshot3=http://127.0.0.1:32380'
1015
1016# launch members
1017bin/etcd --name sshot1 --listen-client-urls http://127.0.0.1:2379 --advertise-client-urls http://127.0.0.1:2379 --listen-peer-urls http://127.0.0.1:12380 &
1018bin/etcd --name sshot2 --listen-client-urls http://127.0.0.1:22379 --advertise-client-urls http://127.0.0.1:22379 --listen-peer-urls http://127.0.0.1:22380 &
1019bin/etcd --name sshot3 --listen-client-urls http://127.0.0.1:32379 --advertise-client-urls http://127.0.0.1:32379 --listen-peer-urls http://127.0.0.1:32380 &
1020```
1021
1022### SNAPSHOT STATUS \<filename\>
1023
1024SNAPSHOT STATUS lists information about a given backend database snapshot file.
1025
1026#### Output
1027
1028##### Simple format
1029
1030Prints a humanized table of the database hash, revision, total keys, and size.
1031
1032##### JSON format
1033
1034Prints a line of JSON encoding the database hash, revision, total keys, and size.
1035
1036#### Examples
1037```bash
1038./etcdctl snapshot status file.db
1039# cf1550fb, 3, 3, 25 kB
1040```
1041
1042```bash
1043./etcdctl -write-out=json snapshot status file.db
1044# {"hash":3474280699,"revision":3,"totalKey":3,"totalSize":24576}
1045```
1046
1047```bash
1048./etcdctl -write-out=table snapshot status file.db
1049+----------+----------+------------+------------+
1050|   HASH   | REVISION | TOTAL KEYS | TOTAL SIZE |
1051+----------+----------+------------+------------+
1052| cf1550fb |        3 |          3 | 25 kB      |
1053+----------+----------+------------+------------+
1054```
1055
1056### MOVE-LEADER \<hexadecimal-transferee-id\>
1057
1058MOVE-LEADER transfers leadership from the leader to another member in the cluster.
1059
1060#### Example
1061
1062```bash
1063# to choose transferee
1064transferee_id=$(./etcdctl \
1065  --endpoints localhost:2379,localhost:22379,localhost:32379 \
1066  endpoint status | grep -m 1 "false" | awk -F', ' '{print $2}')
1067echo ${transferee_id}
1068# c89feb932daef420
1069
1070# endpoints should include leader node
1071./etcdctl --endpoints ${transferee_ep} move-leader ${transferee_id}
1072# Error:  no leader endpoint given at [localhost:22379 localhost:32379]
1073
1074# request to leader with target node ID
1075./etcdctl --endpoints ${leader_ep} move-leader ${transferee_id}
1076# Leadership transferred from 45ddc0e800e20b93 to c89feb932daef420
1077```
1078
1079## Concurrency commands
1080
1081### LOCK [options] \<lockname\> [command arg1 arg2 ...]
1082
1083LOCK acquires a distributed mutex with a given name. Once the lock is acquired, it will be held until etcdctl is terminated.
1084
1085#### Options
1086
1087- ttl - time out in seconds of lock session.
1088
1089#### Output
1090
1091Once the lock is acquired but no command is given, the result for the GET on the unique lock holder key is displayed.
1092
1093If a command is given, it will be executed with environment variables `ETCD_LOCK_KEY` and `ETCD_LOCK_REV` set to the lock's holder key and revision.
1094
1095#### Example
1096
1097Acquire lock with standard output display:
1098
1099```bash
1100./etcdctl lock mylock
1101# mylock/1234534535445
1102```
1103
1104Acquire lock and execute `echo lock acquired`:
1105
1106```bash
1107./etcdctl lock mylock echo lock acquired
1108# lock acquired
1109```
1110
1111Acquire lock and execute `etcdctl put` command
1112```bash
1113./etcdctl lock mylock ./etcdctl put foo bar
1114# OK
1115```
1116
1117#### Remarks
1118
1119LOCK returns a zero exit code only if it is terminated by a signal and releases the lock.
1120
1121If LOCK is abnormally terminated or fails to contact the cluster to release the lock, the lock will remain held until the lease expires. Progress may be delayed by up to the default lease length of 60 seconds.
1122
1123### ELECT [options] \<election-name\> [proposal]
1124
1125ELECT participates on a named election. A node announces its candidacy in the election by providing
1126a proposal value. If a node wishes to observe the election, ELECT listens for new leaders values.
1127Whenever a leader is elected, its proposal is given as output.
1128
1129#### Options
1130
1131- listen -- observe the election.
1132
1133#### Output
1134
1135- If a candidate, ELECT displays the GET on the leader key once the node is elected election.
1136
1137- If observing, ELECT streams the result for a GET on the leader key for the current election and all future elections.
1138
1139#### Example
1140
1141```bash
1142./etcdctl elect myelection foo
1143# myelection/1456952310051373265
1144# foo
1145```
1146
1147#### Remarks
1148
1149ELECT returns a zero exit code only if it is terminated by a signal and can revoke its candidacy or leadership, if any.
1150
1151If a candidate is abnormally terminated, election rogress may be delayed by up to the default lease length of 60 seconds.
1152
1153## Authentication commands
1154
1155### AUTH \<enable or disable\>
1156
1157`auth enable` activates authentication on an etcd cluster and `auth disable` deactivates. When authentication is enabled, etcd checks all requests for appropriate authorization.
1158
1159RPC: AuthEnable/AuthDisable
1160
1161#### Output
1162
1163`Authentication Enabled`.
1164
1165#### Examples
1166
1167```bash
1168./etcdctl user add root
1169# Password of root:#type password for root
1170# Type password of root again for confirmation:#re-type password for root
1171# User root created
1172./etcdctl user grant-role root root
1173# Role root is granted to user root
1174./etcdctl user get root
1175# User: root
1176# Roles: root
1177./etcdctl role add root
1178# Role root created
1179./etcdctl role get root
1180# Role root
1181# KV Read:
1182# KV Write:
1183./etcdctl auth enable
1184# Authentication Enabled
1185```
1186
1187### ROLE \<subcommand\>
1188
1189ROLE is used to specify different roles which can be assigned to etcd user(s).
1190
1191### ROLE ADD \<role name\>
1192
1193`role add` creates a role.
1194
1195RPC: RoleAdd
1196
1197#### Output
1198
1199`Role <role name> created`.
1200
1201#### Examples
1202
1203```bash
1204./etcdctl --user=root:123 role add myrole
1205# Role myrole created
1206```
1207
1208### ROLE GET \<role name\>
1209
1210`role get` lists detailed role information.
1211
1212RPC: RoleGet
1213
1214#### Output
1215
1216Detailed role information.
1217
1218#### Examples
1219
1220```bash
1221./etcdctl --user=root:123 role get myrole
1222# Role myrole
1223# KV Read:
1224# foo
1225# KV Write:
1226# foo
1227```
1228
1229### ROLE DELETE \<role name\>
1230
1231`role delete` deletes a role.
1232
1233RPC: RoleDelete
1234
1235#### Output
1236
1237`Role <role name> deleted`.
1238
1239#### Examples
1240
1241```bash
1242./etcdctl --user=root:123 role delete myrole
1243# Role myrole deleted
1244```
1245
1246### ROLE LIST \<role name\>
1247
1248`role list` lists all roles in etcd.
1249
1250RPC: RoleList
1251
1252#### Output
1253
1254A role per line.
1255
1256#### Examples
1257
1258```bash
1259./etcdctl --user=root:123 role list
1260# roleA
1261# roleB
1262# myrole
1263```
1264
1265### ROLE GRANT-PERMISSION [options] \<role name\> \<permission type\> \<key\> [endkey]
1266
1267`role grant-permission` grants a key to a role.
1268
1269RPC: RoleGrantPermission
1270
1271#### Options
1272
1273- from-key -- grant a permission of keys that are greater than or equal to the given key using byte compare
1274
1275- prefix -- grant a prefix permission
1276
1277#### Output
1278
1279`Role <role name> updated`.
1280
1281#### Examples
1282
1283Grant read and write permission on the key `foo` to role `myrole`:
1284
1285```bash
1286./etcdctl --user=root:123 role grant-permission myrole readwrite foo
1287# Role myrole updated
1288```
1289
1290Grant read permission on the wildcard key pattern `foo/*` to role `myrole`:
1291
1292```bash
1293./etcdctl --user=root:123 role grant-permission --prefix myrole readwrite foo/
1294# Role myrole updated
1295```
1296
1297### ROLE REVOKE-PERMISSION \<role name\> \<permission type\> \<key\> [endkey]
1298
1299`role revoke-permission` revokes a key from a role.
1300
1301RPC: RoleRevokePermission
1302
1303#### Options
1304
1305- from-key -- revoke a permission of keys that are greater than or equal to the given key using byte compare
1306
1307- prefix -- revoke a prefix permission
1308
1309#### Output
1310
1311`Permission of key <key> is revoked from role <role name>` for single key. `Permission of range [<key>, <endkey>) is revoked from role <role name>` for a key range. Exit code is zero.
1312
1313#### Examples
1314
1315```bash
1316./etcdctl --user=root:123 role revoke-permission myrole foo
1317# Permission of key foo is revoked from role myrole
1318```
1319
1320### USER \<subcommand\>
1321
1322USER provides commands for managing users of etcd.
1323
1324### USER ADD \<user name or user:password\> [options]
1325
1326`user add` creates a user.
1327
1328RPC: UserAdd
1329
1330#### Options
1331
1332- interactive -- Read password from stdin instead of interactive terminal
1333
1334#### Output
1335
1336`User <user name> created`.
1337
1338#### Examples
1339
1340```bash
1341./etcdctl --user=root:123 user add myuser
1342# Password of myuser: #type password for my user
1343# Type password of myuser again for confirmation:#re-type password for my user
1344# User myuser created
1345```
1346
1347### USER GET \<user name\> [options]
1348
1349`user get` lists detailed user information.
1350
1351RPC: UserGet
1352
1353#### Options
1354
1355- detail -- Show permissions of roles granted to the user
1356
1357#### Output
1358
1359Detailed user information.
1360
1361#### Examples
1362
1363```bash
1364./etcdctl --user=root:123 user get myuser
1365# User: myuser
1366# Roles:
1367```
1368
1369### USER DELETE \<user name\>
1370
1371`user delete` deletes a user.
1372
1373RPC: UserDelete
1374
1375#### Output
1376
1377`User <user name> deleted`.
1378
1379#### Examples
1380
1381```bash
1382./etcdctl --user=root:123 user delete myuser
1383# User myuser deleted
1384```
1385
1386### USER LIST
1387
1388`user list` lists detailed user information.
1389
1390RPC: UserList
1391
1392#### Output
1393
1394- List of users, one per line.
1395
1396#### Examples
1397
1398```bash
1399./etcdctl --user=root:123 user list
1400# user1
1401# user2
1402# myuser
1403```
1404
1405### USER PASSWD \<user name\> [options]
1406
1407`user passwd` changes a user's password.
1408
1409RPC: UserChangePassword
1410
1411#### Options
1412
1413- interactive -- if true, read password in interactive terminal
1414
1415#### Output
1416
1417`Password updated`.
1418
1419#### Examples
1420
1421```bash
1422./etcdctl --user=root:123 user passwd myuser
1423# Password of myuser: #type new password for my user
1424# Type password of myuser again for confirmation: #re-type the new password for my user
1425# Password updated
1426```
1427
1428### USER GRANT-ROLE \<user name\> \<role name\>
1429
1430`user grant-role` grants a role to a user
1431
1432RPC: UserGrantRole
1433
1434#### Output
1435
1436`Role <role name> is granted to user <user name>`.
1437
1438#### Examples
1439
1440```bash
1441./etcdctl --user=root:123 user grant-role userA roleA
1442# Role roleA is granted to user userA
1443```
1444
1445### USER REVOKE-ROLE \<user name\> \<role name\>
1446
1447`user revoke-role` revokes a role from a user
1448
1449RPC: UserRevokeRole
1450
1451#### Output
1452
1453`Role <role name> is revoked from user <user name>`.
1454
1455#### Examples
1456
1457```bash
1458./etcdctl --user=root:123 user revoke-role userA roleA
1459# Role roleA is revoked from user userA
1460```
1461
1462## Utility commands
1463
1464### MAKE-MIRROR [options] \<destination\>
1465
1466[make-mirror][mirror] mirrors a key prefix in an etcd cluster to a destination etcd cluster.
1467
1468#### Options
1469
1470- dest-cacert -- TLS certificate authority file for destination cluster
1471
1472- dest-cert -- TLS certificate file for destination cluster
1473
1474- dest-key -- TLS key file for destination cluster
1475
1476- prefix -- The key-value prefix to mirror
1477
1478- dest-prefix -- The destination prefix to mirror a prefix to a different prefix in the destination cluster
1479
1480- no-dest-prefix -- Mirror key-values to the root of the destination cluster
1481
1482- dest-insecure-transport -- Disable transport security for client connections
1483
1484#### Output
1485
1486The approximate total number of keys transferred to the destination cluster, updated every 30 seconds.
1487
1488#### Examples
1489
1490```
1491./etcdctl make-mirror mirror.example.com:2379
1492# 10
1493# 18
1494```
1495
1496[mirror]: ./doc/mirror_maker.md
1497
1498### MIGRATE [options]
1499
1500Migrates keys in a v2 store to a v3 mvcc store. Users should run migration command for all members in the cluster.
1501
1502#### Options
1503
1504- data-dir -- Path to the data directory
1505
1506- wal-dir -- Path to the WAL directory
1507
1508- transformer -- Path to the user-provided transformer program (default if not provided)
1509
1510#### Output
1511
1512No output on success.
1513
1514#### Default transformer
1515
1516If user does not provide a transformer program, migrate command will use the default transformer. The default transformer transforms `storev2` formatted keys into `mvcc` formatted keys according to the following Go program:
1517
1518```go
1519func transform(n *storev2.Node) *mvccpb.KeyValue {
1520	if n.Dir {
1521		return nil
1522	}
1523	kv := &mvccpb.KeyValue{
1524		Key:            []byte(n.Key),
1525		Value:          []byte(n.Value),
1526		CreateRevision: int64(n.CreatedIndex),
1527		ModRevision:    int64(n.ModifiedIndex),
1528		Version:        1,
1529	}
1530	return kv
1531}
1532```
1533
1534#### User-provided transformer
1535
1536Users can provide a customized 1:n transformer function that transforms a key from the v2 store to any number of keys in the mvcc store. The migration program writes JSON formatted [v2 store keys][v2key] to the transformer program's stdin, reads protobuf formatted [mvcc keys][v3key] back from the transformer program's stdout, and finishes migration by saving the transformed keys into the mvcc store.
1537
1538The provided transformer should read until EOF and flush the stdout before exiting to ensure data integrity.
1539
1540#### Example
1541
1542```
1543./etcdctl migrate --data-dir=/var/etcd --transformer=k8s-transformer
1544# finished transforming keys
1545```
1546
1547### VERSION
1548
1549Prints the version of etcdctl.
1550
1551#### Output
1552
1553Prints etcd version and API version.
1554
1555#### Examples
1556
1557```bash
1558./etcdctl version
1559# etcdctl version: 3.1.0-alpha.0+git
1560# API version: 3.1
1561```
1562
1563### CHECK \<subcommand\>
1564
1565CHECK provides commands for checking properties of the etcd cluster.
1566
1567### CHECK PERF [options]
1568
1569CHECK PERF checks the performance of the etcd cluster for 60 seconds. Running the `check perf` often can create a large keyspace history which can be auto compacted and defragmented using the `--auto-compact` and `--auto-defrag` options as described below.
1570
1571RPC: CheckPerf
1572
1573#### Options
1574
1575- load -- the performance check's workload model. Accepted workloads: s(small), m(medium), l(large), xl(xLarge)
1576
1577- prefix -- the prefix for writing the performance check's keys.
1578
1579- auto-compact -- if true, compact storage with last revision after test is finished.
1580
1581- auto-defrag -- if true, defragment storage after test is finished.
1582
1583#### Output
1584
1585Prints the result of performance check on different criteria like throughput. Also prints an overall status of the check as pass or fail.
1586
1587#### Examples
1588
1589Shows examples of both, pass and fail, status. The failure is due to the fact that a large workload was tried on a single node etcd cluster running on a laptop environment created for development and testing purpose.
1590
1591```bash
1592./etcdctl check perf --load="s"
1593# 60 / 60 Booooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo! 100.00%1m0s
1594# PASS: Throughput is 150 writes/s
1595# PASS: Slowest request took 0.087509s
1596# PASS: Stddev is 0.011084s
1597# PASS
1598./etcdctl check perf --load="l"
1599# 60 / 60 Booooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo! 100.00%1m0s
1600# FAIL: Throughput too low: 6808 writes/s
1601# PASS: Slowest request took 0.228191s
1602# PASS: Stddev is 0.033547s
1603# FAIL
1604```
1605
1606### CHECK DATASCALE [options]
1607
1608CHECK DATASCALE checks the memory usage of holding data for different workloads on a given server endpoint. Running the `check datascale` often can create a large keyspace history which can be auto compacted and defragmented using the `--auto-compact` and `--auto-defrag` options as described below.
1609
1610RPC: CheckDatascale
1611
1612#### Options
1613
1614- load -- the datascale check's workload model. Accepted workloads: s(small), m(medium), l(large), xl(xLarge)
1615
1616- prefix -- the prefix for writing the datascale check's keys.
1617
1618- auto-compact -- if true, compact storage with last revision after test is finished.
1619
1620- auto-defrag -- if true, defragment storage after test is finished.
1621
1622#### Output
1623
1624Prints the system memory usage for a given workload. Also prints status of compact and defragment if related options are passed.
1625
1626#### Examples
1627
1628```bash
1629./etcdctl check datascale --load="s" --auto-compact=true --auto-defrag=true
1630# Start data scale check for work load [10000 key-value pairs, 1024 bytes per key-value, 50 concurrent clients].
1631# Compacting with revision 18346204
1632# Compacted with revision 18346204
1633# Defragmenting "127.0.0.1:2379"
1634# Defragmented "127.0.0.1:2379"
1635# PASS: Approximate system memory used : 64.30 MB.
1636```
1637
1638## Exit codes
1639
1640For all commands, a successful execution return a zero exit code. All failures will return non-zero exit codes.
1641
1642## Output formats
1643
1644All commands accept an output format by setting `-w` or `--write-out`. All commands default to the "simple" output format, which is meant to be human-readable. The simple format is listed in each command's `Output` description since it is customized for each command. If a command has a corresponding RPC, it will respect all output formats.
1645
1646If a command fails, returning a non-zero exit code, an error string will be written to standard error regardless of output format.
1647
1648### Simple
1649
1650A format meant to be easy to parse and human-readable. Specific to each command.
1651
1652### JSON
1653
1654The JSON encoding of the command's [RPC response][etcdrpc]. Since etcd's RPCs use byte strings, the JSON output will encode keys and values in base64.
1655
1656Some commands without an RPC also support JSON; see the command's `Output` description.
1657
1658### Protobuf
1659
1660The protobuf encoding of the command's [RPC response][etcdrpc]. If an RPC is streaming, the stream messages will be concetenated. If an RPC is not given for a command, the protobuf output is not defined.
1661
1662### Fields
1663
1664An output format similar to JSON but meant to parse with coreutils. For an integer field named `Field`, it writes a line in the format `"Field" : %d` where `%d` is go's integer formatting. For byte array fields, it writes `"Field" : %q` where `%q` is go's quoted string formatting (e.g., `[]byte{'a', '\n'}` is written as `"a\n"`).
1665
1666## Compatibility Support
1667
1668etcdctl is still in its early stage. We try out best to ensure fully compatible releases, however we might break compatibility to fix bugs or improve commands. If we intend to release a version of etcdctl with backward incompatibilities, we will provide notice prior to release and have instructions on how to upgrade.
1669
1670### Input Compatibility
1671
1672Input includes the command name, its flags, and its arguments. We ensure backward compatibility of the input of normal commands in non-interactive mode.
1673
1674### Output Compatibility
1675
1676Output includes output from etcdctl and its exit code. etcdctl provides `simple` output format by default.
1677We ensure compatibility for the `simple` output format of normal commands in non-interactive mode. Currently, we do not ensure
1678backward compatibility for `JSON` format and the format in non-interactive mode. Currently, we do not ensure backward compatibility of utility commands.
1679
1680### TODO: compatibility with etcd server
1681
1682[etcd]: https://github.com/coreos/etcd
1683[READMEv2]: READMEv2.md
1684[v2key]: ../store/node_extern.go#L28-L37
1685[v3key]: ../mvcc/mvccpb/kv.proto#L12-L29
1686[etcdrpc]: ../etcdserver/etcdserverpb/rpc.proto
1687[storagerpc]: ../mvcc/mvccpb/kv.proto
1688

READMEv2.md

1etcdctl
2========
3
4`etcdctl` is a command line client for [etcd][etcd].
5It can be used in scripts or for administrators to explore an etcd cluster.
6
7## Getting etcdctl
8
9The latest release is available as a binary at [Github][github-release] along with etcd.
10
11etcdctl can also be built from source using the build script found in the parent directory.
12
13## Configuration
14### --debug
15+ output cURL commands which can be used to reproduce the request
16
17### --no-sync
18+ don't synchronize cluster information before sending request
19+ Use this to access non-published client endpoints
20+ Without this flag, values from `--endpoint` flag will be overwritten by etcd cluster when it does internal sync.
21
22### --output, -o
23+ output response in the given format (`simple`, `extended` or `json`)
24+ default: `"simple"`
25
26### --discovery-srv, -D
27+ domain name to query for SRV records describing cluster endpoints
28+ default: none
29+ env variable: ETCDCTL_DISCOVERY_SRV
30
31### --peers
32+ a comma-delimited list of machine addresses in the cluster
33+ default: `"http://127.0.0.1:2379"`
34+ env variable: ETCDCTL_PEERS
35
36### --endpoint
37+ a comma-delimited list of machine addresses in the cluster
38+ default: `"http://127.0.0.1:2379"`
39+ env variable: ETCDCTL_ENDPOINT
40+ Without `--no-sync` flag, this will be overwritten by etcd cluster when it does internal sync.
41
42### --cert-file
43+ identify HTTPS client using this SSL certificate file
44+ default: none
45+ env variable: ETCDCTL_CERT_FILE
46
47### --key-file
48+ identify HTTPS client using this SSL key file
49+ default: none
50+ env variable: ETCDCTL_KEY_FILE
51
52### --ca-file
53+ verify certificates of HTTPS-enabled servers using this CA bundle
54+ default: none
55+ env variable: ETCDCTL_CA_FILE
56
57### --username, -u
58+ provide username[:password] and prompt if password is not supplied
59+ default: none
60+ env variable: ETCDCTL_USERNAME
61
62### --timeout
63+ connection timeout per request
64+ default: `"1s"`
65
66### --total-timeout
67+ timeout for the command execution (except watch)
68+ default: `"5s"`
69
70## Usage
71
72### Setting Key Values
73
74Set a value on the `/foo/bar` key:
75
76```sh
77$ etcdctl set /foo/bar "Hello world"
78Hello world
79```
80
81Set a value on the `/foo/bar` key with a value that expires in 60 seconds:
82
83```sh
84$ etcdctl set /foo/bar "Hello world" --ttl 60
85Hello world
86```
87
88Conditionally set a value on `/foo/bar` if the previous value was "Hello world":
89
90```sh
91$ etcdctl set /foo/bar "Goodbye world" --swap-with-value "Hello world"
92Goodbye world
93```
94
95Conditionally set a value on `/foo/bar` if the previous etcd index was 12:
96
97```sh
98$ etcdctl set /foo/bar "Goodbye world" --swap-with-index 12
99Goodbye world
100```
101
102Create a new key `/foo/bar`, only if the key did not previously exist:
103
104```sh
105$ etcdctl mk /foo/new_bar "Hello world"
106Hello world
107```
108
109Create a new in-order key under dir `/fooDir`:
110
111```sh
112$ etcdctl mk --in-order /fooDir "Hello world"
113```
114
115Create a new dir `/fooDir`, only if the key did not previously exist:
116
117```sh
118$ etcdctl mkdir /fooDir
119```
120
121Update an existing key `/foo/bar`, only if the key already existed:
122
123```sh
124$ etcdctl update /foo/bar "Hola mundo"
125Hola mundo
126```
127
128Create or update a directory called `/mydir`:
129
130```sh
131$ etcdctl setdir /mydir
132```
133
134
135### Retrieving a key value
136
137Get the current value for a single key in the local etcd node:
138
139```sh
140$ etcdctl get /foo/bar
141Hello world
142```
143
144Get the value of a key with additional metadata in a parseable format:
145
146```sh
147$ etcdctl -o extended get /foo/bar
148Key: /foo/bar
149Modified-Index: 72
150TTL: 0
151Etcd-Index: 72
152Raft-Index: 5611
153Raft-Term: 1
154
155Hello World
156```
157
158### Listing a directory
159
160Explore the keyspace using the `ls` command
161
162```sh
163$ etcdctl ls
164/akey
165/adir
166$ etcdctl ls /adir
167/adir/key1
168/adir/key2
169```
170
171Add `--recursive` to recursively list subdirectories encountered.
172
173```sh
174$ etcdctl ls --recursive
175/akey
176/adir
177/adir/key1
178/adir/key2
179```
180
181Directories can also have a trailing `/` added to output using `-p`.
182
183```sh
184$ etcdctl ls -p
185/akey
186/adir/
187```
188
189### Deleting a key
190
191Delete a key:
192
193```sh
194$ etcdctl rm /foo/bar
195```
196
197Delete an empty directory or a key-value pair
198
199```sh
200$ etcdctl rmdir /path/to/dir
201```
202
203or
204
205```sh
206$ etcdctl rm /path/to/dir --dir
207```
208
209Recursively delete a key and all child keys:
210
211```sh
212$ etcdctl rm /path/to/dir --recursive
213```
214
215Conditionally delete `/foo/bar` if the previous value was "Hello world":
216
217```sh
218$ etcdctl rm /foo/bar --with-value "Hello world"
219```
220
221Conditionally delete `/foo/bar` if the previous etcd index was 12:
222
223```sh
224$ etcdctl rm /foo/bar --with-index 12
225```
226
227### Watching for changes
228
229Watch for only the next change on a key:
230
231```sh
232$ etcdctl watch /foo/bar
233Hello world
234```
235
236Continuously watch a key:
237
238```sh
239$ etcdctl watch /foo/bar --forever
240Hello world
241.... client hangs forever until ctrl+C printing values as key change
242```
243
244Continuously watch a key, starting with a given etcd index:
245
246```sh
247$ etcdctl watch /foo/bar --forever --index 12
248Hello world
249.... client hangs forever until ctrl+C printing values as key change
250```
251
252Continuously watch a key and exec a program:
253
254```sh
255$ etcdctl exec-watch /foo/bar -- sh -c "env | grep ETCD"
256ETCD_WATCH_ACTION=set
257ETCD_WATCH_VALUE=My configuration stuff
258ETCD_WATCH_MODIFIED_INDEX=1999
259ETCD_WATCH_KEY=/foo/bar
260ETCD_WATCH_ACTION=set
261ETCD_WATCH_VALUE=My new configuration stuff
262ETCD_WATCH_MODIFIED_INDEX=2000
263ETCD_WATCH_KEY=/foo/bar
264```
265
266Continuously and recursively watch a key and exec a program:
267```sh
268$ etcdctl exec-watch --recursive /foo -- sh -c "env | grep ETCD"
269ETCD_WATCH_ACTION=set
270ETCD_WATCH_VALUE=My configuration stuff
271ETCD_WATCH_MODIFIED_INDEX=1999
272ETCD_WATCH_KEY=/foo/bar
273ETCD_WATCH_ACTION=set
274ETCD_WATCH_VALUE=My new configuration stuff
275ETCD_WATCH_MODIFIED_INDEX=2000
276ETCD_WATCH_KEY=/foo/barbar
277```
278
279## Return Codes
280
281The following exit codes can be returned from etcdctl:
282
283```
2840    Success
2851    Malformed etcdctl arguments
2862    Failed to connect to host
2873    Failed to auth (client cert rejected, ca validation failure, etc)
2884    400 error from etcd
2895    500 error from etcd
290```
291
292## Endpoint
293
294If the etcd cluster isn't available on `http://127.0.0.1:2379`, specify a `--endpoint` flag or `ETCDCTL_ENDPOINT` environment variable. One endpoint or a comma-separated list of endpoints can be listed. This option is ignored if the `--discovery-srv` option is provided.
295
296```sh
297ETCDCTL_ENDPOINT="http://10.0.28.1:4002" etcdctl set my-key to-a-value
298ETCDCTL_ENDPOINT="http://10.0.28.1:4002,http://10.0.28.2:4002,http://10.0.28.3:4002" etcdctl set my-key to-a-value
299etcdctl --endpoint http://10.0.28.1:4002 my-key to-a-value
300etcdctl --endpoint http://10.0.28.1:4002,http://10.0.28.2:4002,http://10.0.28.3:4002 etcdctl set my-key to-a-value
301```
302
303## Username and Password
304
305If the etcd cluster is protected by [authentication][authentication], specify username and password using the [`--username`][username-flag] or `ETCDCTL_USERNAME` environment variable. When `--username` flag or `ETCDCTL_USERNAME` environment variable doesn't contain password, etcdctl will prompt password in interactive mode.
306
307```sh
308ETCDCTL_USERNAME="root:password" etcdctl set my-key to-a-value
309```
310
311## DNS Discovery
312
313To discover the etcd cluster through domain SRV records,  specify a `--discovery-srv` flag or `ETCDCTL_DISCOVERY_SRV` environment variable. This option takes precedence over the `--endpoint` flag.
314
315```sh
316ETCDCTL_DISCOVERY_SRV="some-domain" etcdctl set my-key to-a-value
317etcdctl --discovery-srv some-domain set my-key to-a-value
318```
319
320## Project Details
321
322### Versioning
323
324etcdctl uses [semantic versioning][semver].
325Releases will follow lockstep with the etcd release cycle.
326
327### License
328
329etcdctl is under the Apache 2.0 license. See the [LICENSE][license] file for details.
330
331[authentication]: ../Documentation/v2/authentication.md
332[etcd]: https://github.com/coreos/etcd
333[github-release]: https://github.com/coreos/etcd/releases/
334[license]: ../LICENSE
335[semver]: http://semver.org/
336[username-flag]: #--username--u
337