HowTos/BackupScript Mbox Style

From Scalix Wiki
Revision as of 21:01, 4 June 2007 by Kilrathi (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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.

Script

#! /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

done

End Script