Files
mqtt-ingester/scripts/prune.sh
T
2026-08-30 11:30:09 +02:00

49 lines
1.3 KiB
Bash

#!/usr/bin/env bash
# Removes stack data: volumes and orphans, optionally build artifacts.
#
# DANGER: deletes the TimescaleDB data volume (all telemetry data), the
# MQTT log volume, and the Loki volume. Users/groups/sessions stored in
# Postgres are deleted with it.
#
# Usage:
# ./scripts/prune.sh # containers only
# ./scripts/prune.sh --volumes # also delete all data (destructive)
# ./scripts/prune.sh --all # also remove images and build cache
set -euo pipefail
StackRoot="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$StackRoot"
Volumes=0
All=0
for arg in "$@"; do
case "$arg" in
--volumes|-v) Volumes=1 ;;
--all|-a) All=1 ;;
*) echo "Unknown option: $arg" >&2; exit 1 ;;
esac
done
if [ "$Volumes" -eq 1 ]; then
echo "This deletes ALL stored data (telemetry, users, groups, sessions, logs)."
read -r -p "Type 'delete' to continue: " confirm
[ "$confirm" = "delete" ] || { echo "Aborted."; exit 0; }
fi
echo "Removing stack containers..."
docker compose down --remove-orphans
if [ "$Volumes" -eq 1 ]; then
echo "Removing volumes..."
docker compose down --volumes
fi
if [ "$All" -eq 1 ]; then
echo "Removing images and build cache..."
docker compose down --rmi all
docker image prune -f
docker builder prune -f
fi
echo "Done."