~ubuntu-branches/ubuntu/karmic/cyrus-imapd-2.2/karmic

« back to all changes in this revision

Viewing changes to debian/cyrus-common-2.2.cron.daily

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2006-12-07 17:31:51 UTC
  • Revision ID: james.westby@ubuntu.com-20061207173151-u34z5dafs5nh9sat
Tags: 2.2.13-9ubuntu1
* Merge with Debian unstable; remaining changes:
  - Build using DB4.3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/sh
2
 
# Cyrus IMAPd daily maintenance script
3
 
# Copyright (c) 2002,2003 by Henrique M. Holschuh
4
 
# $Id: cyrus-common-2.2.cron.daily 229 2005-12-08 23:26:29Z astronut $
5
 
# Distributed under the terms of the GNU General Public License version 2
6
 
#
7
 
# This script:
8
 
#   1. Backups the mailbox database to the portable text format,
9
 
#      and compresses the result.  This backup can be used to restore
10
 
#      the Cyrus mailbox database using ctl_mboxlist (after uncompressing
11
 
#      the backup file).
12
 
#
13
 
#   2. Cleans up any leftover crap in .stage directories.
14
 
#
15
 
#   3. Runs chk_cyrus and outputs warning messages (so that cron
16
 
#      sends them to the administrator) if any problems are detected.
17
 
 
18
 
set -e
19
 
 
20
 
# Make sure we get sane behaviour in broken locales
21
 
LC_ALL=C
22
 
export LC_ALL
23
 
 
24
 
bak=/var/backups
25
 
bakfile=${bak}/cyrus-mboxlist.txt.gz
26
 
CONF=/etc/imapd.conf
27
 
CHKCYRUS=0
28
 
[ -r /etc/default/cyrus2.2 ] && . /etc/default/cyrus2.2
29
 
umask 022
30
 
 
31
 
# 1. backup mailbox database
32
 
[ -x /usr/sbin/ctl_mboxlist ] && {
33
 
        [ -d $bak ] || ( mkdir -p $bak ; chmod 600 $bak )
34
 
        [ -f $bakfile ] && mv ${bakfile} ${bakfile}.bak
35
 
#       su "--command=/usr/sbin/ctl_mboxlist -d" - cyrus | ...
36
 
        start-stop-daemon --start --exec /usr/sbin/ctl_mboxlist --quiet --chuid cyrus -- -d | gzip -9 >${bakfile}
37
 
}
38
 
 
39
 
# 2. clean up all leftover .stage directories in all spools listed in
40
 
#    the default config file
41
 
[ $CHKCYRUS -ne 0 ] && {
42
 
    [ -r "$CONF" ] || {
43
 
        echo $0: unable to read configuration file $CONF. Aborting...
44
 
        exit 1
45
 
    }
46
 
    partitions=$(sed --silent -e "/^[[:blank:]]*partition-[[:alnum:]]\+:/ { \
47
 
            s#^[[:blank:]]*partition-[[:alnum:]]\+:[[:blank:]]*## \
48
 
            p
49
 
            } " < "$CONF" | sort | uniq | xargs)
50
 
    for i in $partitions ; do
51
 
        find "$i" -name '.stage' -type d -print0 | \
52
 
          xargs --null -n 1 -r -i'{1}' \
53
 
            find {1} -type f -ctime +1 -exec rm -f {} \;
54
 
    done
55
 
}
56
 
 
57
 
# 3. runs chk_cyrus
58
 
[ -x /usr/sbin/chk_cyrus ] && {
59
 
        tmpfile=$(mktemp -t cyrus-daily-cronjob.XXXXXXXXXX)
60
 
        trap 'rm -f "${tmpfile}"' 0
61
 
#       su "--command=/usr/sbin/chk_cyrus" - cyrus | ...
62
 
        start-stop-daemon --start --exec /usr/sbin/chk_cyrus --quiet --chuid cyrus >"${tmpfile}" 2>&1 || cat "${tmpfile}" 1>&2
63
 
        rm -f "${tmpfile}"
64
 
        trap '' 0
65
 
}
66
 
 
67
 
exit 0