Skip to content

Instantly share code, notes, and snippets.

@Pyppe
Forked from dadoonet/backup.sh
Last active August 29, 2015 14:12
Show Gist options
  • Save Pyppe/d9f70131b58f333dc655 to your computer and use it in GitHub Desktop.
Save Pyppe/d9f70131b58f333dc655 to your computer and use it in GitHub Desktop.
curl -XPOST http://localhost:9200/_optimize
curl -XPOST http://localhost:9200/_flush
curl -XPOST http://localhost:9200/_all/_close
# DO THE BACKUP
curl -XPOST http://localhost:9200/_all/_open
# 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