go.etcd.io/etcd@v3.3.27+incompatible/etcdctl/README.md (about)

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