Last active
November 10, 2018 01:02
-
-
Save ChrisCinelli/db1af03d007d2f64a44ff22f4633fe74 to your computer and use it in GitHub Desktop.
Migrate all indexes of Elastic Search from a cluster to another - It has less limirations then reindex when runinng with differnt ES versions
This file contains 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 | |
# See https://gist.github.com/db1af03d007d2f64a44ff22f4633fe74 for more info | |
# This script backup data from a ES instance to disk and create a xz archive with the command to restore it | |
# You need to have jq ( https://stedolan.github.io/jq/ ) and elasticdump ( https://www.npmjs.com/package/elasticdump ) installed | |
# source ES instance | |
DEFAULT_ESR='http://source:9200' # Edit this | |
ESR=${1:-$DEFAULT_ESR} # Or just use $1 to add the Elastic Search url | |
# source ES instance | |
DEFAULT_ESW='http://localhost:9200' # Edit this | |
ESW=${2:-$DEFAULT_ESW} # Or just use $2 to add the Elastic Search url | |
# Tune this reg expression to filter the indexes you want to backup | |
DEFAULT_REGEX='.*' | |
REGEX=${3:-$DEFAULT_REGEX} | |
DEFAULT_CMD='elasticdump' # You can use your own clone of elasticdump. Ex: 'Ex: '/Users/youruser/my-projects/elasticsearch-dump/bin/elasticdump' | |
CMD=${4:-$DEFAULT_CMD} | |
duplicate_index() { | |
local in=$1 | |
local out=$2 | |
local index=$3 | |
shift | |
shift | |
shift | |
for i; do | |
echo " ----> Duplicating '${in}/${index}' ('$i')" | |
$CMD \ | |
--limit=9999 \ | |
--input=${in}/${index} \ | |
--output=${out}/${index} \ | |
--type=$i | |
done; | |
} | |
indexes=$(curl $ESR/_aliases?pretty=1 | jq --raw-output 'keys | .[]') | |
echo "$indexes" | while read -r current_index; do | |
if [[ $current_index =~ $REGEX ]] | |
then | |
echo " --> Coping '$current_index'"; | |
duplicate_index "$ESR" "$ESW" "$current_index" analyzer settings mapping alias data | |
else | |
echo " !!--> Skipping '$current_index' that does not match the REGEX $REGEX"; | |
fi | |
done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment