HowTos/BackupScript Mbox Style

From Scalix Wiki
Jump to: navigation, search

Scalix Wiki -> How-Tos -> BackupScript Mbox Style

MBOX Style Backup Script for Scalix v11

This is a shell script I use to backup all my users to a single flat file (mbox style). I then backup the directory to an offisite location for disaster recovery purposes.

This script backs up all user mailboxes into a single flat file (mbox style) in the directory specified (MBOXDIR). I backup those .mbox files to an offsite archive for disaster recovery purposes. Every time you run this script it will look in the directory specified for an existing .mbox file. If it finds one it will delete it first, then create a new .mbox file from the Scalix Server. This was written for Scalix Server v11. I do not know know how well it will work with earlier versions.


Added $SXDIR variable for simpler customization and better cron compatibility (paths may not be set up)

Added nice -n 19 so the backup script plays nice with running jobs (lowest priority)

Added public folders example

Added some echos for better legibility (+++++++ now separates users)


#! /bin/bash

# Edit the following two values if necessary
# No more editing after this line

echo "Mailbox Backup Starting [`date`]"
if [ -d $MBOXDIR ]; then
     echo "Found Backup Directory ${MBOXDIR}. Using It."
    echo "Creating Backup Directory ${MBOXDIR} to backup mailboxes."
    mkdir -p ${MBOXDIR}
for i in $(${SXDIR}/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 +++++++++++++++++++++++++++++++++++++++++++++
    echo ${user}
    if [ -a $MBOXDIR/$i.mbox ]; then
        echo "Existing backup found.  Deleting before creating new backup."
        rm -f ${MBOXDIR}/${user}.mbox
    echo "Backing up user ${user}"
    nice -n 19 ${SXDIR}/sxmboxexp -u "${user}" -a ${MBOXDIR}/"${user}".mbox --listlevel folder -F
    echo +++++++++++++++++++++++++++++++++++++++++++++
    echo "Finished backing up user data."
    echo "Backing up public folders..."
    if [ -a $MBOXDIR/public_folders.mbox ]; then
        echo "Existing backup found.  Deleting before creating new backup."
        rm -f ${MBOXDIR}/public_folders.mbox
    nice -n 19 ${SXDIR}/sxmboxexp -p -a ${MBOXDIR}/public_folders.mbox --listlevel folder -F
    echo "Done with mailbox backup! [`date`]"

Cron Job

I run this script every week on my mail server. I decided to run it every saturday at 1am since that is when the least amount of users are logged into my system. I also decided to send the output to a new log file each week. I named my backup script Here is what my cron job looks like.

0 1 * * 6 /backup/scripts/ > /var/log/mailbox_backup[`date '+%m.%d.%Y'`].log

Now I can look in /var/log at the backup log for each week and verify that each individual users mailbox was backed up completely. Each log file will also have a date stamp in the filename for quick reference.