etcd/etcdctl/README.md

1688 lines
42 KiB
Markdown
Raw Normal View History

2014-10-23 03:59:29 +04:00
etcdctl
========
`etcdctl` is a command line client for [etcd][etcd].
The 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].
If using released versions earlier than v3.4, set `ETCDCTL_API=3` to use v3 API.
2014-10-23 03:59:29 +04:00
Global flags (e.g., `dial-timeout`, `--cacert`, `--cert`, `--key`) can be set with environment variables:
```
ETCDCTL_DIAL_TIMEOUT=3s
ETCDCTL_CACERT=/tmp/ca.pem
ETCDCTL_CERT=/tmp/cert.pem
ETCDCTL_KEY=/tmp/key.pem
```
Prefix flag strings with `ETCDCTL_`, convert all letters to upper-case, and replace dash(`-`) with underscore(`_`).
## Key-value commands
2016-06-01 21:28:43 +03:00
### PUT [options] \<key\> \<value\>
2014-10-23 03:59:29 +04:00
2016-06-01 21:28:43 +03:00
PUT assigns the specified value with the specified key. If key already holds a value, it is overwritten.
2014-10-23 03:59:29 +04:00
RPC: Put
2016-06-01 21:28:43 +03:00
#### Options
2016-06-01 21:28:43 +03:00
- lease -- lease ID (in hexadecimal) to attach to the key.
- prev-kv -- return the previous key-value pair before modification.
- ignore-value -- updates the key using its current value.
- ignore-lease -- updates the key using its current lease.
#### Output
`OK`
2016-06-01 21:28:43 +03:00
#### Examples
2016-09-15 09:32:38 +03:00
```bash
./etcdctl put foo bar --lease=1234abcd
2016-09-09 12:49:52 +03:00
# OK
./etcdctl get foo
2016-09-09 12:49:52 +03:00
# foo
# bar
./etcdctl put foo --ignore-value # to detache lease
# OK
2016-06-01 21:28:43 +03:00
```
```bash
./etcdctl put foo bar --lease=1234abcd
# OK
./etcdctl put foo bar1 --ignore-lease # to use existing lease 1234abcd
# OK
./etcdctl get foo
# foo
# bar1
```
```bash
./etcdctl put foo bar1 --prev-kv
# OK
# foo
# bar
./etcdctl get foo
# foo
# bar1
```
#### Remarks
2014-10-23 03:59:29 +04:00
2016-06-01 21:28:43 +03:00
If \<value\> isn't given as command line argument, this command tries to read the value from standard input.
2014-10-23 03:59:29 +04:00
2016-06-01 21:28:43 +03:00
When \<value\> begins with '-', \<value\> is interpreted as a flag.
Insert '--' for workaround:
2014-10-23 03:59:29 +04:00
2016-09-15 09:32:38 +03:00
```bash
2016-06-01 21:28:43 +03:00
./etcdctl put <key> -- <value>
./etcdctl put -- <key> <value>
2014-10-23 03:59:29 +04:00
```
Providing \<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:
```bash
./etcdctl put <key>\r
<value>
```
A \<value\> can have multiple lines or spaces but it must be provided with a double-quote as demonstrated below:
```bash
./etcdctl put foo "bar1 2 3"
```
2016-06-01 21:28:43 +03:00
### GET [options] \<key\> [range_end]
GET gets the key or a range of keys [key, range_end) if range_end is given.
2016-06-01 21:28:43 +03:00
RPC: Range
2016-06-01 21:28:43 +03:00
#### Options
- hex -- print out key and value as hex encode string
- limit -- maximum number of results
- prefix -- get keys by matching prefix
- order -- order of results; ASCEND or DESCEND
- sort-by -- sort target; CREATE, KEY, MODIFY, VALUE, or VERSION
- rev -- specify the kv revision
- print-value-only -- print only value when used with write-out=simple
- consistency -- Linearizable(l) or Serializable(s)
- from-key -- Get keys that are greater than or equal to the given key using byte compare
- keys-only -- Get only the keys
2016-06-01 21:28:43 +03:00
#### Output
2016-06-01 21:28:43 +03:00
\<key\>\n\<value\>\n\<next_key\>\n\<next_value\>...
2016-06-01 21:28:43 +03:00
#### Examples
First, populate etcd with some keys:
2016-09-15 09:32:38 +03:00
```bash
./etcdctl put foo bar
# OK
./etcdctl put foo1 bar1
# OK
./etcdctl put foo2 bar2
# OK
./etcdctl put foo3 bar3
# OK
```
Get the key named `foo`:
```bash
2016-06-01 21:28:43 +03:00
./etcdctl get foo
2016-09-09 12:49:52 +03:00
# foo
# bar
```
Get all keys:
```bash
./etcdctl get --from-key ''
# foo
# bar
# foo1
# bar1
# foo2
# foo2
# foo3
# bar3
```
Get all keys with names greater than or equal to `foo1`:
```bash
./etcdctl get --from-key foo1
# foo1
# bar1
# foo2
# bar2
# foo3
# bar3
```
Get keys with names greater than or equal to `foo1` and less than `foo3`:
```bash
./etcdctl get foo1 foo3
# foo1
# bar1
# foo2
# bar2
2014-10-23 03:59:29 +04:00
```
#### Remarks
2016-06-01 21:28:43 +03:00
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.
2016-06-01 21:28:43 +03:00
### DEL [options] \<key\> [range_end]
Removes the specified key or range of keys [key, range_end) if range_end is given.
2016-06-01 21:28:43 +03:00
RPC: DeleteRange
2016-06-01 21:28:43 +03:00
#### Options
- prefix -- delete keys by matching prefix
2016-09-21 21:46:53 +03:00
- prev-kv -- return deleted key-value pairs
- from-key -- delete keys that are greater than or equal to the given key using byte compare
2016-06-01 21:28:43 +03:00
#### Output
2016-06-01 21:28:43 +03:00
Prints the number of keys that were removed in decimal if DEL succeeded.
2016-06-01 21:28:43 +03:00
#### Examples
2016-09-15 09:32:38 +03:00
```bash
2016-06-01 21:28:43 +03:00
./etcdctl put foo bar
2016-09-09 12:49:52 +03:00
# OK
2016-06-01 21:28:43 +03:00
./etcdctl del foo
2016-09-09 12:49:52 +03:00
# 1
./etcdctl get foo
2016-06-01 21:28:43 +03:00
```
```bash
./etcdctl put key val
# OK
./etcdctl del --prev-kv key
# 1
# key
# val
./etcdctl get key
```
```bash
./etcdctl put a 123
# OK
./etcdctl put b 456
# OK
./etcdctl put z 789
# OK
./etcdctl del --from-key a
# 3
./etcdctl get --from-key a
```
```bash
./etcdctl put zoo val
# OK
./etcdctl put zoo1 val1
# OK
./etcdctl put zoo2 val2
# OK
./etcdctl del --prefix zoo
# 3
./etcdctl get zoo2
```
2016-06-01 21:28:43 +03:00
### TXN [options]
TXN reads multiple etcd requests from standard input and applies them as a single atomic transaction.
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.
RPC: Txn
2016-06-01 21:28:43 +03:00
#### Options
- hex -- print out keys and values as hex encoded strings.
2016-06-01 21:28:43 +03:00
- interactive -- input transaction with interactive prompting.
2016-06-01 21:28:43 +03:00
#### Input Format
```ebnf
<Txn> ::= <CMP>* "\n" <THEN> "\n" <ELSE> "\n"
<CMP> ::= (<CMPCREATE>|<CMPMOD>|<CMPVAL>|<CMPVER>|<CMPLEASE>) "\n"
2016-06-01 21:28:43 +03:00
<CMPOP> ::= "<" | "=" | ">"
<CMPCREATE> := ("c"|"create")"("<KEY>")" <CMPOP> <REVISION>
2016-06-01 21:28:43 +03:00
<CMPMOD> ::= ("m"|"mod")"("<KEY>")" <CMPOP> <REVISION>
<CMPVAL> ::= ("val"|"value")"("<KEY>")" <CMPOP> <VALUE>
<CMPVER> ::= ("ver"|"version")"("<KEY>")" <CMPOP> <VERSION>
<CMPLEASE> ::= "lease("<KEY>")" <CMPOP> <LEASE>
2016-06-01 21:28:43 +03:00
<THEN> ::= <OP>*
<ELSE> ::= <OP>*
<OP> ::= ((see put, get, del etcdctl command syntax)) "\n"
<KEY> ::= (%q formatted string)
<VALUE> ::= (%q formatted string)
<REVISION> ::= "\""[0-9]+"\""
<VERSION> ::= "\""[0-9]+"\""
<LEASE> ::= "\""[0-9]+\""
2014-10-23 03:59:29 +04:00
```
#### Output
2016-06-01 21:28:43 +03:00
`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.
2014-10-23 03:59:29 +04:00
2016-06-01 21:28:43 +03:00
#### Examples
txn in interactive mode:
2016-09-15 09:32:38 +03:00
```bash
2016-06-01 21:28:43 +03:00
./etcdctl txn -i
# compares:
2016-06-01 21:28:43 +03:00
mod("key1") > "0"
# success requests (get, put, delete):
2016-06-01 21:28:43 +03:00
put key1 "overwrote-key1"
# failure requests (get, put, delete):
2016-06-01 21:28:43 +03:00
put key1 "created-key1"
put key2 "some extra key"
2016-09-09 12:49:52 +03:00
# FAILURE
2016-06-01 21:28:43 +03:00
2016-09-09 12:49:52 +03:00
# OK
2016-06-01 21:28:43 +03:00
2016-09-09 12:49:52 +03:00
# OK
2016-06-01 21:28:43 +03:00
```
txn in non-interactive mode:
2016-09-15 09:32:38 +03:00
```bash
2016-06-01 21:28:43 +03:00
./etcdctl txn <<<'mod("key1") > "0"
put key1 "overwrote-key1"
put key1 "created-key1"
put key2 "some extra key"
'
2016-09-15 09:32:38 +03:00
2016-09-09 12:49:52 +03:00
# FAILURE
2016-06-01 21:28:43 +03:00
2016-09-09 12:49:52 +03:00
# OK
2016-06-01 21:28:43 +03:00
2016-09-09 12:49:52 +03:00
# OK
```
2016-06-01 21:28:43 +03:00
#### Remarks
When 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:
```bash
./etcdctl txn <<<'mod("key1") > "0"
put key1 "overwrote-key1"
put key1 "created-key1"
put key2 "this is\na multi-line\nvalue"
'
# FAILURE
# OK
# OK
```
### COMPACTION [options] \<revision\>
COMPACTION discards all etcd event history prior to a given revision. Since etcd uses a multiversion concurrency control
model, it preserves all key updates as event history. When the event history up to some revision is no longer needed,
all superseded keys may be compacted away to reclaim storage space in the etcd backend database.
RPC: Compact
#### Options
- physical -- 'true' to wait for compaction to physically remove all old revisions
#### Output
Prints the compacted revision.
#### Example
```bash
./etcdctl compaction 1234
# compacted revision 1234
```
### WATCH [options] [key or prefix] [range_end] [--] [exec-command arg1 arg2 ...]
2014-10-23 03:59:29 +04:00
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".
2014-10-23 03:59:29 +04:00
RPC: Watch
2016-06-01 21:28:43 +03:00
#### Options
- hex -- print out key and value as hex encode string
- interactive -- begins an interactive watch session
- prefix -- watch on a prefix if prefix is set.
2016-07-02 05:17:01 +03:00
- prev-kv -- get the previous key-value pair before the event happens.
2016-06-01 21:28:43 +03:00
- rev -- the revision to start watching. Specifying a revision is useful for observing past events.
#### Input format
2016-06-01 21:28:43 +03:00
Input is only accepted for interactive mode.
```
watch [options] <key or prefix>\n
2014-10-23 03:59:29 +04:00
```
#### Output
2016-06-01 21:28:43 +03:00
\<event\>[\n\<old_key\>\n\<old_value\>]\n\<key\>\n\<value\>\n\<event\>\n\<next_key\>\n\<next_value\>\n...
2016-06-01 21:28:43 +03:00
#### Examples
##### Non-interactive
2016-09-15 09:32:38 +03:00
```bash
2016-06-01 21:28:43 +03:00
./etcdctl watch foo
2016-09-09 12:49:52 +03:00
# PUT
# foo
# bar
2016-06-01 21:28:43 +03:00
```
```bash
ETCDCTL_WATCH_KEY=foo ./etcdctl watch
# PUT
# foo
# bar
```
Receive events and execute `echo watch event received`:
```bash
./etcdctl watch foo -- echo watch event received
# PUT
# foo
# bar
# watch event received
```
Watch response is set via `ETCD_WATCH_*` environmental variables:
```bash
./etcdctl watch foo -- sh -c "env | grep ETCD_WATCH_"
# PUT
# foo
# bar
# ETCD_WATCH_REVISION=11
# ETCD_WATCH_KEY="foo"
# ETCD_WATCH_EVENT_TYPE="PUT"
# ETCD_WATCH_VALUE="bar"
```
Watch with environmental variables and execute `echo watch event received`:
```bash
export ETCDCTL_WATCH_KEY=foo
./etcdctl watch -- echo watch event received
# PUT
# foo
# bar
# watch event received
```
```bash
export ETCDCTL_WATCH_KEY=foo
export ETCDCTL_WATCH_RANGE_END=foox
./etcdctl watch -- echo watch event received
# PUT
# fob
# bar
# watch event received
```
2016-06-01 21:28:43 +03:00
##### Interactive
2016-09-15 09:32:38 +03:00
```bash
2016-06-01 21:28:43 +03:00
./etcdctl watch -i
watch foo
watch foo
2016-09-09 12:49:52 +03:00
# PUT
# foo
# bar
# PUT
# foo
# bar
```
Receive events and execute `echo watch event received`:
```bash
./etcdctl watch -i
watch foo -- echo watch event received
# PUT
# foo
# bar
# watch event received
```
Watch with environmental variables and execute `echo watch event received`:
```bash
export ETCDCTL_WATCH_KEY=foo
./etcdctl watch -i
watch -- echo watch event received
# PUT
# foo
# bar
# watch event received
```
```bash
export ETCDCTL_WATCH_KEY=foo
export ETCDCTL_WATCH_RANGE_END=foox
./etcdctl watch -i
watch -- echo watch event received
# PUT
# fob
# bar
# watch event received
```
2016-06-01 21:28:43 +03:00
### LEASE \<subcommand\>
LEASE provides commands for key lease management.
### LEASE GRANT \<ttl\>
LEASE GRANT creates a fresh lease with a server-selected time-to-live in seconds
greater than or equal to the requested TTL value.
2014-10-23 03:59:29 +04:00
RPC: LeaseGrant
2016-06-01 21:28:43 +03:00
#### Output
2016-06-01 21:28:43 +03:00
Prints a message with the granted lease ID.
2016-06-01 21:28:43 +03:00
#### Example
```bash
./etcdctl lease grant 10
2016-09-09 12:49:52 +03:00
# lease 32695410dcc0ca06 granted with TTL(10s)
2014-10-23 03:59:29 +04:00
```
2016-06-01 21:28:43 +03:00
### LEASE REVOKE \<leaseID\>
LEASE REVOKE destroys a given lease, deleting all attached keys.
RPC: LeaseRevoke
2016-06-01 21:28:43 +03:00
#### Output
2014-10-23 03:59:29 +04:00
Prints a message indicating the lease is revoked.
2016-06-01 21:28:43 +03:00
#### Example
```bash
./etcdctl lease revoke 32695410dcc0ca06
2016-09-09 12:49:52 +03:00
# lease 32695410dcc0ca06 revoked
2014-10-23 03:59:29 +04:00
```
### LEASE TIMETOLIVE \<leaseID\> [options]
LEASE TIMETOLIVE retrieves the lease information with the given lease ID.
RPC: LeaseTimeToLive
#### Options
- keys -- Get keys attached to this lease
#### Output
Prints lease information.
#### Example
```bash
./etcdctl lease grant 500
2016-09-09 12:49:52 +03:00
# lease 2d8257079fa1bc0c granted with TTL(500s)
./etcdctl put foo1 bar --lease=2d8257079fa1bc0c
# OK
./etcdctl put foo2 bar --lease=2d8257079fa1bc0c
# OK
./etcdctl lease timetolive 2d8257079fa1bc0c
2016-09-09 12:49:52 +03:00
# lease 2d8257079fa1bc0c granted with TTL(500s), remaining(481s)
./etcdctl lease timetolive 2d8257079fa1bc0c --keys
2016-09-09 12:49:52 +03:00
# lease 2d8257079fa1bc0c granted with TTL(500s), remaining(472s), attached keys([foo2 foo1])
./etcdctl lease timetolive 2d8257079fa1bc0c --write-out=json
2016-09-09 12:49:52 +03:00
# {"cluster_id":17186838941855831277,"member_id":4845372305070271874,"revision":3,"raft_term":2,"id":3279279168933706764,"ttl":465,"granted-ttl":500,"keys":null}
./etcdctl lease timetolive 2d8257079fa1bc0c --write-out=json --keys
2016-09-09 12:49:52 +03:00
# {"cluster_id":17186838941855831277,"member_id":4845372305070271874,"revision":3,"raft_term":2,"id":3279279168933706764,"ttl":459,"granted-ttl":500,"keys":["Zm9vMQ==","Zm9vMg=="]}
./etcdctl lease timetolive 2d8257079fa1bc0c
# lease 2d8257079fa1bc0c already expired
```
### LEASE LIST
LEASE LIST lists all active leases.
RPC: LeaseLeases
#### Output
Prints a message with a list of active leases.
#### Example
```bash
./etcdctl lease grant 10
# lease 32695410dcc0ca06 granted with TTL(10s)
./etcdctl lease list
32695410dcc0ca06
```
2016-06-01 21:28:43 +03:00
### LEASE KEEP-ALIVE \<leaseID\>
LEASE KEEP-ALIVE periodically refreshes a lease so it does not expire.
RPC: LeaseKeepAlive
2014-10-23 03:59:29 +04:00
#### Output
2016-06-01 21:28:43 +03:00
Prints a message for every keep alive sent or prints a message indicating the lease is gone.
2016-06-01 21:28:43 +03:00
#### Example
```bash
2016-09-09 12:49:52 +03:00
./etcdctl lease keep-alive 32695410dcc0ca0
# lease 32695410dcc0ca0 keepalived with TTL(100)
# lease 32695410dcc0ca0 keepalived with TTL(100)
# lease 32695410dcc0ca0 keepalived with TTL(100)
2016-06-01 21:28:43 +03:00
...
2014-10-23 03:59:29 +04:00
```
## Cluster maintenance commands
2014-10-23 03:59:29 +04:00
2016-06-01 21:28:43 +03:00
### MEMBER \<subcommand\>
MEMBER provides commands for managing etcd cluster membership.
### MEMBER ADD \<memberName\> [options]
2014-10-23 03:59:29 +04:00
2016-06-01 21:28:43 +03:00
MEMBER ADD introduces a new member into the etcd cluster as a new peer.
2014-10-23 03:59:29 +04:00
RPC: MemberAdd
2016-06-01 21:28:43 +03:00
#### Options
- peer-urls -- comma separated list of URLs to associate with the new member.
2016-06-01 21:28:43 +03:00
#### Output
2016-06-01 21:28:43 +03:00
Prints the member ID of the new member and the cluster ID.
2016-06-01 21:28:43 +03:00
#### Example
```bash
./etcdctl member add newMember --peer-urls=https://127.0.0.1:12345
Member ced000fda4d05edf added to cluster 8c4281cc65c7b112
ETCD_NAME="newMember"
ETCD_INITIAL_CLUSTER="newMember=https://127.0.0.1:12345,default=http://10.0.0.30:2380"
ETCD_INITIAL_CLUSTER_STATE="existing"
2014-10-23 03:59:29 +04:00
```
### MEMBER UPDATE \<memberID\> [options]
2016-06-01 21:28:43 +03:00
MEMBER UPDATE sets the peer URLs for an existing member in the etcd cluster.
2014-10-23 03:59:29 +04:00
RPC: MemberUpdate
2016-06-01 21:28:43 +03:00
#### Options
- peer-urls -- comma separated list of URLs to associate with the updated member.
2016-06-01 21:28:43 +03:00
#### Output
2016-06-01 21:28:43 +03:00
Prints the member ID of the updated member and the cluster ID.
2016-06-01 21:28:43 +03:00
#### Example
```bash
./etcdctl member update 2be1eb8f84b7f63e --peer-urls=https://127.0.0.1:11112
2016-09-09 12:49:52 +03:00
# Member 2be1eb8f84b7f63e updated in cluster ef37ad9dc622a7c4
2014-10-23 03:59:29 +04:00
```
2016-06-01 21:28:43 +03:00
### MEMBER REMOVE \<memberID\>
MEMBER REMOVE removes a member of an etcd cluster from participating in cluster consensus.
2014-10-23 03:59:29 +04:00
RPC: MemberRemove
2016-06-01 21:28:43 +03:00
#### Output
2016-06-01 21:28:43 +03:00
Prints the member ID of the removed member and the cluster ID.
2016-06-01 21:28:43 +03:00
#### Example
```bash
./etcdctl member remove 2be1eb8f84b7f63e
2016-09-09 12:49:52 +03:00
# Member 2be1eb8f84b7f63e removed from cluster ef37ad9dc622a7c4
2014-10-23 03:59:29 +04:00
```
2016-06-01 21:28:43 +03:00
### MEMBER LIST
MEMBER LIST prints the member details for all members associated with an etcd cluster.
RPC: MemberList
2016-06-01 21:28:43 +03:00
#### Output
2016-06-01 21:28:43 +03:00
Prints a humanized table of the member IDs, statuses, names, peer addresses, and client addresses.
2016-06-01 21:28:43 +03:00
#### Examples
```bash
./etcdctl member list
2016-09-09 12:49:52 +03:00
# 8211f1d0f64f3269, started, infra1, http://127.0.0.1:12380, http://127.0.0.1:2379
# 91bc3c398fb3c146, started, infra2, http://127.0.0.1:22380, http://127.0.0.1:22379
# fd422379fda50e48, started, infra3, http://127.0.0.1:32380, http://127.0.0.1:32379
2014-10-23 03:59:29 +04:00
```
2016-06-01 21:28:43 +03:00
```bash
./etcdctl -w json member list
2016-09-09 12:49:52 +03:00
# {"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"]}]}
2016-06-01 21:28:43 +03:00
```
2016-06-01 21:28:43 +03:00
```bash
./etcdctl -w table member list
+------------------+---------+--------+------------------------+------------------------+
| ID | STATUS | NAME | PEER ADDRS | CLIENT ADDRS |
+------------------+---------+--------+------------------------+------------------------+
| 8211f1d0f64f3269 | started | infra1 | http://127.0.0.1:12380 | http://127.0.0.1:2379 |
| 91bc3c398fb3c146 | started | infra2 | http://127.0.0.1:22380 | http://127.0.0.1:22379 |
| fd422379fda50e48 | started | infra3 | http://127.0.0.1:32380 | http://127.0.0.1:32379 |
+------------------+---------+--------+------------------------+------------------------+
```
2014-10-23 03:59:29 +04:00
2016-06-01 21:28:43 +03:00
### ENDPOINT \<subcommand\>
2014-10-23 03:59:29 +04:00
2016-06-01 21:28:43 +03:00
ENDPOINT provides commands for querying individual endpoints.
2014-10-23 03:59:29 +04:00
#### Options
- cluster -- fetch and use all endpoints from the etcd cluster member list
2016-06-01 21:28:43 +03:00
### ENDPOINT HEALTH
ENDPOINT HEALTH checks the health of the list of endpoints with respect to cluster. An endpoint is unhealthy
when it cannot participate in consensus with the rest of the cluster.
#### Output
2016-06-01 21:28:43 +03:00
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.
2016-06-01 21:28:43 +03:00
#### Example
Check the default endpoint's health:
2016-06-01 21:28:43 +03:00
```bash
./etcdctl endpoint health
2016-09-09 12:49:52 +03:00
# 127.0.0.1:2379 is healthy: successfully committed proposal: took = 2.095242ms
```
Check all endpoints for the cluster associated with the default endpoint:
```bash
./etcdctl endpoint --cluster health
# http://127.0.0.1:2379 is healthy: successfully committed proposal: took = 1.060091ms
# http://127.0.0.1:22379 is healthy: successfully committed proposal: took = 903.138µs
# http://127.0.0.1:32379 is healthy: successfully committed proposal: took = 1.113848ms
2014-10-23 03:59:29 +04:00
```
2016-06-01 21:28:43 +03:00
### ENDPOINT STATUS
ENDPOINT STATUS queries the status of each endpoint in the given endpoint list.
2014-10-23 03:59:29 +04:00
#### Output
2016-06-01 21:28:43 +03:00
##### Simple format
2016-06-01 21:28:43 +03:00
Prints a humanized table of each endpoint URL, ID, version, database size, leadership status, raft term, and raft status.
2016-06-01 21:28:43 +03:00
##### JSON format
2016-06-01 21:28:43 +03:00
Prints a line of JSON encoding each endpoint URL, ID, version, database size, leadership status, raft term, and raft status.
2016-06-01 21:28:43 +03:00
#### Examples
Get the status for the default endpoint:
2016-06-01 21:28:43 +03:00
```bash
./etcdctl endpoint status
2016-09-09 12:49:52 +03:00
# 127.0.0.1:2379, 8211f1d0f64f3269, 3.0.0, 25 kB, false, 2, 63
2014-10-23 03:59:29 +04:00
```
Get the status for the default endpoint as JSON:
2016-06-01 21:28:43 +03:00
```bash
./etcdctl -w json endpoint status
# [{"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}}]
2016-06-01 21:28:43 +03:00
```
2014-10-23 03:59:29 +04:00
Get the status for all endpoints in the cluster associated with the default endpoint:
2016-06-01 21:28:43 +03:00
```bash
./etcdctl -w table endpoint --cluster status
+------------------------+------------------+----------------+---------+-----------+-----------+------------+
| ENDPOINT | ID | VERSION | DB SIZE | IS LEADER | RAFT TERM | RAFT INDEX |
+------------------------+------------------+----------------+---------+-----------+-----------+------------+
| http://127.0.0.1:2379 | 8211f1d0f64f3269 | 3.2.0-rc.1+git | 25 kB | false | 2 | 8 |
| http://127.0.0.1:22379 | 91bc3c398fb3c146 | 3.2.0-rc.1+git | 25 kB | false | 2 | 8 |
| http://127.0.0.1:32379 | fd422379fda50e48 | 3.2.0-rc.1+git | 25 kB | true | 2 | 8 |
+------------------------+------------------+----------------+---------+-----------+-----------+------------+
2014-10-23 03:59:29 +04:00
```
### ENDPOINT HASHKV
ENDPOINT HASHKV fetches the hash of the key-value store of an endpoint.
#### Output
##### Simple format
Prints a humanized table of each endpoint URL and KV history hash.
##### JSON format
Prints a line of JSON encoding each endpoint URL and KV history hash.
#### Examples
Get the hash for the default endpoint:
```bash
./etcdctl endpoint hashkv
# 127.0.0.1:2379, 1084519789
```
Get the status for the default endpoint as JSON:
```bash
./etcdctl -w json endpoint hashkv
# [{"Endpoint":"127.0.0.1:2379","Hash":{"header":{"cluster_id":14841639068965178418,"member_id":10276657743932975437,"revision":1,"raft_term":3},"hash":1084519789,"compact_revision":-1}}]
```
Get the status for all endpoints in the cluster associated with the default endpoint:
```bash
./etcdctl -w table endpoint --cluster hashkv
+------------------------+------------+
| ENDPOINT | HASH |
+------------------------+------------+
| http://127.0.0.1:2379 | 1084519789 |
| http://127.0.0.1:22379 | 1084519789 |
| http://127.0.0.1:32379 | 1084519789 |
+------------------------+------------+
```
### ALARM \<subcommand\>
2016-06-01 21:28:43 +03:00
Provides alarm related commands
2016-06-01 21:28:43 +03:00
### ALARM DISARM
2016-06-01 21:28:43 +03:00
`alarm disarm` Disarms all alarms
2016-06-01 21:28:43 +03:00
RPC: Alarm
2016-06-01 21:28:43 +03:00
#### Output
2016-06-01 21:28:43 +03:00
`alarm:<alarm type>` if alarm is present and disarmed.
2016-06-01 21:28:43 +03:00
#### Examples
2016-06-01 21:28:43 +03:00
```bash
./etcdctl alarm disarm
2014-10-23 03:59:29 +04:00
```
If NOSPACE alarm is present:
2016-06-01 21:28:43 +03:00
```bash
./etcdctl alarm disarm
# alarm:NOSPACE
```
2016-06-01 21:28:43 +03:00
### ALARM LIST
2016-06-01 21:28:43 +03:00
`alarm list` lists all alarms.
2014-10-23 03:59:29 +04:00
RPC: Alarm
2016-06-01 21:28:43 +03:00
#### Output
2016-09-22 15:49:13 +03:00
`alarm:<alarm type>` if alarm is present, empty string if no alarms present.
2016-09-22 15:49:13 +03:00
#### Examples
2016-06-01 21:28:43 +03:00
```bash
./etcdctl alarm list
```
2016-06-01 21:28:43 +03:00
If NOSPACE alarm is present:
2016-06-01 21:28:43 +03:00
```bash
./etcdctl alarm list
# alarm:NOSPACE
2014-10-23 03:59:29 +04:00
```
### DEFRAG [options]
2016-06-01 21:28:43 +03:00
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.
**Note that defragmentation to a live member blocks the system from reading and writing data while rebuilding its states.**
**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.**
#### Options
- data-dir -- Optional. If present, defragments a data directory not in use by etcd.
2016-06-01 21:28:43 +03:00
#### Output
2014-10-23 03:59:29 +04:00
For each endpoints, prints a message indicating whether the endpoint was successfully defragmented.
2016-06-01 21:28:43 +03:00
#### Example
2016-06-01 21:28:43 +03:00
```bash
./etcdctl --endpoints=localhost:2379,badendpoint:2379 defrag
2016-09-09 12:49:52 +03:00
# Finished defragmenting etcd member[localhost:2379]
# Failed to defragment etcd member[badendpoint:2379] (grpc: timed out trying to connect)
2014-10-23 03:59:29 +04:00
```
Run defragment operations for all endpoints in the cluster associated with the default endpoint:
```bash
./etcdctl defrag --cluster
Finished defragmenting etcd member[http://127.0.0.1:2379]
Finished defragmenting etcd member[http://127.0.0.1:22379]
Finished defragmenting etcd member[http://127.0.0.1:32379]
```
To defragment a data directory directly, use the `--data-dir` flag:
``` bash
# Defragment while etcd is not running
./etcdctl defrag --data-dir default.etcd
# success (exit status 0)
# Error: cannot open database at default.etcd/member/snap/db
```
#### Remarks
2014-10-23 03:59:29 +04:00
DEFRAG returns a zero exit code only if it succeeded defragmenting all given endpoints.
2016-06-01 21:28:43 +03:00
### SNAPSHOT \<subcommand\>
SNAPSHOT provides commands to restore a snapshot of a running etcd server into a fresh cluster.
### SNAPSHOT SAVE \<filename\>
SNAPSHOT SAVE writes a point-in-time snapshot of the etcd backend database to a file.
#### Output
2014-10-23 03:59:29 +04:00
The backend snapshot is written to the given file path.
2014-10-23 03:59:29 +04:00
2016-06-01 21:28:43 +03:00
#### Example
Save a snapshot to "snapshot.db":
```
./etcdctl snapshot save snapshot.db
2014-10-23 03:59:29 +04:00
```
2016-06-01 21:28:43 +03:00
### SNAPSHOT RESTORE [options] \<filename\>
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.
#### Options
The snapshot restore options closely resemble to those used in the `etcd` command for defining a cluster.
- data-dir -- Path to the data directory. Uses \<name\>.etcd if none given.
- wal-dir -- Path to the WAL directory. Uses data directory if none given.
2016-06-01 21:28:43 +03:00
- initial-cluster -- The initial cluster configuration for the restored etcd cluster.
- initial-cluster-token -- Initial cluster token for the restored etcd cluster.
- initial-advertise-peer-urls -- List of peer URLs for the member being restored.
- name -- Human-readable name for the etcd cluster member being restored.
- skip-hash-check -- Ignore snapshot integrity hash value (required if copied from data directory)
#### Output
2016-06-01 21:28:43 +03:00
A new etcd data directory initialized with the snapshot.
2016-06-01 21:28:43 +03:00
#### Example
Save a snapshot, restore into a new 3 node cluster, and start the cluster:
2014-10-23 03:59:29 +04:00
```
2016-06-01 21:28:43 +03:00
./etcdctl snapshot save snapshot.db
# restore members
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'
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'
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'
2014-10-23 03:59:29 +04:00
2016-06-01 21:28:43 +03:00
# launch members
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 &
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 &
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 &
2014-10-23 03:59:29 +04:00
```
2016-06-01 21:28:43 +03:00
### SNAPSHOT STATUS \<filename\>
SNAPSHOT STATUS lists information about a given backend database snapshot file.
#### Output
2016-06-01 21:28:43 +03:00
##### Simple format
2016-06-01 21:28:43 +03:00
Prints a humanized table of the database hash, revision, total keys, and size.
2016-06-01 21:28:43 +03:00
##### JSON format
2014-10-23 03:59:29 +04:00
Prints a line of JSON encoding the database hash, revision, total keys, and size.
2016-06-01 21:28:43 +03:00
#### Examples
```bash
./etcdctl snapshot status file.db
2016-09-09 12:49:52 +03:00
# cf1550fb, 3, 3, 25 kB
2014-10-23 03:59:29 +04:00
```
2016-06-01 21:28:43 +03:00
```bash
./etcdctl -write-out=json snapshot status file.db
2016-09-09 12:49:52 +03:00
# {"hash":3474280699,"revision":3,"totalKey":3,"totalSize":24576}
2014-10-23 03:59:29 +04:00
```
2016-06-01 21:28:43 +03:00
```bash
./etcdctl -write-out=table snapshot status file.db
+----------+----------+------------+------------+
| HASH | REVISION | TOTAL KEYS | TOTAL SIZE |
+----------+----------+------------+------------+
| cf1550fb | 3 | 3 | 25 kB |
+----------+----------+------------+------------+
```
2014-10-23 03:59:29 +04:00
### MOVE-LEADER \<hexadecimal-transferee-id\>
MOVE-LEADER transfers leadership from the leader to another member in the cluster.
#### Example
```bash
# to choose transferee
transferee_id=$(./etcdctl \
--endpoints localhost:2379,localhost:22379,localhost:32379 \
endpoint status | grep -m 1 "false" | awk -F', ' '{print $2}')
echo ${transferee_id}
# c89feb932daef420
# endpoints should include leader node
./etcdctl --endpoints ${transferee_ep} move-leader ${transferee_id}
# Error: no leader endpoint given at [localhost:22379 localhost:32379]
# request to leader with target node ID
./etcdctl --endpoints ${leader_ep} move-leader ${transferee_id}
# Leadership transferred from 45ddc0e800e20b93 to c89feb932daef420
```
## Concurrency commands
2014-10-23 03:59:29 +04:00
2017-08-05 08:06:46 +03:00
### LOCK [options] \<lockname\> [command arg1 arg2 ...]
2016-06-01 21:28:43 +03:00
LOCK acquires a distributed mutex with a given name. Once the lock is acquired, it will be held until etcdctl is terminated.
2016-06-01 21:28:43 +03:00
2017-08-05 08:06:46 +03:00
#### Options
- ttl - time out in seconds of lock session.
#### Output
2016-06-01 21:28:43 +03:00
Once the lock is acquired but no command is given, the result for the GET on the unique lock holder key is displayed.
2014-10-23 03:59:29 +04:00
If 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.
#### Example
Acquire lock with standard output display:
```bash
./etcdctl lock mylock
# mylock/1234534535445
```
Acquire lock and execute `echo lock acquired`:
```bash
./etcdctl lock mylock echo lock acquired
# lock acquired
```
Acquire lock and execute `etcdctl put` command
```bash
./etcdctl lock mylock ./etcdctl put foo bar
# OK
```
#### Remarks
LOCK returns a zero exit code only if it is terminated by a signal and releases the lock.
2016-06-01 21:28:43 +03:00
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.
2016-06-01 21:28:43 +03:00
### ELECT [options] \<election-name\> [proposal]
2016-06-01 21:28:43 +03:00
ELECT participates on a named election. A node announces its candidacy in the election by providing
a proposal value. If a node wishes to observe the election, ELECT listens for new leaders values.
Whenever a leader is elected, its proposal is given as output.
2016-06-01 21:28:43 +03:00
#### Options
2016-06-01 21:28:43 +03:00
- listen -- observe the election.
#### Output
2016-06-01 21:28:43 +03:00
- If a candidate, ELECT displays the GET on the leader key once the node is elected election.
2016-06-01 21:28:43 +03:00
- If observing, ELECT streams the result for a GET on the leader key for the current election and all future elections.
2016-06-01 21:28:43 +03:00
#### Example
```bash
./etcdctl elect myelection foo
# myelection/1456952310051373265
# foo
```
#### Remarks
ELECT returns a zero exit code only if it is terminated by a signal and can revoke its candidacy or leadership, if any.
If a candidate is abnormally terminated, election rogress may be delayed by up to the default lease length of 60 seconds.
## Authentication commands
### AUTH \<enable or disable\>
`auth enable` activates authentication on an etcd cluster and `auth disable` deactivates. When authentication is enabled, etcd checks all requests for appropriate authorization.
RPC: AuthEnable/AuthDisable
#### Output
`Authentication Enabled`.
#### Examples
```bash
./etcdctl user add root
# Password of root:#type password for root
# Type password of root again for confirmation:#re-type password for root
# User root created
./etcdctl user grant-role root root
# Role root is granted to user root
./etcdctl user get root
# User: root
# Roles: root
./etcdctl role add root
# Role root created
./etcdctl role get root
# Role root
# KV Read:
# KV Write:
./etcdctl auth enable
# Authentication Enabled
2016-06-01 21:28:43 +03:00
```
### ROLE \<subcommand\>
2016-06-21 20:52:51 +03:00
2018-03-07 18:32:07 +03:00
ROLE is used to specify different roles which can be assigned to etcd user(s).
2016-06-21 20:52:51 +03:00
### ROLE ADD \<role name\>
`role add` creates a role.
RPC: RoleAdd
2016-06-21 20:52:51 +03:00
#### Output
2016-06-21 20:52:51 +03:00
`Role <role name> created`.
2016-06-21 20:52:51 +03:00
#### Examples
2016-09-15 09:32:38 +03:00
```bash
2016-09-09 12:49:52 +03:00
./etcdctl --user=root:123 role add myrole
# Role myrole created
2016-06-21 20:52:51 +03:00
```
### ROLE GET \<role name\>
`role get` lists detailed role information.
RPC: RoleGet
2016-06-21 20:52:51 +03:00
#### Output
2016-06-21 20:52:51 +03:00
Detailed role information.
2016-06-21 20:52:51 +03:00
#### Examples
2016-09-15 09:32:38 +03:00
```bash
2016-09-09 12:49:52 +03:00
./etcdctl --user=root:123 role get myrole
2016-06-21 20:52:51 +03:00
# Role myrole
# KV Read:
2016-09-09 12:49:52 +03:00
# foo
2016-06-21 20:52:51 +03:00
# KV Write:
2016-09-09 12:49:52 +03:00
# foo
2016-06-21 20:52:51 +03:00
```
### ROLE DELETE \<role name\>
2016-06-21 20:52:51 +03:00
`role delete` deletes a role.
2016-06-21 20:52:51 +03:00
RPC: RoleDelete
#### Output
`Role <role name> deleted`.
#### Examples
```bash
./etcdctl --user=root:123 role delete myrole
# Role myrole deleted
```
2016-06-21 20:52:51 +03:00
### ROLE LIST \<role name\>
2016-06-21 20:52:51 +03:00
`role list` lists all roles in etcd.
2016-06-21 20:52:51 +03:00
RPC: RoleList
#### Output
A role per line.
2016-06-21 20:52:51 +03:00
#### Examples
2016-09-15 09:32:38 +03:00
```bash
./etcdctl --user=root:123 role list
# roleA
# roleB
# myrole
2016-06-21 20:52:51 +03:00
```
### ROLE GRANT-PERMISSION [options] \<role name\> \<permission type\> \<key\> [endkey]
2016-06-21 20:52:51 +03:00
`role grant-permission` grants a key to a role.
RPC: RoleGrantPermission
2016-06-21 20:52:51 +03:00
#### Options
2016-06-21 20:52:51 +03:00
- from-key -- grant a permission of keys that are greater than or equal to the given key using byte compare
- prefix -- grant a prefix permission
2016-06-21 20:52:51 +03:00
#### Output
2016-06-21 20:52:51 +03:00
`Role <role name> updated`.
2016-06-21 20:52:51 +03:00
#### Examples
Grant read and write permission on the key `foo` to role `myrole`:
2016-09-15 09:32:38 +03:00
```bash
./etcdctl --user=root:123 role grant-permission myrole readwrite foo
# Role myrole updated
2016-06-21 20:52:51 +03:00
```
Grant read permission on the wildcard key pattern `foo/*` to role `myrole`:
```bash
./etcdctl --user=root:123 role grant-permission --prefix myrole readwrite foo/
# Role myrole updated
```
### ROLE REVOKE-PERMISSION \<role name\> \<permission type\> \<key\> [endkey]
2016-06-21 20:52:51 +03:00
`role revoke-permission` revokes a key from a role.
2016-06-21 20:52:51 +03:00
RPC: RoleRevokePermission
2016-06-21 20:52:51 +03:00
#### Options
- from-key -- revoke a permission of keys that are greater than or equal to the given key using byte compare
- prefix -- revoke a prefix permission
#### Output
2016-06-21 20:52:51 +03:00
`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.
2016-06-21 20:52:51 +03:00
#### Examples
2016-09-15 09:32:38 +03:00
```bash
./etcdctl --user=root:123 role revoke-permission myrole foo
# Permission of key foo is revoked from role myrole
2016-06-21 20:52:51 +03:00
```
### USER \<subcommand\>
2016-06-21 20:52:51 +03:00
USER provides commands for managing users of etcd.
### USER ADD \<user name or user:password\> [options]
`user add` creates a user.
RPC: UserAdd
#### Options
- interactive -- Read password from stdin instead of interactive terminal
2016-06-21 20:52:51 +03:00
#### Output
2016-06-21 20:52:51 +03:00
`User <user name> created`.
2016-06-21 20:52:51 +03:00
#### Examples
2016-09-15 09:32:38 +03:00
```bash
./etcdctl --user=root:123 user add myuser
# Password of myuser: #type password for my user
# Type password of myuser again for confirmation:#re-type password for my user
# User myuser created
2016-06-21 20:52:51 +03:00
```
### USER GET \<user name\> [options]
2016-06-21 20:52:51 +03:00
`user get` lists detailed user information.
RPC: UserGet
#### Options
- detail -- Show permissions of roles granted to the user
#### Output
2016-06-21 20:52:51 +03:00
Detailed user information.
2016-06-21 20:52:51 +03:00
#### Examples
2016-09-15 09:32:38 +03:00
```bash
2016-09-09 12:49:52 +03:00
./etcdctl --user=root:123 user get myuser
2016-06-21 20:52:51 +03:00
# User: myuser
# Roles:
```
### USER DELETE \<user name\>
`user delete` deletes a user.
RPC: UserDelete
#### Output
`User <user name> deleted`.
#### Examples
```bash
./etcdctl --user=root:123 user delete myuser
# User myuser deleted
```
### USER LIST
`user list` lists detailed user information.
RPC: UserList
#### Output
- List of users, one per line.
#### Examples
```bash
./etcdctl --user=root:123 user list
# user1
# user2
# myuser
```
### USER PASSWD \<user name\> [options]
2016-06-21 20:52:51 +03:00
`user passwd` changes a user's password.
RPC: UserChangePassword
2016-06-21 20:52:51 +03:00
#### Options
- interactive -- if true, read password in interactive terminal
#### Output
2016-06-21 20:52:51 +03:00
`Password updated`.
2016-06-21 20:52:51 +03:00
#### Examples
2016-09-15 09:32:38 +03:00
```bash
2016-09-09 12:49:52 +03:00
./etcdctl --user=root:123 user passwd myuser
# Password of myuser: #type new password for my user
# Type password of myuser again for confirmation: #re-type the new password for my user
2016-06-21 20:52:51 +03:00
# Password updated
```
### USER GRANT-ROLE \<user name\> \<role name\>
`user grant-role` grants a role to a user
RPC: UserGrantRole
2016-06-21 20:52:51 +03:00
#### Output
2016-06-21 20:52:51 +03:00
`Role <role name> is granted to user <user name>`.
2016-06-21 20:52:51 +03:00
#### Examples
2016-09-15 09:32:38 +03:00
```bash
2016-09-09 12:49:52 +03:00
./etcdctl --user=root:123 user grant-role userA roleA
2016-06-21 20:52:51 +03:00
# Role roleA is granted to user userA
```
### USER REVOKE-ROLE \<user name\> \<role name\>
`user revoke-role` revokes a role from a user
RPC: UserRevokeRole
2016-06-21 20:52:51 +03:00
#### Output
2016-06-21 20:52:51 +03:00
`Role <role name> is revoked from user <user name>`.
2016-06-21 20:52:51 +03:00
#### Examples
2016-09-15 09:32:38 +03:00
```bash
2016-09-09 12:49:52 +03:00
./etcdctl --user=root:123 user revoke-role userA roleA
2016-06-21 20:52:51 +03:00
# Role roleA is revoked from user userA
```
## Utility commands
### MAKE-MIRROR [options] \<destination\>
[make-mirror][mirror] mirrors a key prefix in an etcd cluster to a destination etcd cluster.
#### Options
- dest-cacert -- TLS certificate authority file for destination cluster
- dest-cert -- TLS certificate file for destination cluster
- dest-key -- TLS key file for destination cluster
- prefix -- The key-value prefix to mirror
- dest-prefix -- The destination prefix to mirror a prefix to a different prefix in the destination cluster
- no-dest-prefix -- Mirror key-values to the root of the destination cluster
- dest-insecure-transport -- Disable transport security for client connections
#### Output
The approximate total number of keys transferred to the destination cluster, updated every 30 seconds.
#### Examples
```
./etcdctl make-mirror mirror.example.com:2379
# 10
# 18
```
[mirror]: ./doc/mirror_maker.md
### MIGRATE [options]
Migrates keys in a v2 store to a v3 mvcc store. Users should run migration command for all members in the cluster.
#### Options
- data-dir -- Path to the data directory
- wal-dir -- Path to the WAL directory
- transformer -- Path to the user-provided transformer program (default if not provided)
#### Output
No output on success.
#### Default transformer
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:
```go
func transform(n *storev2.Node) *mvccpb.KeyValue {
if n.Dir {
return nil
}
kv := &mvccpb.KeyValue{
Key: []byte(n.Key),
Value: []byte(n.Value),
CreateRevision: int64(n.CreatedIndex),
ModRevision: int64(n.ModifiedIndex),
Version: 1,
}
return kv
}
```
#### User-provided transformer
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.
The provided transformer should read until EOF and flush the stdout before exiting to ensure data integrity.
#### Example
```
./etcdctl migrate --data-dir=/var/etcd --transformer=k8s-transformer
# finished transforming keys
```
### VERSION
Prints the version of etcdctl.
#### Output
Prints etcd version and API version.
#### Examples
```bash
./etcdctl version
# etcdctl version: 3.1.0-alpha.0+git
# API version: 3.1
```
### CHECK \<subcommand\>
CHECK provides commands for checking properties of the etcd cluster.
### CHECK PERF [options]
CHECK 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.
RPC: CheckPerf
#### Options
- load -- the performance check's workload model. Accepted workloads: s(small), m(medium), l(large), xl(xLarge)
- prefix -- the prefix for writing the performance check's keys.
- auto-compact -- if true, compact storage with last revision after test is finished.
- auto-defrag -- if true, defragment storage after test is finished.
#### Output
Prints the result of performance check on different criteria like throughput. Also prints an overall status of the check as pass or fail.
#### Examples
Shows 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.
```bash
./etcdctl check perf --load="s"
# 60 / 60 Booooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo! 100.00%1m0s
# PASS: Throughput is 150 writes/s
# PASS: Slowest request took 0.087509s
# PASS: Stddev is 0.011084s
# PASS
./etcdctl check perf --load="l"
# 60 / 60 Booooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo! 100.00%1m0s
# FAIL: Throughput too low: 6808 writes/s
# PASS: Slowest request took 0.228191s
# PASS: Stddev is 0.033547s
# FAIL
```
### CHECK DATASCALE [options]
CHECK 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.
RPC: CheckDatascale
#### Options
- load -- the datascale check's workload model. Accepted workloads: s(small), m(medium), l(large), xl(xLarge)
- prefix -- the prefix for writing the datascale check's keys.
- auto-compact -- if true, compact storage with last revision after test is finished.
- auto-defrag -- if true, defragment storage after test is finished.
#### Output
Prints the system memory usage for a given workload. Also prints status of compact and defragment if related options are passed.
#### Examples
```bash
./etcdctl check datascale --load="s" --auto-compact=true --auto-defrag=true
# Start data scale check for work load [10000 key-value pairs, 1024 bytes per key-value, 50 concurrent clients].
# Compacting with revision 18346204
# Compacted with revision 18346204
# Defragmenting "127.0.0.1:2379"
# Defragmented "127.0.0.1:2379"
# PASS: Approximate system memory used : 64.30 MB.
```
## Exit codes
For all commands, a successful execution return a zero exit code. All failures will return non-zero exit codes.
## Output formats
2016-06-01 21:28:43 +03:00
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.
2016-06-01 21:28:43 +03:00
If a command fails, returning a non-zero exit code, an error string will be written to standard error regardless of output format.
### Simple
A format meant to be easy to parse and human-readable. Specific to each command.
### JSON
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.
Some commands without an RPC also support JSON; see the command's `Output` description.
### Protobuf
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.
### Fields
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"`).
2016-06-01 21:28:43 +03:00
## Compatibility Support
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.
2016-06-01 21:28:43 +03:00
### Input Compatibility
2014-10-23 03:59:29 +04:00
2016-06-01 21:28:43 +03:00
Input includes the command name, its flags, and its arguments. We ensure backward compatibility of the input of normal commands in non-interactive mode.
2014-10-23 03:59:29 +04:00
2016-06-01 21:28:43 +03:00
### Output Compatibility
2014-10-23 03:59:29 +04:00
2016-06-01 21:28:43 +03:00
Output includes output from etcdctl and its exit code. etcdctl provides `simple` output format by default.
We ensure compatibility for the `simple` output format of normal commands in non-interactive mode. Currently, we do not ensure
backward compatibility for `JSON` format and the format in non-interactive mode. Currently, we do not ensure backward compatibility of utility commands.
2014-10-23 03:59:29 +04:00
2016-06-01 21:28:43 +03:00
### TODO: compatibility with etcd server
2014-10-23 03:59:29 +04:00
[etcd]: https://github.com/coreos/etcd
2016-06-01 21:28:43 +03:00
[READMEv2]: READMEv2.md
[v2key]: ../store/node_extern.go#L28-L37
[v3key]: ../mvcc/mvccpb/kv.proto#L12-L29
[etcdrpc]: ../etcdserver/etcdserverpb/rpc.proto
[storagerpc]: ../mvcc/mvccpb/kv.proto