#!/bin/sh
# $Id$
# Compress files generated by the CruiseControl process.
# Call this script from a cron job, as follows:
#
## # 4 AM: find all build logs more than 13 days old and compress them
## 00 04 * * * $HOME/open/bootstrap/compress-logfiles.sh

# Set LOGDIR to a sensible default.
if [ ! "$LOGDIR" ]; then
   export LOGDIR=$HOME/web/logs
fi

if [ ! -d "$LOGDIR" ]; then
   echo "Variable LOGDIR is not set or is not valid directory."
   exit 1
fi

# Find all files more than 13 days old and compress them.
find $LOGDIR -maxdepth 2 -daystart -mtime +13 \
 -not -name "*.bz2" \
 -not -name currentbuildstatus.txt \
 -type f \
 -exec bzip2 {} ";" 

# If the directories contain no .xml files (because the last build was more
# than 13 days ago), decompress the most recent .xml.bz2
for i in $(find $LOGDIR/* -type d -maxdepth 0); do
   if [ "$(echo $i/*.xml)" = "$i/*.xml" \
         -a "$(echo $i/*.xml.bz2)" != "$i/*.xml.bz2" ]; then
      mostRecent="$(ls $i/*.xml.bz2 | tail -1)"
      if [ -f "$mostRecent" ]; then
         echo "There are no .xml files in $i; compressing the most recent .xml.bz2, $mostRecent"
         bzip2 -d "$mostRecent"
      fi
   fi
done

# End


Add script to compress old build artifacts, while keeping the most recent.
BOOTSTRAP: Add script to compress old build artifacts, while keeping the most recent.

[git-p4: depot-paths = "//open/dt/dev/": change = 2748]
