wilde: utils/admin save-annotations.sh,NONE,1.1

cvs at intevation.de cvs at intevation.de
Tue Jan 24 11:36:42 CET 2006


Author: wilde

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

Added Files:
	save-annotations.sh 
Log Message:
Added some more explanations to the comments for BACKUP_DIR and USER.


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

# -------------------------------------------------------------------
# Copyright (C) 2006 by Intevation GmbH
# Author(s):
# Sascha Wilde <wilde 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-annotations.sh,v 1.1 2006/01/24 10:36:39 wilde Exp $

# Description:

# Backup and check annotations db.

# As the kolab/cyrus-imap annotations.db tends to break on a regular
# basis, this script should be setup as a cronjob.

# This script:
# - backups the annotations.db
# - checks if the backup file is a valid skiplist db
# - informs the admin if it isn't
# - removes old backups if everything worked fine

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

# These variables shall be configured:

# Error-reports will be send to this address:
ADMIN_MAIL=root at localhost

# Error-reports will have this from address:
ERROR_SENDER=postmaster@`hostname -f`

# Path to annotations.db:
ANNOTATIONSDB=/kolab/var/imapd/annotations.db

# Directory of the backups:
# This must be writeable for $USER (see below)
BACKUP_DIR=/tmp/backuptest/

# Keep backup files for N days:
BACKUP_LIVESPAN=7

# Run this script as user:
# The user must be able to read $ANNOTATIONSDB and to write to $BACKUP_DIR
USER=kolab-r

# Used Binaries:
CVT_CYRUSDB=/kolab/bin/cvt_cyrusdb

# Command used:
# - to copy annotations.db to backup
COPY="/usr/bin/rsync"
# - to compress file, for no compression leave empty
COMPRESS="/bin/gzip -9"

# sendmail used to send error-reports
# THIS HAS TO BE CORRECT OR ANY ERROR-REPORTING WILL FAIL!!!
SENDMAIL=/kolab/sbin/sendmail

# -------------------------------------------------------------------
# Nothing to configure past this point...

BACKUP_FILE="${BACKUP_DIR}/annotations.db-`date +%Y%m%d-%H:%M:%S`"

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

# Error handling functions:
reporterr()
{
  $SENDMAIL $ADMIN_MAIL \
    <<EOF 
From: Save Annotations Script <${ERROR_SENDER}>
To: <${ADMIN_MAIL}>
Subject: Save Annotations Error
X-Save-Annotations-Error: generated on $HOSTNAME

$0 reported error:
$1
EOF
}

fatal()
{
  reporterr "$1"
  exit 1
}

# Worker functions:
backup-annotations()
{
  [ -d "$BACKUP_DIR" ] || mkdir -p "$BACKUP_DIR"
  $COPY >/dev/null 2>&1 "$ANNOTATIONSDB" "$BACKUP_FILE" || \
    fatal "FATAL: \"$COPY $ANNOTATIONSDB $BACKUP_FILE\" failed with returncode $?"
}

check-backup()
{
  temp_file="${BACKUP_DIR}/.tempflatdb"
  # beware this takes a few seconds!
  $CVT_CYRUSDB "$BACKUP_FILE" skiplist \
    "$temp_file" flat >/dev/null 2>&1 && \
    rm $temp_file
}

compress-backup()
{
  if [ "$COMPRESS" ] ; then
    $COMPRESS >/dev/null 2>&1 "$BACKUP_FILE" || \
      reporterr "Compression failed: \"$COMPRESS $BACKUP_FILE\" returened $?"
  fi
}

expunge-old-backups()
{
  find "$BACKUP_DIR" -type f \! -mtime -$BACKUP_LIVESPAN \
    -exec rm \{\} \;
}

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

if [ -f "$ANNOTATIONSDB" ] ; then
  backup-annotations
  check-backup
  check_success=$?
  if [ ! $check_success -eq 0 ] ; then
    reporterr "BROKEN DB: check of $BACKUP_FILE failed.  
Kolab most likely stoped working!"
    mv "$BACKUP_FILE" "${BACKUP_FILE}_CORRUPT"
    BACKUP_FILE="${BACKUP_FILE}_CORRUPT"
  fi
  compress-backup
  [ $check_success -eq 0 ] && \
    expunge-old-backups
else
  fatal "FATAL: File \"$ANNOTATIONSDB\" does not exist."
fi





More information about the commits mailing list