Skip to content

Instantly share code, notes, and snippets.

@VMuliadi
Last active July 31, 2020 11:10
Show Gist options
  • Select an option

  • Save VMuliadi/7d174924491190d291d7f88a8019dcbf to your computer and use it in GitHub Desktop.

Select an option

Save VMuliadi/7d174924491190d291d7f88a8019dcbf to your computer and use it in GitHub Desktop.
1st positional parameter: ES source. 2nd positional argument: ES target. 3rd positional argument: Action (backup/migrate)
#!/usr/bin/bash
dependency=()
command -v elasticdump > /dev/null || dependency+="elasticdump "
command -v curl > /dev/null || dependency+="curl "
command -v jq > /dev/null || dependency+="jq "
if [[ ${#dependency[@]} -gt 0 ]]; then
echo "Missing dependency: ${dependency[@]}"
exit 1
fi
if [[ -z $1 ]] || [[ -z $2 ]] || [[ -z $3 ]]; then
echo "Please set these variables... "
echo "ES source as the 1st parameter"
echo "ES target as the 2nd parameter"
echo "ES action as the 3rd parameter"
echo "./elasticdump.sh source:9092 dest:9092 backup/migrate"
exit 1
fi
for index in $(curl -XGET $1/_cat/indices -s | awk '{print $3}'); do
if [[ $3 == "migrate" ]]; then
elasticdump --input=$1/${index} --output=$2/${index} --type=analyzer
elasticdump --input=$1/${index} --output=$2/${index} --type=mapping
elasticdump --input=$1/${index} --output=$2/${index} --type=data
elif [[ $3 == "backup" ]]; then
elasticdump --input=$1/${index} --output=${index}.analyzer.json --type=analyzer
elasticdump --input=$1/${index} --output=${index}.mapping.json --type=mapping
elasticdump --input=$1/${index} --output=${index}.data.json --type=data
fi
done
@VMuliadi

Copy link
Copy Markdown
Author

How to use

./elastigrate.sh source.9092 target:9092 migrate  # migrate the data from source to target
./elastigrate.sh source.9092 target:9092 backup  # backup the indexes from source into local JSON file 

Thanks to elastidump developer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment