From fdf15e012a71bd3ff8f97c79787161d2a0fbf61c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Charaoui?= Date: Thu, 29 Aug 2024 12:52:22 -0400 Subject: [PATCH] (maint) Add prune-reports subcommand This adds a puppetserver subcommand to help garbage-collect old reports. The default TTL is the same as the one used for PuppetDB (14d), where this garbage collection is done automatically. --- resources/ext/cli/prune.erb | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 resources/ext/cli/prune.erb diff --git a/resources/ext/cli/prune.erb b/resources/ext/cli/prune.erb new file mode 100644 index 0000000000..feb8073456 --- /dev/null +++ b/resources/ext/cli/prune.erb @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +usage() { + echo "Prune contents of report and bucket directories." + echo + echo "Usage: puppetserver prune []" + echo " bucketdir|reportdir work on either bucketdir or reportdir" + echo " delete data older than this amount of time (default: 14d)" +} + +prune() { + DIR="$1" + AGE=${2:-14d} + puppet apply --no-report --log_level=warning -e "tidy { \$settings::${DIR}: age=>'${AGE}', recurse=>true, rmdirs=>true }" +} + +case $1 in + -h|--help) + usage + exit 0 + ;; + bucketdir|reportdir) + prune "$1" "$2" + ;; + *) + echo "Error: unknown argument." + usage + exit 1 + ;; +esac