Page 1 of 1

Backup script for user mailboxes

Posted: Mon Jun 04, 2007 4:25 pm
by kilrathi
Since we first installed Scalix I've been looking for a simple solution for backing up our users mailbox without having to mirror file systems, bring down the mailserver, or any of that. I just wanted a simple script that would pull the messages and put them in one place for each user. From what I've seen so far there are a few different ways to accomplish that. I took bits and pieces from all of those and made my own backup script for my users. Since most of the information I used to accomplish this came from this forum I decided I would share. I am not taking any credit for any of the code. This is simply my own rendition of many different backup options.


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
done


I 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.

Posted: Tue Jun 05, 2007 1:37 pm
by kilrathi

Posted: Wed Jul 04, 2007 2:26 am
by dbroll
Wow - excellent and simple! Thanks for posting this! Any arguments against using this as a primary way to back up Scalix mailboxes (perhaps nightly) ?

Posted: Fri Jul 06, 2007 10:56 am
by tbone
I guess public folders will be missing ?

Posted: Tue Jul 10, 2007 5:40 am
by Valerion
You can add an sxmboxexp -p to the end of the script to export the Public Folders.

Posted: Wed Oct 17, 2007 5:42 am
by kmeyer2
I got problems with omshowu and sxmboxexp - I've created a backup-script.sh and when I started it, it works fine.
But as I tried to start it with the crontab - the commands omshowu and sxmboxexp are not working. Is there anyone who has the same problems?
the script ist located in the diretory /etc/init.d/sxbackup.sh
crontab user is root

- as I tried without logfile, the system told me that sxmboxexp - command not found
..the same for omshowu

- as I tries with logfile (/backup/backup.log) it was startet - and the next message - backup compleded.

:?:

Scalix 11.1 / Open Suse 10.1

BR Amok

Posted: Wed Oct 17, 2007 6:30 pm
by charon
path variable correctly set?

Posted: Thu Oct 18, 2007 3:07 am
by kmeyer2
Hi charon,

how can it be?
As I call
/etc/init.d/sxbackup.sh it works fine!
the crontab call the same , the script is starting, but the script does not do the job at that moment.

???
Help would be fine..

BR Amok

Posted: Thu Oct 18, 2007 10:30 am
by kanderson
As already indicated, this will be a path problem. The easiest way to fix that is to specify the whole path to both sxmboxexp and to omshowu.

They'll be in /opt/scalix/bin/<whatever command>

Kev.

Posted: Thu Oct 18, 2007 7:15 pm
by les
kmeyer2 wrote:Hi charon,

how can it be?
As I call
/etc/init.d/sxbackup.sh it works fine!
the crontab call the same , the script is starting, but the script does not do the job at that moment.

???
Help would be fine..

BR Amok


cron uses a different variables and runs a more limited shell as opposed to when you run it logged in as root.

It is better to explicitly define your commands with full pathnames.

Backup to mount

Posted: Fri Nov 16, 2007 5:50 pm
by keywestcity
I was able to take this a step further and backup the mailboxes to a mounted drive on my NAS.

-Create a folder in /mnt called nas

-Create a mount to the NAS

mount -t cifs -o username=blabla //(nas ip, or name)/(share name) /mnt/nas

Mine looked like this. My username is vbackup, my share on the NAS is backup.

mount -t cifs -o username=vbackup //10.10.x.x/backup /mnt/nas

-create a folder on the NAS called tape1 or monday1. whatever you like..

-the drive path in the script will be /mnt/nas/tape1

Now you won't fill up your server with data because the backups are written directly to the NAS.