sábado, 18 de fevereiro de 2017

Simple yet smart backup script for ElasticSearch Data

Backup script for ElasticSearch Data

Simple yet smart


If you have a ES endpoint that for some reason got a severe DELETE, and you only noticed it a couple of days later (ok, we aren't talking about any production deployment, of course), here's a little script that checks if current backup file size is bigger than 50MB, and only replaces last backup if true. First it compares if it's bigger than current bigger one:
#!/bin/bash 
cd /DATA/backups 
tar cvfz ESdata-today.tar.gz ../ESdata/ 
today=$(stat -c %s ESdata-today.tar.gz) 
prev=$(stat -c %s ESdataBigger.tar.gz) 
if [ "$today" -gt "$prev" ];
then
mv ESdata-today.tar.gz ESdataBigger.tar.gz
else
if [ "$today" -gt 50000000 ];
   then
mv ESdata-today.tar.gz ESdata.tar.gz
fi
fi
 
The 50MB size would be the minimum expected for it, that if smaller chances are you've lost lots of data: adjust to your needs (over time).

Sem comentários:

Enviar um comentário