Skip to content

Instantly share code, notes, and snippets.

@gisjedi
Created February 1, 2018 18:25
Show Gist options
  • Save gisjedi/b261eb84542b6591573d7e31d4ee929a to your computer and use it in GitHub Desktop.
Save gisjedi/b261eb84542b6591573d7e31d4ee929a to your computer and use it in GitHub Desktop.
archive-script.sh
ADDRESS=http://10.3.2.183:9200/
TWOYEARMARK=$(($(date -v-24S +'%s * 1000 + %-N / 1000000')))
BUCKETNAME="ais-elasticsearch-snapshots"
AWSENDPOINT="s3.us-east-2.amazonaws.com"
AWSBASEPATH="snapshots/archives"
DELETEINDCIES=false
curl -s http://$ADDRESS/_cat/indices?h=i,cd > test.txt
while read OUTPUT
do
echo "ok in the loop"
stringarray=($OUTPUT)
indexname=${stringarray[0]}
indexdate=${stringarray[1]}
if [ $indexdate -lt $TWOYEARMARK ]
then
echo ""
echo "Index $indexname older than 2 years. Archiving....."
curl -XPUT -s http://$ADDRESS/_snapshot/$indexname -d '{ "type": "s3", "settings": { "bucket": "'"$BUCKETNAME"'", "endpoint": "'"$AWSENDPOINT"'", "base_path" : "'"$AWSBASEPATH"'" }}'
#curl -XPUT -s http://$ADDRESS/_snapshot/$indexname -d '{ "type": "fs","settings": { "location": "'"$indexname"'", "compress": true}}'
echo ""
curl -XPUT -s http://$ADDRESS/_snapshot/$indexname/0?wait_for_completion=true -d '{ "indices": "'"$indexname"'", "ignore_unavailable": true, "include_global_state": false}'
echo ""
if [ DELETEINDCIES = true ] # verify snapshot?
then
echo "im deleting stuff"
curl -XDELETE http://$ADDRESS/$indexname
fi
fi
done <test.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment