#!/bin/sh
#
# Archives the log files of ovirt
# usage:
# ovirtlogrot.sh <log directory> <max log age in hours>
#

logdir=$1
maxage=$2
dateformat="+%Y%m%d_%H"

date=`date $dateformat`

for i in `ls $logdir/engine.log.* -t`; do
 m=`expr match $i .*gz`
 if [ $m == 0 ]
 then
  cat $i | gzip -9 > $i-$date.gz && rm $i
 fi
done;

#
# remove the old logs
#

lastlogday=`date -d "$maxage hours ago" $dateformat`
for i in `ls $logdir/engine.log.*.gz`; do
 timestamp=`echo $i | sed s/.*-// | sed s/\.gz//`
 if [[ "$lastlogday" > "$timestamp" ]]
 then
  rm -f $logdir/engine.log.*$timestamp.gz
 fi
done


#!/bin/sh
#
# Archives the log files of ovirt
# usage:
# ovirtlogrot.sh <log directory> <max log age in hours>
#

logdir=$1
maxage=$2
dateformat="+%Y%m%d_%H%M%S"

date=`date $dateformat`

for i in `ls $logdir/engine.log.* -t`; do
 m=`expr match $i .*gz`
 if [ $m == 0 ]
 then
  cat $i | gzip -9 > $i-$date.gz && rm $i
 fi
done;

#
# remove the old logs
#

lastlogday=`date -d "$maxage hours ago" $dateformat`
for i in `ls $logdir/engine.log.*.gz`; do
 timestamp=`echo $i | sed s/.*-// | sed s/\.gz//`
 if [[ "$lastlogday" > "$timestamp" ]]
 then
  rm -f $logdir/engine.log.*$timestamp.gz
 fi
done

Change the timestamp of log rotation.
packaging: Change the timestamp of log rotation.

Changed the timestamp of the log rotation to make it more clear to a
user when the log was rotated.

Change-Id: I1d115f9ade4bd49245f4b26e7d96b8df582d110c
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=889751
Signed-off-by: Kiril Nesenko <c377644256f2520ee68af386b25c50ac247ee8aa@redhat.com>
