Files
securityonion/salt/common/tools/so-influxdb-clear
2021-05-05 13:29:24 -04:00

42 lines
1.1 KiB
Plaintext

echo "This script is used to reduce the size of InfluxDB by removing old data and retaining only the duration specified."
echo "The duration will need to be specified as an integer followed by the duration unit, without a space."
echo "For example, to purge all data, but retain the past 3 months, specify 3mo for the duration."
echo "The duration units are as follows:"
echo " mo - month(s)"
echo " w - week(s)"
echo " d - day(s)"
while true; do
echo ""
read -p 'Enter the duration of past data that you would like to retain: ' duration
duration=$(echo $duration | tr '[:upper:]' '[:lower:]')
originalIFS=$IFS
case "${duration}" in
[0-9]+mo$)
break
;;
[0-9]+w$)
break
;;
[0-9]+d$)
break
;;
*)
echo ""
echo "Invalid duration."
;;
esac
done
IFS=$originalIFS
echo "Cleaning InfluxDb and saving only the past ${duration}"
docker exec -t so-influxdb /bin/bash -c "influx -ssl -unsafeSsl -database telegraf -execute \"DELETE FROM /.*/ WHERE \"time\" >= '2020-01-01T00:00:00.0000000Z' AND \"time\" <= now() - ${duration}\""