Skip to content

Instantly share code, notes, and snippets.

@shokoe
Created December 11, 2016 12:36
Show Gist options
  • Save shokoe/e4180ead84cd7476e48cd373eba227ef to your computer and use it in GitHub Desktop.
Save shokoe/e4180ead84cd7476e48cd373eba227ef to your computer and use it in GitHub Desktop.
Local Elasticsearch Logstash indices retention cron script.
#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
local_indices='/var/lib/elasticsearch/elasticsearch/nodes/0/indices'
# retention
i=14
# history verification for skipped runs
h=10
I=$i
while true; do
[ $(($i-$I)) -eq $h ] && break
T=`date -d "-$i days" +%Y.%m.%d`
if [ -d $local_indices/logstash-$T ]; then
o=`curl -XDELETE "http://localhost:9200/logstash-$T"`
echo "logstash-$T - $o"
else
echo "logstash-$T - Not Found"
fi
i=$(($i+1))
done | sed "s#^#`date` -- #" >> /var/log/es_clean.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment