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