Update for log rotation and backups
This commit is contained in:
26
scripts/log-rotate.sh
Normal file
26
scripts/log-rotate.sh
Normal 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
|
||||
|
Reference in New Issue
Block a user