gauc 0.3.0

Couchbase Rust Adapter / CLI
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
# cbc(1) - Couchbase Client Commandline Utility

## SYNOPSIS

`cbc` _COMMAND_ [_OPTIONS_]<br>
`cbc help`<br>
`cbc version`<br>
`cbc cat` _KEYS_ ... [_OPTIONS_]<br>
`cbc create` _KEY_ _-V VALUE_ [_OPTIONS_]<br>
`cbc create` _KEY_ [_OPTIONS_]<br>
`cbc cp` _FILES_ ... [_OPTIONS_]<br>
`cbc incr` _KEY_ [_OPTIONS_]<br>
`cbc decr` _KEY_ [_OPTIONS_]<br>
`cbc rm` _KEY_ [_OPTIONS_]<br>
`cbc hash` _KEY_ [_OPTIONS_]<br>
`cbc stats` _KEYS_ ... [_OPTIONS_]<br>
`cbc observe` _KEYS_ ... [_OPTIONS_]<br>
`cbc view` _VIEWPATH_ [_OPTIONS_]<br>
`cbc lock` _KEY_ [_OPTIONS_]<br>
`cbc unlock` _KEY_ _CAS_ [_OPTIONS_]<br>
`cbc admin` _-P PASSWORD_ _RESTAPI_ [_OPTIONS_]<br>
`cbc bucket-create` _-P PASSWORD_ _NAME_ [_OPTIONS_]<br>
`cbc bucket-delete` _-P PASSWORD_ _NAME_ [_OPTIONS_]<br>
`cbc bucket-flush` _NAME_ [_OPTIONS_]<br>
`cbc connstr` _SPEC_<br>
`cbc n1ql` _QUERY_ ... [_OPTIONS_]<br>

## DESCRIPTION

`cbc` is a utility for communicating with a Couchbase cluster.

`cbc` should be invoked with the command name first and then a series of command
options appropriate for the specific command. `cbc help` will always show the full
list of available commands.

<a name="OPTIONS"></a>
## OPTIONS

Options may be read either from the command line, or from a configuration file
(see cbcrc(4)):

The following common options may be applied to most of the commands

* `-U`, `--spec`=_SPEC_:
  A string describing the cluster to connect to. The string is in a URI-like syntax,
  and may also contain other options. See the [EXAMPLES]#examples section for information.
  Typically such a URI will look like `couchbase://host1,host2,host3/bucket`.

  The default for this option is `couchbase://localhost/default`

* `-u`, `--username`=_USERNAME_:
  Specify the _username_ for the bucket. As of Couchbase Server 2.5 this field
  should be either left empty or set to the name of the bucket itself.

* `-P`, `--password`=_SASLPASS_:
* `-P -`, `--password=-`:
  Specify the SASL password for the bucket. This is only needed if the bucket is
  protected with a password. Note that this is _not_ the administrative password
  used to log into the web interface.

  Specifying the `-` as the password indicates that the program should prompt for the
  password. You may also specify the password on the commandline, directly, 
  but is insecure as command line arguments are visible via commands such as `ps`.

* `-T`, `--timings`:
  Dump command timings at the end of execution. This will display a histogram
  showing the latencies for the commands executed.

* `-v`, `--verbose`:
  Specify more information to standard error about what the client is doing. You may
  specify this option multiple times for increased output detail.

* `-D`, `--cparam`=OPTION=VALUE:
  Provide additional client options. Acceptable options can also be placed
  in the connection string, however this option is provided as a convenience.
  This option may be specified multiple times, each time specifying a key=value
  pair (for example, `-Doperation_timeout=10 -Dconfig_cache=/foo/bar/baz`).
  See [ADDITIONAL OPTIONS]#additional-options for more information


<a name="additional-options"></a>
## ADDITIONAL OPTIONS

The following options may be included in the connection string (via the `-U`
option) as URI-style query params (e.g.
`couchbase://host/bucket?option1=value1&option2=value2`) or as individual
key=value pairs passed to the `-D` switch (e.g. `-Doption1=value1
-Doption2=value`). The `-D` will internally build the connection string,
and is provided as a convenience for options to be easily passed on the
command-line

* `operation_timeout=SECONDS`:
  Specify the operation timeout in seconds. This is the time the client will
  wait for an operation to complete before timing it out. The default is `2.5`
* `config_cache=PATH`:
  Enables the client to make use of a file based configuration cache rather
  than connecting for the bootstrap operation. If the file does not exist, the
  client will first connect to the cluster and then cache the bootstrap information
  in the file.
* `certpath=PATH`:
  The path to the server's SSL certificate. This is typically required for SSL
  connectivity unless the certificate has already been added to the openssl
  installation on the system (only applicable with `couchbases://` scheme)
* `ssl=no_verify`:
  Temporarily disable certificate verification for SSL (only applicable with
  `couchbases://` scheme). This should only be used for quickly debugging SSL
  functionality.
* `sasl_mech_force=MECHANISM`:
  Force a specific _SASL_ mechanism to be used when performing the initial
  connection. This should only need to be modified for debugging purposes.
  The currently supported mechanisms are `PLAIN` and `CRAM-MD5`
* `bootstrap_on=<both,http,cccp>`:
  Specify the bootstrap protocol the client should use when attempting to connect
  to the cluster. Options are: `cccp`: Bootstrap using the Memcached protocol
  (supported on clusters 2.5 and greater); `http`: Bootstrap using the HTTP REST
  protocol (supported on any cluster version); and `both`: First attempt bootstrap
  over the Memcached protocol, and use the HTTP protocol if Memcached bootstrap fails.
  The default is `both`

## COMMANDS

The following commands are supported by `cbc`. Unless otherwise specified, each
command supports all of the options above.

### cat

Write the value of keys to standard output.

This command requires that at least one key may be passed to it, but may accept
multiple keys. The keys should be specified as positional arguments after the
command.

In addition to the options in the [OPTIONS](#OPTIONS) section, the following options are supported:

* `r`, `--replica`=_all|INDEX_:
  Read the value from a replica server. The value for this option can either be
  the string `all` which will cause the client to request the value from each
  replica, or `INDEX` where `INDEX` is a 0-based replica index.

* `e`, `--expiry`=_EXPIRATION_:
  Specify that this operation should be a _get-and-touch_ operation in which the
  key's expiry time is updated along with retrieving the item.


### create

### cp

Create a new item in the cluster, or update the value of an existing item.
By default this command will read the value from standard input unless the
`--value` option is specified.

The `cp` command functions the same, except it operates on a list of files. Each file is
stored in the cluster under the name specified on the command line.

In addition to the options in the [OPTIONS](#OPTIONS) section, the following options are supported:

* `-V`, `--value`=_VALUE_:
  The value to store in the cluster. If omitted, the value is read from standard input. This
  option is valid only for the `create` command.

* `f`, `--flags`=_ITEMFLAGS_:
  A 32 bit unsigned integer to be stored alongside the value. This number is returned
  when the item is retrieved again. Other clients commonly use this value to determine
  the type of item being stored.

* `e`, `--expiry`=_EXPIRATION_:
  The number of time in seconds from now at which the item should expire.

* `M`, `--mode`=_upsert|insert|replace_:
  Specify the storage mode. Mode can be one of `insert` (store item if it does
  not yet exist), `replace` (only store item if key already exists), or
  `upsert` (unconditionally store item)

* `p`, `--persist-to`=_NUMNODES_:
  Wait until the item has been persisted to at least `NUMNODES` nodes' disk. If
  `NUMNODES` is 1 then wait until only the master node has persisted the item for
  this key. You may not specify a number greater than the number of nodes actually
  in the cluster.

* `r` `--replicate-to`=_NREPLICAS_:
  Wait until the item has been replicated to at least `NREPLICAS` replica nodes.
  The bucket must be configured with at least one replica, and at least `NREPLICAS`
  replica nodes must be online.


### observe

Retrieve persistence and replication information for items.

This command will print the status of each key to standard error.

See the [OPTIONS](#OPTIONS) for accepted options

### incr

### decr

These commands increment or decrement a _counter_ item in the cluster. A _counter_
is a value stored as an ASCII string which is readable as a number, thus for example
`42`.

These commands will by default refuse to operate on an item which does not exist in
the cluster.

The `incr` and `decr` command differ with how they treat the `--delta` argument. The
`incr` command will treat the value as a _positive_ offset and increment the current
value by the amount specified, whereas the `decr` command will treat the value as a
_negative_ offset and decrement the value by the amount specified.

In addition to [OPTIONS](#OPTIONS), the following options are supported:

* `--initial=_DEFAULT_`:
  Set the initial value for the item if it does not exist in the cluster. The value
  should be an unsigned 64 bit integer. If this option is not specified and the item
  does not exist, the operation will fail. If the item _does_ exist, this option is
  ignored.

* `--delta`=_DELTA_:
  Set the absolute delta by which the value should change. If the command is `incr`
  then the value will be _incremented_ by this amount. If the command is `decr` then
  the value will be _decremented_ by this amount. The default value for this option is
  `1`.

* `-e`, `--expiry`=_EXPIRATION_:
  Set the expiration time for the key, in terms of seconds from now.


### hash

Display mapping information for a key.

This command diplays mapping information about a key. The mapping information
indicates which _vBucket_ the key is mapped to, and which server is currently the
master node for the given _vBucket_.

See the [OPTIONS](#OPTIONS) for accepted options

<a name="lock"></a>
### lock

Lock an item in the cluster.

This will retrieve and lock an item in the cluster, making it inaccessible for
modification until it is unlocked (see [unlock](#unlock)).

In addition to the common options ([OPTIONS](#OPTIONS)), this command accepts the following
options:

* `e`, `--expiry`=_LOCKTIME_:
  Specify the amount of time the lock should be held for. If not specified, it will
  default to the server side maximum of 15 seconds.

<a name="unlock"></a>
### unlock

Unlock a previously locked item.

This command accepts two mandatory positional arguments which are the key and _CAS_ value.
The _CAS_ value should be specified as printed from the [lock][] command (i.e. with the
leading `0x` hexadecimal prefix).

See the [OPTIONS](#OPTIONS) for accepted options


### rm

Remove an item from the cluster.

This command will remove an item from the cluster. If the item does not exist, the
operation will fail.


See the [OPTIONS](#OPTIONS) for accepted options


### stats

Retrieve a list of cluster statistics. If positional arguments are passed to this
command, only the statistics classified under those keys will be retrieved. See the
server documentation for a full list of possible statistics categories.

This command will contact each server in the cluster and retrieve that node's own set
of statistics.

The statistics are printed to standard output in the form of `SERVER STATISTIC VALUE`
where _SERVER_ is the _host:port_ representation of the node from which has provided this
statistic, _STATISTIC_ is the name of the current statistical key, and _VALUE_ is the
value for this statistic.


See the [OPTIONS](#OPTIONS) for accepted options

### version

Display information about the underlying version of _libcouchbase_ to which the
`cbc` binary is linked.

### verbosity

Set the memcached logging versbosity on the cluster. This affects how the memcached
processes write their logs. This command accepts a single positional argument which
is a string describing the verbosity level to be set. The options are `detail`, `debug`
`info`, and `warning`.

### mcflush

Flush a _memcached_ bucket. This command takes no arguments, and will fail if the
bucket specified is not a memcached bucket. You may also use [bucket-flush](#bucket-flush)
to flush any bucket (including a couchbase bucket). The `mcflush` command may be
quicker for memcached buckets, though.

### view

Execute an HTTP request against the server's view (CAPI) interface.

The request may be one to create a design document, view a design document, or query a
view.

To create a design document, the definition of the document (in JSON) should be piped
to the command on standard input.

This command accepts one positional argument which is the _path_ (relative to the
bucket) to execute. Thus to query the `brewery_beers` view in the `beer` design
document within the `beer-sample` bucket one would do:
    cbc view -U couchbase://localhost/beer-sample _design/beer/_view/brewery_beers

In addition to the [OPTIONS](#OPTIONS) specified above, the following options are recognized:

* `-X`, `--method`=_GET|PUT|POST|DELETE_:
  Specify the HTTP method to use for the specific request. The default method is `GET`
  to query a view. To delete an existing design document, specify `DELETE`, and to
  create a new design document, specify `PUT`.

### n1ql

Execute a N1QL Query. The cluster must have at least one query node enabled.

The query itself is passed as a positional argument on the commandline. The
query may contain named placeholders (in the format of `$param`), whose values
may be supplied later on using the `--qarg='$param=value'` syntax.

It is recommended to place the statement in single quotes to avoid shell
expansion.

In addition to the [OPTIONS](#OPTIONS) specified above, the following options
are recognized:

* `-Q`, `--qopt`=_SETTING=VALUE_:
  Specify additional options controlling the execution of the query. This can
  be used for example, to set the `scan_consistency` of the query.

* `-A`, `--qarg`=_PLACEHOLDER=VALUE_:
  Supply values for placeholders found in the query string. The placeholders
  must evaluate to valid JSON values.

### admin

Execute an administrative request against the management REST API.
Note that in order to perform an administrative API you will need to provide
_administrative_ credentials to `cbc admin`. This means the username and password
used to log into the administration console.

This command accepts a single positional argument which is the REST API endpoint
(i.e. HTTP path) to execute.

If the request requires a _body_, it should be supplied via standard input

In addition to the [OPTIONS](#OPTIONS) specified above, the following options are recognized:

* `-X`, `--method`=_GET|PUT|POST|DELETE_:
  Specify the HTTP method to use for the specific request. The default method is
  `GET`.

### bucket-create

Create a bucket in the cluster.

This command will create a bucket with the name specified as the lone positional
argument on the command line.

As this is an administrative command, the `--username` and `--password` options should
be supplied administrative credentials.

In addition to the [OPTIONS](#OPTIONS) specified above, the following options are recognized:

* `--bucket-type`=_couchbase|memcached_:
  Specify the type of bucket to create. A _couchbase_ bucket has persistence to disk and
  replication. A _memached_ bucket is in-memory only and does not replicate.

* `--ram-quota`=_QUOTA_:
  Specify the maximum amount of memory the bucket should occupy (per node) in megabytes.
  If not specified, the default is _512_.

* `--bucket-password`=_PASSWORD_:
  Specify the password to secure this bucket. If passed, this password will be required
  by all clients attempting to connect to the bucket. If ommitted, this bucket may be
  accessible to everyone for both read and write access.

* `--num-replicas`=_REPLICAS_:
  Specify the amount of replicas the bucket should have. This will set the number of nodes
  each item will be replicated to. If not specified the default is _1_.


### bucket-flush

This command will flush the bucket with the name specified as the lone positional
argument on the command line.

This command does not require administrative level credentials, however it does
require that _flush_ be enabled for the bucket.

See the [OPTIONS](#OPTIONS) for accepted options

### connstr 

This command will parse a connection string into its constituent parts and
display them on the screen. The command takes a single positional argument
which is the string to parse.

## EXAMPLES


### CONNECTION EXAMPLES

The following shows how to connect to various types of buckets. These examples
all show how to retrieve the key `key`. See
[OPERATION EXAMPLES](#OPERATION EXAMPLES) for more information on specific
sub-commands.


Run against a bucket (`a_bucket`) on a cluster on a remote host:

    cbc cat key -U couchbase://192.168.33.101/a_bucket

Connect to an SSL cluster at `secure.net`. The certificate for the cluster is
stored locally at `/home/couchbase/couchbase_cert.pem`:

    cbc cat key -U couchbases://secure.net/topsecret_bucket?certpath=/home/couchbase/couchbase_cert.pem

Connect to an SSL cluster at `secure.net`, ignoring certificate verification.
This is insecure but handy for testing:

    cbc cat key -U couchbases://secure.net/topsecret_bucket?ssl=no_verify

Connect to a password protected bucket (`protected`) on a remote host:

    cbc cat key -U couchbase://remote.host.net/protected -P-
    Bucket password:
    ...

Connect to a password protected bucket, specifying the password on the
command line (INSECURE, but useful for testing dummy environments)

    cbc cat key -U couchbase://remote.host.net/protected -P t0ps3cr3t

Connect to a bucket running on a cluster with a custom REST API port

    cbc cat key -U http://localhost:9000/default

Connec to bucket running on a cluster with a custom memcached port

    cbc cat key -U couchbase://localhost:12000/default

Connect to a *memcached* (http://memcached.org)
cluster using the binary protocol. A vanilla memcached cluster is not the same
as a memcached bucket residing within a couchbase cluster (use the normal
`couchbase://` scheme for that):

    cbc cat key -U memcached://host1,host2,host3,host4


Connect to a cluster using the HTTP protocol for bootstrap, and set the
operation timeout to 5 seconds

    cbc cat key -U couchbase://host/bucket -Dbootstrap_on=http -Doperation_timeout=5


### OPERATION EXAMPLES

Store a file to the cluster:

    $ cbc cp mystuff.txt
    mystuff.txt         Stored. CAS=0xe15dbe22efc1e00


Retrieve persistence/replication information about an item (note that _Status_
is a set of bits):

    $ cbc observe mystuff.txt
    mystuff              [Master] Status=0x80, CAS=0x0


Display mapping information about keys:

    $cbc hash foo bar baz
    foo: [vBucket=115, Index=3] Server: cbnode3:11210, CouchAPI: http://cbnode3:8092/default
    bar: [vBucket=767, Index=0] Server: cbnode1:11210, CouchAPI: http://cbnode1:8092/default
    baz: [vBucket=36, Index=2] Server: cbnode2:11210, CouchAPI: http://cbnode2:8092/default

Create a bucket:

    $ cbc bucket-create --bucket-type=memcached --ram-quota=100 --password=letmein -u Administrator -P 123456 mybucket
    Requesting /pools/default/buckets
    202
      Cache-Control: no-cache
      Content-Length: 0
      Date: Sun, 22 Jun 2014 22:43:56 GMT
      Location: /pools/default/buckets/mybucket
      Pragma: no-cache
      Server: Couchbase Server

Flush a bucket:

    $ cbc bucket-flush default
    Requesting /pools/default/buckets/default/controller/doFlush


    200
      Cache-Control: no-cache
      Content-Length: 0
      Date: Sun, 22 Jun 2014 22:53:44 GMT
      Pragma: no-cache
      Server: Couchbase Server

Delete a bucket:

    $ cbc bucket-delete mybucket -P123456
    Requesting /pools/default/buckets/mybucket
    200
      Cache-Control: no-cache
      Content-Length: 0
      Date: Sun, 22 Jun 2014 22:55:58 GMT
      Pragma: no-cache
      Server: Couchbase Server

Use `cbc stats` to determine the minimum and maximum timeouts for a lock operation:

    $ cbc stats | grep ep_getl
    localhost:11210 ep_getl_default_timeout 15
    localhost:11210 ep_getl_max_timeout 30


Create a design document:

    $ echo '{"views":{"all":{"map":"function(doc,meta){emit(meta.id,null)}"}}}' | cbc view -X PUT _design/blog
    201
      Cache-Control: must-revalidate
      Content-Length: 32
      Content-Type: application/json
      Date: Sun, 22 Jun 2014 23:03:40 GMT
      Location: http://localhost:8092/default/_design/blog
      Server: MochiWeb/1.0 (Any of you quaids got a smint?)
    {"ok":true,"id":"_design/blog"}


Query a view:

    $ cbc view _design/blog/_view/all?limit=5
    200
      Cache-Control: must-revalidate
      Content-Type: application/json
      Date: Sun, 22 Jun 2014 23:06:09 GMT
      Server: MochiWeb/1.0 (Any of you quaids got a smint?)
      Transfer-Encoding: chunked
    {"total_rows":20,"rows":[
    {"id":"bin","key":"bin","value":null},
    {"id":"check-all-libev-unit-tests.log","key":"check-all-libev-unit-tests.log","value":null},
    {"id":"check-all-libevent-unit-tests.log","key":"check-all-libevent-unit-tests.log","value":null},
    {"id":"check-all-select-unit-tests.log","key":"check-all-select-unit-tests.log","value":null},
    {"id":"cmake_install.cmake","key":"cmake_install.cmake","value":null}
    ]
    }


Issue a N1QL query:

    $ cbc n1ql 'SELECT * FROM `travel-sample` WHERE type="airport" AND city=$city' -Qscan_consistency=request_plus -A'$city=\"Reno\"'

## FILES

cbc(1) and cbc-pillowfight(1) may also read options from cbcrc(4). The default
path for `cbcrc` is `$HOME/.cbcrc`, but may be overridden by setting the
`CBC_CONFIG` evironment variable to an alternate path.

## BUGS

The options in this utility and their behavior are subject to change. This script
should be used for experiemntation only and not inside production scripts.


## SEE ALSO

cbc-pillowfight(1), cbcrc(4)


## History

The cbc command first appeared in version 0.3.0 of the library. It was significantly
rewritten in version 2.4.0