From d555bb48fa2d844ee49257465f2bc18eac7a68f1 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 27 Jan 2015 13:37:05 -0500 Subject: [PATCH] CMD59864 improved log file cleanup * use -mtime instead of -ctime for finding files to delete * clean up empty directories * extend notes on why we're not using logrotate Signed-off-by: Bill Erickson --- KCLS/misc-scripts/manage-log-files.sh | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/KCLS/misc-scripts/manage-log-files.sh b/KCLS/misc-scripts/manage-log-files.sh index f00e846fc4..93da78d070 100755 --- a/KCLS/misc-scripts/manage-log-files.sh +++ b/KCLS/misc-scripts/manage-log-files.sh @@ -5,6 +5,22 @@ set -eu # To future generations: this script was a lot simpler # to implement and test than a logrotate setup. +# Specifically, the hurdle is that logratate is designed +# to handle multiple log files in the last path component +# (e.g. /my/path/to/logfiles/*). KCLS log directory tree +# has several levels which are year, month and day. To +# fully express what this script does a lot of hardcoded +# configuration would need to be written. +# While it still technically should be possible to +# configure logrotate to do what this script achieves +# it will be really cumbersome and significantly time +# demanding. Especially, when the log directory tree +# structure needs to be modified in the future as it will +# necessitate revision of logrotate configuration that +# would need to be rewritten to account for the changes +# in the structure of the log directory tree. Not to mention +# use of underdocumented features (iliv@commandprompt.com) + # *_AGE values are stored as days # Example: a compress value of "3" means compress files # last modified more than 3 days ago. @@ -29,11 +45,15 @@ done; # Delete all Evergreen log files that are older than DELETE_AGE # days, except for the Apache access log and Evergreen activity log. -/usr/bin/find /var/log/evergreen -type f -ctime +$DELETE_AGE \ +/usr/bin/find /var/log/evergreen -type f -mtime +$DELETE_AGE \ -not -name "ap_access*" -not -name "activity*" -delete # Compress Evergreen log files older than COMPRESS_AGE days -/usr/bin/find /var/log/evergreen/ -type f -ctime +$COMPRESS_AGE \ +/usr/bin/find /var/log/evergreen/ -type f -mtime +$COMPRESS_AGE \ -not -name "*bz2" -exec /bin/bzip2 {} \; +# clean up empty directories + +/usr/bin/find /var/log/evergreen/ -type d -empty -exec rmdir '{}' \; + -- 2.11.0