thomas: utils/admin save-mailboxinfo.sh,NONE,1.1

cvs at kolab.org cvs at kolab.org
Fri Jun 22 18:33:59 CEST 2007


Author: thomas

Update of /kolabrepository/utils/admin
In directory doto:/tmp/cvs-serv15349

Added Files:
	save-mailboxinfo.sh 
Log Message:
Wrapper around kolab-mailboxinfo to be run from crontab


--- NEW FILE: save-mailboxinfo.sh ---
#!/bin/bash

# -------------------------------------------------------------------
# Copyright (C) 2006, 2007 by Intevation GmbH
# Author(s):
# Sascha Wilde <wilde at intevation.de>
# Thomas Arendsen Hein <thomas at intevation.de>

# This program is free software under the GNU GPL (>=v2)
# Read the file COPYING coming with the software for details.
# -------------------------------------------------------------------
# $Id: save-mailboxinfo.sh,v 1.1 2007/06/22 16:33:57 thomas Exp $

# Configuration can be done in /kolab/etc/imapd/skiplistsafe.conf
# Don't change anything in this script!

# -------------------------------------------------------------------

ADMIN_MAIL=root at localhost
ERROR_SENDER=postmaster@`hostname -f`
BACKUP_LIVESPAN=30
USER=kolab
SENDMAIL=/kolab/sbin/sendmail
MAILBOXINFO=/kolab/sbin/kolab-mailboxinfo.pl

BACKUP_DIR="/kolab/var/kolab-mailboxinfo"
BACKUP_FILE="${BACKUP_DIR}/`basename $BACKUP_DIR`-`date +%Y%m%d-%H%M%S`"
BACKUP_LATEST="${BACKUP_DIR}/latest"

# Change identity if necessary
if [ `whoami` != "$USER" ] ; then
  if [ $UID -eq 0 ] ; then
    exec su -p - $USER "$0" "$1"
  else
    echo >&2 "$0 must be run as $USER or root!"
    exit 1
  fi
fi

# Error handling functions:
report()
{
  $SENDMAIL $ADMIN_MAIL \
    <<EOF 
From: Kolab Mailboxinfo Script <${ERROR_SENDER}>
To: Kolab Admin <${ADMIN_MAIL}>
Subject: Kolab Mailboxinfo for `hostname -f`

$0 reported:
$1
EOF
}

backup()
{
  [ -d "$BACKUP_DIR" ] || { mkdir -p "$BACKUP_DIR"; touch "$BACKUP_LATEST"; }
  $MAILBOXINFO > "$BACKUP_FILE"
  if diff -u "$BACKUP_LATEST" "$BACKUP_FILE" >/dev/null; then
    # no differences
    rm "$BACKUP_FILE"
  else
    report "`diff -u "$BACKUP_LATEST" "$BACKUP_FILE" | grep '^[+-][^+-]'`"
    cp "$BACKUP_FILE" "$BACKUP_LATEST"
    gzip -9 "$BACKUP_FILE"
  fi
}

expunge-old-backups()
{
  find "$BACKUP_DIR" \
    -type f -name "`basename $BACKUP_DIR`-*.gz" -mtime +$BACKUP_LIVESPAN \
    -exec rm \{\} \;
}

# -------------------------------------------------------------------
# Main routine:

backup
expunge-old-backups






More information about the commits mailing list