Skip to content

Instantly share code, notes, and snippets.

@brockoffdev
Last active January 23, 2018 05:37
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 brockoffdev/69a3304443cde2848e2ce46998711c17 to your computer and use it in GitHub Desktop.
Save brockoffdev/69a3304443cde2848e2ce46998711c17 to your computer and use it in GitHub Desktop.
Rollback with Versioning in Vault
#!/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