Code: Select all
#! /bin/bash
echo "Mailbox Backup Starting [`date`]"
MBOXDIR="/backup/mailboxes"
if [ -d $MBOXDIR ]; then
echo "Found Backup Directory. Using It."
else
echo "Creating Backup Directory ${MBOXDIR} to backup mailboxes."
mkdir ${MBOXDIR}
fi
for i in $(omshowu -m all | cut -d "/" -f 1 | sed -e 's: $::g' -e 's/ /\//g'); do
user=`printf "$i" | sed -e 's:/: :g'`
#
# $user = Username With Space
# $i = Username With \ Before Space
# ex: $user="Firstname Lastname"
# ex: $i="Firstname\ Lastname"
#
echo ${user}
if [ -a $MBOXDIR/$i.mbox ]; then
echo "Existing backup found. Removing before creating new backup."
rm ${MBOXDIR}/${user}.mbox
fi
echo "Backing up user ${user}"
sxmboxexp -u "${user}" -a ${MBOXDIR}/"${user}".mbox --listlevel folder -F
doneI simply run this script in a cron job ever week and send the output to /var/log in a log file I check every week to ensure the backup was complete. I also backup the mail folder this script dumps the mailboxes to offsite for disaster recovery purposes. Questions / Suggestions are welcome and thanks to all the people who help out here. Without you guys I could not solve half of the problems that crop up.
