Skip to content

Instantly share code, notes, and snippets.

@iam4x
Created March 25, 2026 11:59
Show Gist options
  • Select an option

  • Save iam4x/4d52dcf07c1ca7dc4f178b90a6227a4e to your computer and use it in GitHub Desktop.

Select an option

Save iam4x/4d52dcf07c1ca7dc4f178b90a6227a4e to your computer and use it in GitHub Desktop.
#!/bin/bash
DATA_PATH="/root/hl/data"
# Folders to exclude from pruning
# Example: EXCLUDES=("visor_child_stderr" "rate_limited_ips" "node_logs")
EXCLUDES=("visor_child_stderr")
# Log startup for debugging
echo "$(date): Prune script started"
# Check if data directory exists
if [ ! -d "$DATA_PATH" ]; then
echo "$(date): Error: Data directory $DATA_PATH does not exist."
exit 1
fi
echo "$(date): Starting pruning process at $(date)"
# Get directory size before pruning
size_before=$(du -sh "$DATA_PATH" | cut -f1)
files_before=$(find "$DATA_PATH" -type f | wc -l)
echo "$(date): Size before pruning: $size_before with $files_before files"
# Build the -prune arguments for excluding directories
PRUNE_ARGS=()
for dir in "${EXCLUDES[@]}"; do
PRUNE_ARGS+=(-path "*/$dir" -prune -o)
done
# Delete data older than 48 hours = 60 minutes * 48 hours
HOURS=$((60*12))
find "$DATA_PATH" -mindepth 1 "${PRUNE_ARGS[@]}" -type f -mmin +$HOURS -exec rm {} +
# Get directory size after pruning
size_after=$(du -sh "$DATA_PATH" | cut -f1)
files_after=$(find "$DATA_PATH" -type f | wc -l)
echo "$(date): Size after pruning: $size_after with $files_after files"
echo "$(date): Pruning completed. Reduced from $size_before to $size_after ($(($files_before - $files_after)) files removed)."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment