zeek/aux/broctl/bin/archive-log.in
Robin Sommer 2b6ad76bd5 Creating a branch release/1.5 with the current 1.5.3 release code.
This is so that people working from the current stable version can
still start using git.
2011-03-09 15:26:01 -08:00

69 lines
1.3 KiB
Bash
Executable file

#! /usr/bin/env bash
#
# $Id: archive-log.in 6860 2009-08-14 19:01:47Z robin $
#
# Bro postprocessor script to archive log files.
#
# archive-log <rotated-file-name> <base-name> <timestamp-when-opened> <timestamp-when-closed> <terminating> [<tag>]
delete=1
if [ "$1" == "-c" ]; then
delete=0
shift
fi
# We do not keep the logs for workers/proxies.
if [ -e .worker -o -e .proxy ]; then
test $delete = 0 || rm -rf $1
exit 0
fi
terminating=$5
century=`date +%Y | sed 's/..$//g'`
from=`echo $3 | sed 's/[_.]/-/g'`
from="$century$from"
to=`echo $4 | sed 's/[_.]/-/g'`
to="$century$to"
dest=`${makearchivename} $2 $from $to`
echo $dest | grep -q '^/'
if [ $? != 0 ]; then
dest="${logdir}/$dest"
fi
dest_dir=`dirname $dest`
mkdir -p $dest_dir # Makes sure all parent directories exist.
# Record time of last rotation.
date +%y-%m-%d_%H.%M.%S >.rotated.$2 # Bro default format when rotating files.
# Run other postprocessors.
for pp in ${postprocdir}/*; do
nice $pp $@
done
if [ -e $1 ]; then
nice gzip -9 <$1 >$dest.gz 2>/dev/null &
fi
wait
if [ "$?" == "0" ]; then
if [ "$delete" == "1" ]; then
rm -rf $1
else
# Only delete if too large (>100MB).
find $1 -size +104857600c -delete
fi
fi
if [ "$terminating" == "1" ]; then
${scriptsdir}/remove-link-for-log $2
fi