020be8
#!/bin/sh
020be8
#
020be8
# This file is run on a daily basis to perform a backup of your
020be8
# mailbox list which can be used to recreate mailboxes.db from backup.
020be8
# Restore is done using ctl_mboxlist after uncompressing the file.
020be8
020be8
BACKDIR="/var/lib/imap/backup"
020be8
MBOXLIST="${BACKDIR}/mboxlist"
020be8
ROTATE=6
020be8
020be8
# fallback to su if runuser not available
020be8
if [ -x /sbin/runuser ]; then
020be8
  RUNUSER=runuser
020be8
else
020be8
  RUNUSER=su
020be8
fi
020be8
020be8
# source custom configuration
020be8
if [ -f /etc/sysconfig/cyrus-imapd ]; then
020be8
  . /etc/sysconfig/cyrus-imapd
020be8
fi
020be8
020be8
[ -x /usr/sbin/ctl_mboxlist ] || exit 0
020be8
[ -f /var/lib/imap/db/skipstamp ] || exit 0
020be8
020be8
# rotate mailbox lists
020be8
seq $[ $ROTATE - 1 ] -1 1 | while read i; do
020be8
  [ -f ${MBOXLIST}.${i}.gz ] && mv -f ${MBOXLIST}.${i}.gz ${MBOXLIST}.$[ $i + 1 ].gz
020be8
done
020be8
[ -f ${MBOXLIST}.gz ] && mv -f ${MBOXLIST}.gz ${MBOXLIST}.1.gz
020be8
020be8
# export mailboxes.db
020be8
$RUNUSER - cyrus -s /bin/sh -c "umask 077 < /dev/null ; /usr/sbin/ctl_mboxlist -d | gzip > ${MBOXLIST}.gz"
020be8
020be8
exit 0
020be8
# EOF