Backup script for user mailboxes

Discuss the Scalix Server software

Moderators: ScalixSupport, admin

kilrathi
Posts: 14
Joined: Mon Sep 18, 2006 11:05 am

Backup script for user mailboxes

Postby kilrathi » Mon Jun 04, 2007 4:25 pm

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.

kilrathi
Posts: 14
Joined: Mon Sep 18, 2006 11:05 am

Postby kilrathi » Tue Jun 05, 2007 1:37 pm


dbroll

Postby dbroll » Wed Jul 04, 2007 2:26 am

Wow - excellent and simple! Thanks for posting this! Any arguments against using this as a primary way to back up Scalix mailboxes (perhaps nightly) ?

tbone
Posts: 25
Joined: Mon Jan 30, 2006 4:40 pm

Postby tbone » Fri Jul 06, 2007 10:56 am

I guess public folders will be missing ?

Valerion
Scalix Star
Scalix Star
Posts: 2730
Joined: Thu Feb 26, 2004 7:40 am
Location: Johannesburg, South Africa
Contact:

Postby Valerion » Tue Jul 10, 2007 5:40 am

You can add an sxmboxexp -p to the end of the script to export the Public Folders.

kmeyer2
Posts: 62
Joined: Mon Apr 02, 2007 6:11 am

Postby kmeyer2 » Wed Oct 17, 2007 5:42 am

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

charon
Posts: 128
Joined: Sun Jul 01, 2007 5:38 am
Location: Germany
Contact:

Postby charon » Wed Oct 17, 2007 6:30 pm

path variable correctly set?

kmeyer2
Posts: 62
Joined: Mon Apr 02, 2007 6:11 am

Postby kmeyer2 » Thu Oct 18, 2007 3:07 am

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

kanderson

Postby kanderson » Thu Oct 18, 2007 10:30 am

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.

les
Scalix Star
Scalix Star
Posts: 819
Joined: Thu Feb 23, 2006 10:18 am
Location: Sydney, Australia

Postby les » Thu Oct 18, 2007 7:15 pm

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.
Regards,

Les Stott

keywestcity
Posts: 48
Joined: Fri Nov 03, 2006 12:45 pm

Backup to mount

Postby keywestcity » Fri Nov 16, 2007 5:50 pm

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.


Return to “Scalix Server”



Who is online

Users browsing this forum: No registered users and 2 guests

cron