open-consul/website/content/commands/kv/import.mdx

74 lines
1.6 KiB
Plaintext
Raw Normal View History

---
layout: commands
2020-04-07 18:55:19 +00:00
page_title: 'Commands: KV Import'
description: >-
The `consul kv import` command adds values to Consul's key/value store according to a JSON representation of the data.
---
# Consul KV Import
Command: `consul kv import`
The `kv import` command is used to import KV pairs from the JSON representation
generated by the `kv export` command.
The table below shows this command's [required ACLs](/consul/api-docs/api-structure#authentication). Configuration of
[blocking queries](/consul/api-docs/features/blocking) and [agent caching](/consul/api-docs/features/caching)
are not supported from commands, but may be from the corresponding HTTP endpoint.
| ACL Required |
| ------------ |
| `key:write` |
## Usage
Usage: `consul kv import [options] [DATA]`
#### Command Options
- `-prefix` - Key prefix for imported data. The default value is empty meaning
root. Added in Consul 1.10.
#### Enterprise Options
@include 'http_api_partition_options.mdx'
2020-04-07 18:55:19 +00:00
@include 'http_api_namespace_options.mdx'
#### API Options
@include 'http_api_options_client.mdx'
@include 'http_api_options_server.mdx'
## Examples
To import from a file, prepend the filename with `@`:
2020-05-19 18:32:38 +00:00
```shell-session
$ consul kv import @values.json
# Output
```
To import from stdin, use `-` as the data parameter:
2020-05-19 18:32:38 +00:00
```shell-session
$ cat values.json | consul kv import -
# Output
```
You can also pass the JSON directly, however care must be taken with shell
escaping:
2020-05-19 18:32:38 +00:00
```shell-session
$ consul kv import "$(cat values.json)"
# Output
```
To import under prefix, use `-prefix` option:
```shell-session
$ cat values.json | consul kv import -prefix=sub/dir/ -
# Output
```