Update for log rotation and backups

This commit is contained in:
2024-10-14 12:15:11 -07:00
parent ed9ba0118b
commit bbd2de6792
12 changed files with 68 additions and 99 deletions

26
scripts/log-rotate.sh Normal file
View File

@@ -0,0 +1,26 @@
#!/usr/bin/env bash
# Set the log directory
LOG_DIR="/etc/httpd/logs"
# Get current date
DATE=$(date +%Y%m%d)
# Rotate access log
if [ -f "$LOG_DIR/access_log" ]; then
cp "$LOG_DIR/access_log" "$LOG_DIR/access_log.$DATE"
cat /dev/null > "$LOG_DIR/access_log"
fi
# Rotate error log
if [ -f "$LOG_DIR/error_log" ]; then
cp "$LOG_DIR/error_log" "$LOG_DIR/error_log.$DATE"
cat /dev/null > "$LOG_DIR/error_log"
fi
# Compress logs older than 3 days
find "$LOG_DIR" -name "*.log.*" -type f -mtime +3 -exec gzip {} \;
# Delete logs older than 7 days
find "$LOG_DIR" -name "*.log.*" -type f -mtime +7 -delete