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
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
13
# 2. Cleans up any leftover crap in .stage directories.
15
# 3. Runs chk_cyrus and outputs warning messages (so that cron
16
# sends them to the administrator) if any problems are detected.
20
# Make sure we get sane behaviour in broken locales
25
bakfile=${bak}/cyrus-mboxlist.txt.gz
28
[ -r /etc/default/cyrus2.2 ] && . /etc/default/cyrus2.2
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}
39
# 2. clean up all leftover .stage directories in all spools listed in
40
# the default config file
41
[ $CHKCYRUS -ne 0 ] && {
43
echo $0: unable to read configuration file $CONF. Aborting...
46
partitions=$(sed --silent -e "/^[[:blank:]]*partition-[[:alnum:]]\+:/ { \
47
s#^[[:blank:]]*partition-[[:alnum:]]\+:[[:blank:]]*## \
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 {} \;
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