Skip to content

Instantly share code, notes, and snippets.

@r7vme
Created August 7, 2017 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save r7vme/bcba3380fd33694906c4f63faa607e41 to your computer and use it in GitHub Desktop.
Save r7vme/bcba3380fd33694906c4f63faa607e41 to your computer and use it in GitHub Desktop.
etcd v3 dump restore keys
#!/bin/bash
# Script to restore keys to etcd
#
# To dump keys use:
# etcdctl get "" --prefix=true > kv
etcdctl="ETCDCTL_API=3 etcdctl --endpoints=http://127.0.0.1:2379"
# Input filename
F=${1:-'kv'}
LINESNUM=$(cat $F | wc -l)
for k in $(seq 1 2 $LINESNUM); do
# Get key
KEY=$(sed -n "${k}p" $F)
# Get value
v=$((k + 1))
VALUE=$(sed -n "${v}p" $F)
# put key to etcd
eval $etcdctl put \'$KEY\' \'$VALUE\'
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment