diff options
author | Britney Fransen <brfransen@gmail.com> | 2013-11-13 16:11:18 (GMT) |
---|---|---|
committer | Britney Fransen <brfransen@gmail.com> | 2013-11-13 16:11:18 (GMT) |
commit | 65d116fd70f48623c761c9375c31ab6ee6fcc179 (patch) | |
tree | 2fdd1ce64223bac7d5bd890a9dc002e9919618d0 /abs/core/rsyslog/log_care.sh | |
parent | 404d8881490095229560d5820ea56e8ba0b7f172 (diff) | |
download | linhes_pkgbuild-65d116fd70f48623c761c9375c31ab6ee6fcc179.zip linhes_pkgbuild-65d116fd70f48623c761c9375c31ab6ee6fcc179.tar.gz linhes_pkgbuild-65d116fd70f48623c761c9375c31ab6ee6fcc179.tar.bz2 |
rsyslog: log_care.sh: keep backups based on number rather than time.
Diffstat (limited to 'abs/core/rsyslog/log_care.sh')
-rw-r--r-- | abs/core/rsyslog/log_care.sh | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/abs/core/rsyslog/log_care.sh b/abs/core/rsyslog/log_care.sh index b0a774b..ced0f06 100644 --- a/abs/core/rsyslog/log_care.sh +++ b/abs/core/rsyslog/log_care.sh @@ -1,14 +1,16 @@ #!/bin/bash MYTH_RUN_STATUS=1 . /etc/profile -YEAR=`date +%Y` -LASTYEAR=$(($YEAR - 1)) -for DATE in $YEAR $LASTYEAR -do - echo "Compressing log files" - find /var/log/$DATE* -mtime +1 -exec gzip -9 {} \; + +BackupDir="/var/log/20*-*-*" +KeepBackups=14 +NumBackups=`ls -d $BackupDir | wc -l` + +if [[ $NumBackups > $KeepBackups ]]; then echo "Deleting old log files" - find /var/log/$DATE* -mtime +12 -exec rm -rf {} \; - echo "Deleting empty directories" - find /var/log/$DATE* -depth -type d -empty -exec rm -rf {} \; -done + numdel=$(($NumBackups-$KeepBackups)) + rm -rf `ls -d $BackupDir | head -$numdel` +fi + +echo "Compressing log files" +find $BackupDir -type f -mtime +2 \( ! -iname "*.gz" \) -exec gzip -9 {} \; |