#!/bin/sh
### Copyright 1999-2025. WebPros International GmbH. All rights reserved.

# discover "/opt/psa/var/health/data/*/$target-*" directories
# and remove rrd databases which have not being updated for a month
# also remove directories which became empty

# "disk", "df", and "interface" targets may refer to unmounted devices
# "plesk_cgroups" target may refer to removed users
for target in "disk" "df" "interface" "plesk_cgroups"; do
	/usr/bin/find "/opt/psa/var/health/data" -mindepth 2 -maxdepth 2 -type d -name "${target}-*" | while read -r target_rrd_d; do
		/usr/bin/find "$target_rrd_d" -mindepth 1 -maxdepth 1 -name "*.rrd" -type f -mtime +30 -delete
		/usr/bin/find "$target_rrd_d" -maxdepth 0 -type d -empty -delete
	done
done
