Last active
January 23, 2018 05:37
-
-
Save brockoffdev/69a3304443cde2848e2ce46998711c17 to your computer and use it in GitHub Desktop.
Rollback with Versioning in Vault
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 | |
VAULT_PATH=/dev/single | |
DATETIME=$(date -u +"%Y%m%d%H%M%S") | |
PREVIOUS=${1:-previous} | |
echo "Rolling back application config to \"$PREVIOUS\"..." | |
# Create Tempfiles for writing to... | |
OLDTMPFILE=`mktemp /tmp/we.XXXXXX` || exit 1 | |
NEWTMPFILE=`mktemp /tmp/we.XXXXXX` || exit 1 | |
# Read our old configuration (and current), and save to tempfiles | |
vault read -format=json $VAULT_PATH | jq .data >> $OLDTMPFILE | |
vault read -format=json /versions$VAULT_PATH/$PREVIOUS | \ | |
jq .data >> $NEWTMPFILE | |
# Perform the rollback | |
echo "Saving current config state..." | |
vault write /versions$VAULT_PATH/$DATETIME @$OLDTMPFILE > /dev/null | |
vault write /versions$VAULT_PATH/previous @$OLDTMPFILE > /dev/null | |
vault write $VAULT_PATH @$NEWTMPFILE \ | |
&& rm $OLDTMPFILE $NEWTMPFILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment