Files
aars/scripts/logs-cleanup.sh

20 lines
740 B
Bash
Executable File

#!/bin/bash
# Daily log cleanup for AARS. Keep app/access for 7 days, error for 30 days.
# Add to crontab: 0 3 * * * /root/aars/scripts/logs-cleanup.sh
set -e
LOG_DIR="/root/aars/logs"
APP_DAYS=7
ERROR_DAYS=30
if [ ! -d "$LOG_DIR" ]; then
echo "$(date): $LOG_DIR not found, nothing to clean"
exit 0
fi
DELETED_APP=$(find "$LOG_DIR" -maxdepth 1 -name 'app-*.jsonl' -mtime +$APP_DAYS -delete -print | wc -l)
DELETED_ACCESS=$(find "$LOG_DIR" -maxdepth 1 -name 'access-*.jsonl' -mtime +$APP_DAYS -delete -print | wc -l)
DELETED_ERROR=$(find "$LOG_DIR" -maxdepth 1 -name 'error-*.jsonl' -mtime +$ERROR_DAYS -delete -print | wc -l)
echo "$(date): cleanup done — deleted app=$DELETED_APP access=$DELETED_ACCESS error=$DELETED_ERROR"