verify with user before proceedig to clean

This commit is contained in:
m0duspwnens
2021-05-05 15:08:11 -04:00
parent 44de611097
commit db98b7ed27

View File

@@ -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