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