Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#/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
You can’t perform that action at this time.