Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

kv bulkload doesn't accept JSONs generated by kv read #43

Closed
SoTMaR opened this issue Nov 29, 2016 · 2 comments
Closed

kv bulkload doesn't accept JSONs generated by kv read #43

SoTMaR opened this issue Nov 29, 2016 · 2 comments

Comments

@SoTMaR
Copy link

SoTMaR commented Nov 29, 2016

Hi guys,

I need some assistance...

I'm trying to backup/restore my consul KV store via consul-cli and facing the following problem.

First, I "backup" the current KV store with consul-cli kv read:

(as JSON)
consul-cli kv read "" --consul=XXX.YYY.com:8500 --recurse=true --format=json > export.json

RESULT
[{"Key":"project/","CreateIndex":1730,"ModifyIndex":1730,"LockIndex":0,"Flags":0,"Value":"","Session":""},{"Key":"project/environment/some.other.property","CreateIndex":1736,"ModifyIndex":1736,"LockIndex":0,"Flags":0,"Value":"some.other.value","Session":""},{"Key":"project/environment/some.property","CreateIndex":1733,"ModifyIndex":1733,"LockIndex":0,"Flags":0,"Value":"some.value","Session":""}]

(as "pretty" JSON)
consul-cli kv read "" --consul=XXX.YYY.com:8500 --recurse=true --format=prettyjson > prettyexport.json

RESULT

[
  {
    "Key": "project/",
    "CreateIndex": 1730,
    "ModifyIndex": 1730,
    "LockIndex": 0,
    "Flags": 0,
    "Value": "",
    "Session": ""
  },
  {
    "Key": "project/environment/some.other.property",
    "CreateIndex": 1736,
    "ModifyIndex": 1736,
    "LockIndex": 0,
    "Flags": 0,
    "Value": "some.other.value",
    "Session": ""
  },
  {
    "Key": "project/environment/some.property",
    "CreateIndex": 1733,
    "ModifyIndex": 1733,
    "LockIndex": 0,
    "Flags": 0,
    "Value": "some.value",
    "Session": ""
  }
]

Then, I try to restore those same backups with consul-cli kv bulkload:

(as JSON)

consul-cli kv bulkload --consul=XXX.YYY.com:8500 --json=export.json
Error: json: cannot unmarshal array into Go value of type map[string]interface {}

(as "pretty" JSON)

consul-cli kv bulkload --consul=XXX.YYY:8500 --json=prettyexport.json
Error: json: cannot unmarshal array into Go value of type map[string]interface {}

I would have expected to be able to use the result of the read as input for the bulkload but it doesn't seem to be the case. What am I doing wrong?

Thank you in advance,
SoTMaR

@agperson
Copy link

agperson commented Dec 15, 2016

See the example in the wiki for how to do this. Bulkload is expecting key=value only without any other data.

@SoTMaR
Copy link
Author

SoTMaR commented Jan 20, 2017

Hi @agperson,

Thank you very much for your answer!

I tried that in the past without success:

cat prettyexport.json | jq from_entries
jq: error: Cannot use null as object key
jq: error: Cannot use null as object key
jq: error: Cannot use null as object key
null

Nevertheless, thanks to your comment and this jq issue, I found out that my CentOS was using jq 1.3 but the fix was added to later versions. I got jq 1.5 and everything is now working as expected.

Thanks again!

Cheers,
SoTMaR

@SoTMaR SoTMaR closed this as completed Jan 20, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants