Skip to content

Instantly share code, notes, and snippets.

@cdahlqvist
Created January 24, 2019 20:10
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 cdahlqvist/aedec2a699df73a6c6efea5a45999cb0 to your computer and use it in GitHub Desktop.
Save cdahlqvist/aedec2a699df73a6c6efea5a45999cb0 to your computer and use it in GitHub Desktop.
#/bin/bash
TIMESTAMP=$(date +%s)
ES_HOST=$1
REPOSITORY=$2
INDEX_NAME=$3
SNAPSHOT_ID=$4
NEW_INDEX_NAME=$5
RESULT=$(curl -XPOST -s http://$ES_HOST/_snapshot/$REPOSITORY\/$SNAPSHOT_ID\/_restore -d "{
\"indices\": \"$INDEX_NAME\",
\"ignore_unavailable\": \"true\",
\"include_global_state\": false,
\"rename_pattern\": \"$INDEX_NAME\",
\"rename_replacement\": \"$NEW_INDEX_NAME\"
}")
if [ "$RESULT" == '{"accepted":true}' ]
then
echo $(date) "Snapshot initiated. Restoring" $INDEX_NAME "into" $NEW_INDEX_NAME "from repository" $REPOSITORY ". Await completion."
COUNT=0
while [ $COUNT == 0 ]
do
sleep 30
COUNT=$(curl -s http://$ES_HOST/_cat/indices | grep $NEW_INDEX_NAME | grep green | wc -l)
if [ $COUNT == 1 ]
then
echo $(date) "Snapshot restoration of" $NEW_INDEX_NAME "has completed."
else
echo $(date) "Snapshot restoration of" $NEW_INDEX_NAME "still not completed."
fi
done
else
echo $(date) "Initiation of snapshot restoration for" $NEW_INDEX_NAME "FAILED."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment