Created
December 11, 2016 12:36
-
-
Save shokoe/e4180ead84cd7476e48cd373eba227ef to your computer and use it in GitHub Desktop.
Local Elasticsearch Logstash indices retention cron script.
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
#!/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