Last active
July 31, 2020 11:10
-
-
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)
This file contains hidden or 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
| #!/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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to use
Thanks to
elastidumpdeveloper