diff --git a/scripts/elastic-upgrade.sh b/scripts/elastic-upgrade.sh index a915f997e..9f1c1bb93 100755 --- a/scripts/elastic-upgrade.sh +++ b/scripts/elastic-upgrade.sh @@ -11,6 +11,12 @@ config() { + if ! command -v curl + then + echo "Please install curl before running this script." + echo "curl was not found, exiting..." + exit 1 + fi FM_PATH=$(pwd) TYPE="NOT-FOUND" read -rp "Is fab-manager installed at \"$FM_PATH\"? (y/n) " confirm /dev/null | grep [[:digit:]] | awk '{print $3}') + for index in indices + do + local migration_index="$index""_$1" + curl -XPUT "http://$ES_IP:9200/$migration_index/" -d '{ + "settings" : { + "index" : { + "number_of_shards" : 0, + "number_of_replicas" : 0, + "refresh_interval": -1 + } + } + }' + curl -XPOST "$ES_IP:9200/_reindex?pretty" -H 'Content-Type: application/json' -d "{ + 'source': { + 'index': '$index' + }, + 'dest': { + 'index': '$migration_index' + } + }" + done + echo "Reindex completed, deleting previous index..." + echo "Indices are reindexing, waiting to finish..." + local state=$(curl "$ES_IP:9200/_cat/indices?v" 2>/dev/null | grep [[:digit:]] | awk '{print $1}' | sort | uniq) + while [ "$state" = "green" ] + do + sleep 1 + state=$(curl "$ES_IP:9200/_cat/indices?v" 2>/dev/null | grep [[:digit:]] | awk '{print $1}' | sort | uniq) + done + echo "Reindex completed, deleting previous index..." + for index in indices + do + curl -XDELETE "$ES_IP:9200/$index?pretty" + done +} + +reindex_final_indices() +{ + local previous=$1 + local indices=$(curl "$ES_IP:9200/_cat/indices?v" 2>/dev/null | grep [[:digit:]] | awk '{print $3}') + for index in indices + do + local final_index=$(echo "$index" | sed "s/\(.*\)_$previous$/\1/") + curl -XPUT "http://$ES_IP:9200/$final_index" + curl -XPOST "$ES_IP:9200/_reindex?pretty" -H 'Content-Type: application/json' -d "{ + 'source': { + 'index': '$index' + }, + 'dest': { + 'index': '$final_index' + } + }" + done + echo "Indices are reindexing, waiting to finish..." + local state=$(curl "$ES_IP:9200/_cat/indices?v" 2>/dev/null | grep [[:digit:]] | awk '{print $1}' | sort | uniq) + while [ "$state" != "green" ] + do + sleep 1 + state=$(curl "$ES_IP:9200/_cat/indices?v" 2>/dev/null | grep [[:digit:]] | awk '{print $1}' | sort | uniq) + done + echo "Reindex completed, deleting previous index..." + for index in indices + do + curl -XDELETE "$ES_IP:9200/$index?pretty" + done +} + start_upgrade() { + # $1: current version + # $2: target version case "$TYPE" in "DOCKER-COMPOSE") - upgrade_compose + upgrade_compose $1 $2 ;; "DOCKER") - upgrade_docker + upgrade_docker $1 $2 ;; "CLASSIC") - upgrade_classic + upgrade_classic $2 ;; *) echo "Unexpected ElasticSearch installation $TYPE" @@ -222,7 +321,12 @@ upgrade_elastic() { config detect_installation - start_upgrade + start_upgrade '1.7' '2.4' + reindex_indices '24' + start_upgrade '2.4' '5.6' + reindex_indices '56' + start_upgrade '5.6' '6.2' + reindex_final_indices '56' } upgrade_elastic "$@" \ No newline at end of file