Files
intl_news/scripts/cleanup_logs.sh
T
2026-07-18 16:13:52 +08:00

25 lines
751 B
Bash
Executable File

#!/bin/bash
# =============================================
# 日志清理:删除 14 天前的日志文件
# 适用于海外 + 国内服务器
# =============================================
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
LOG_DIR="$PROJECT_DIR/logs"
RETENTION_DAYS=14
if [ ! -d "$LOG_DIR" ]; then
exit 0
fi
DELETED=$(find "$LOG_DIR" -type f -name "*.log" -mtime +$RETENTION_DAYS 2>/dev/null | wc -l)
if [ "$DELETED" -gt 0 ]; then
find "$LOG_DIR" -type f -name "*.log" -mtime +$RETENTION_DAYS -delete 2>/dev/null
echo "[$(date)] 清理完成: 删除 $DELETED 个旧日志 (>${RETENTION_DAYS}d)"
else
echo "[$(date)] 无旧日志需要清理"
fi