mirror of
https://github.com/Security-Onion-Solutions/securityonion.git
synced 2025-12-19 15:33:06 +01:00
first take at so-infludb-clean
This commit is contained in:
42
salt/common/tools/so-influxdb-clear
Normal file
42
salt/common/tools/so-influxdb-clear
Normal file
@@ -0,0 +1,42 @@
|
||||
|
||||
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}\""
|
||||
Reference in New Issue
Block a user