From db98b7ed276cb0df0661798180771a7379562268 Mon Sep 17 00:00:00 2001 From: m0duspwnens Date: Wed, 5 May 2021 15:08:11 -0400 Subject: [PATCH] verify with user before proceedig to clean --- salt/common/tools/sbin/so-influxdb-clean | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/salt/common/tools/sbin/so-influxdb-clean b/salt/common/tools/sbin/so-influxdb-clean index 809b17381..453d5b2e4 100644 --- a/salt/common/tools/sbin/so-influxdb-clean +++ b/salt/common/tools/sbin/so-influxdb-clean @@ -19,11 +19,9 @@ modurregex="^[0-9]+mo$" wdurregex="^[0-9]+w$" ddurregex="^[0-9]+d$" -echo "" -echo "This script is used to reduce the size of InfluxDB by removing old data and retaining only the duration specified." +echo -e "\nThis 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 "" -echo "For example, to purge all data, but retain the past 3 months, specify 3mo for the duration." +echo -e "\nFor 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)" @@ -38,13 +36,18 @@ while true; do break fi - echo "" - echo "Invalid duration." + echo -e "\nInvalid duration." done -echo "Cleaning InfluxDb and saving only the past ${duration}" -if 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\""; then - echo "InfluxDb clean complete." +echo -e "\nInfluxDB will now be cleaned and leave only the past $duration worth of data." +read -r -p "Are you sure you want to continue? [y/N] " yorn +if [[ "$yorn" =~ ^([yY][eE][sS]|[yY])$ ]]; then + echo -e "\nCleaning InfluxDb and saving only the past $duration. This may could take several minutes depending on how much data needs to be cleaned." + if 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\""; then + echo -e "\nInfluxDb clean complete." + else + echo -e "\nSomething went wrong with cleaning InfluxDB. Please verify that the so-influxdb Docker container is running, and check the log at /opt/so/log/influxdb/influxdb.log for any details." + fi else - echo "Something went wrong with cleaning InfluxDB. Please verify that the so-influxdb Docker container is running, and check the log at /opt/so/log/influxdb/influxdb.log for any details." + echo -e "\nExiting as requested." fi