Skip to content

Instantly share code, notes, and snippets.

@dadoonet
Created December 26, 2012 14:50
Show Gist options
  • Save dadoonet/4380715 to your computer and use it in GitHub Desktop.
Save dadoonet/4380715 to your computer and use it in GitHub Desktop.
Backup Elasticsearch node
# Script to be placed in elasticsearch/bin
# Launch it from elasticsearch dir
# bin/backup indexname
# We suppose that data are under elasticsearch/data
# It will create a backup file under elasticsearch/backup
if [ -z "$1" ]; then
INDEX_NAME="dummy"
else
INDEX_NAME=$1
fi
# Optimize index
curl -XPOST http://localhost:9200/$INDEX_NAME/_optimize
# Flush index
curl -XPOST http://localhost:9200/$INDEX_NAME/_flush
# Close index
curl -XPOST http://localhost:9200/$INDEX_NAME/_close
# Backup you data dir
mkdir backup
tar zcf backup/$INDEX_NAME.tar.gz data/elasticsearch/nodes/*/indices/$INDEX_NAME/
# Then reopen index
curl -XPOST http://localhost:9200/$INDEX_NAME/_open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment