Skip to content

Commit 0ac4fd5

Browse files
author
Christopher M. Neill
committed
Normalizing variables and comments
1 parent 90e8eff commit 0ac4fd5

2 files changed

Lines changed: 16 additions & 12 deletions

File tree

ansible/roles/loggly/files/archiveOldLogs.sh

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,28 @@
44
# This is to be run only for legacy logs in /var/log, not application logs in /var/log/runnable
55
#
66

7+
# we only want this run as root
78
if [ "root" != `whoami` ] ; then
89
echo "It don't mean a thing if it ain't got that swing."
910
exit 127
1011
fi
1112

12-
LOGDIR=/var/log
13-
ARCHDIR=/docker/archive
14-
DATE=`date +%Y%m%d%H%m`
13+
# legacy log path
14+
logdir=/var/log
15+
# store log archives here, purge manually
16+
archdir=/docker/archive
17+
datetime=`date +%Y%m%d%H%m`
1518

16-
# these haven't been modified in > 24 hours, so "doing it live" should be OK:
19+
# these logfiles haven't been modified in > 24 hours, so moving them without cleanup up filehandles first should be OK:
1720
echo "Compressing logs > 24h"
18-
find ${LOGDIR} -maxdepth 2 -type f -mmin +1440 -name '*.log' -exec bzip2 -9 {} \; -print
21+
find ${logdir} -maxdepth 2 -type f -mmin +1440 -name '*.log' -exec bzip2 -9 {} \; -print
1922
echo "Restarting rsyslogd"
23+
# but we do need to clean the filehandles after, just in case
2024
service rsyslog restart
2125

2226
# archive anything > 1wk
2327
echo "Archiving logs > 1wk"
24-
mkdir -p ${ARCHDIR} 2>&1
25-
find ${LOGDIR} -maxdepth 2 -type f -mtime +6 -name '*z' | xargs tar jcvpf ${ARCHDIR}/log-archive-${DATE}.tbz
28+
mkdir -p ${archdir} 2>&1
29+
find ${logdir} -maxdepth 2 -type f -mtime +6 -name '*z' | xargs tar jcvpf ${archdir}/log-archive-${datetime}.tbz
2630
echo "Purging logs > 1wk"
27-
find ${LOGDIR} -maxdepth 2 -type f -mtime +6 -exec rm -f {} \; -print
31+
find ${logdir} -maxdepth 2 -type f -mtime +6 -exec rm -f {} \; -print

ansible/roles/loggly/files/purgeLogs.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
# Runs from crontab.
66
#
77

8-
LOGDIR=${1}
8+
logdir=${1}
99

1010
# We can compress anything older than 6 hours
11-
find ${LOGDIR} -mindepth 2 -type f -mmin +360 -name '*.log' -exec bzip2 -9 {} \;
11+
find ${logdir} -mindepth 2 -type f -mmin +360 -name '*.log' -exec bzip2 -9 {} \;
1212

13-
# purge anything > 1wk
14-
find ${LOGDIR} -maxdepth 2 -type f -mtime +6 -exec rm -f {} \;
13+
# We automatically purge anything > 1wk
14+
find ${logdir} -maxdepth 2 -type f -mtime +7 -exec rm -f {} \;

0 commit comments

Comments
 (0)