Created
August 7, 2017 20:40
-
-
Save r7vme/bcba3380fd33694906c4f63faa607e41 to your computer and use it in GitHub Desktop.
etcd v3 dump restore keys
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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