diff --git a/salt/common/tools/so-influxdb-clear b/salt/common/tools/so-influxdb-clear new file mode 100644 index 000000000..38ef6491f --- /dev/null +++ b/salt/common/tools/so-influxdb-clear @@ -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}\"" \ No newline at end of file