Contribute  :  Advanced Search  :  Directory  :  Forum  :  FAQ's  :  My Downloads  :  Links  :  Polls  
AFP548 Changing the world one server at a time.
Welcome to AFP548
Thursday, July 29 2010 @ 09:23 am MDT
   

OS X Server 10.3 Mail Backup

ArticlesScript to backup both Postfix and Cyrus on OS X Server 10.3

Get the backup script here and read more to find out how to use it.

If you have an automated backup system, or if you are just looking for a quick and dirty way to back up your mail store, you should be careful to stop the mail server before copying the spool files. While a lot of people get away without doing this, you always put yourself at a little bit of a risk whenever that happens.

I had a script up on the site to backup the 10.2 mail server. However, as you know if you have used the new mail server, 10.3 is significantly different than 10.2. We now have to worry about a spool file for both Postfix, which does the SMTP part of the mail system, and Cyrus, which handles the POP/IMAP part.

Some of the process got a lot easier in 10.3 with the addition of the serveradmin command. In 10.2 the script had to manually edit the watchdog config file so that watchdog didn't restart the mail system before the backup was done. Now serveradmin takes care of all of that.

The only real ugly part in the script right now is a line that starts Postfix by hand after running the serveradmin command to start the whole mail system. Although we shouldn't have to do this, serveradmin should do both Cyrus and Postfix but it sometimes doesn't. There shouldn't be any detrimental effects from running the two commands. Even if the first one works.

Right now the script will backup the Postfix spool, which contains incoming and outgoing SMTP mail, the Cyrus spool file, which contains all of your user's e-mail boxes, and the Postfix config files, everything in /etc/postfix.

Currently the script requires you to hand edit some variables at the top if you keep your Cyrus spool in a custom directory. I hope to add this functionality into a command line variable, and have started doing that, but it doesn't seem to work that way yet.

The script uses rsync for your Cyrus spool and ditto for the Postifx spool. Rysnc does an actual sync between the old and the new, so should be quite efficient, especially in heavy IMAP situations. I'd have used rysnc for the Postfix spool, but there are a few funky files in there that rsync doesn't like. Perhaps in a latter verions I'll code those files out since I don't think they matter for the backup. Either way you shouldn't have too much in your Postfix spool, and you most likely won't have anything in there that hasn't changed in 24 hours.

So, here's how to use it.

sudo mailback -b /Volumes/XRAID/mailbackup -p

This command will sync the spool folders and /etc/postfix to /Volumes/XRAID/mailbackup

sudo mailback -r /Volumes/XRAID/mailbackup

Will pull the Postfix and Cyrus spools from the backup, but it will not rewrite /etc/postfix since -p was not specified.

mailback -help

Will return a quick usage summary.

Once you have it downloaded you should put it somewhere in your path, /usr/sbin is as good a place as any. Make sure you make the script executable and then add it into your routine.

If you have any additions to this please let me know as I'd be happy to incorporate them into future versions.

Story Options

Advertising

OS X Server 10.3 Mail Backup | 15 comments | Create New Account
The following comments are owned by whomever posted them. This site is not responsible for what they say.
OS X Server 10.3 Mail Backup
Authored by: Anonymous on Friday, September 24 2004 @ 04:38 pm MDT
WOW! Thank you MacTroll. I needed this and I found it. Go afp548.com...
OS X Server 10.3 Mail Backup
Authored by: mrowell on Sunday, September 26 2004 @ 10:07 pm MDT
Thanks, Works a treat!!!!
OS X Server 10.3 Mail Backup
Authored by: Anonymous on Friday, October 01 2004 @ 03:03 pm MDT
I got this error, even thouh it looks like it worked:

./mailbak: line 145: syntax error near unexpected token `fi'
./mailbak: line 145: `fi'
OS X Server 10.3 Mail Backup
Authored by: Anonymous on Tuesday, October 19 2004 @ 12:48 pm MDT
Had a little trouble with this script.

If your volume name has more than one word then the $BACKUP_DIR variable
on line 115 needs to be quoted, I think.

For me the script now runs without error but still does not work, the backup
folder is created but no files are copied.
OS X Server 10.3 Mail Backup
Authored by: Kayners on Wednesday, October 20 2004 @ 02:37 pm MDT
Awesome! I didn't expect to find anything like this, but there it was, first
Google hit.

Much appreciated.

Steve.
OS X Server 10.3 Mail Backup
Authored by: superhenne on Tuesday, May 31 2005 @ 05:57 am MDT
Hi, thanks for this great script - i use it regularly and it works just fine. I added two things - the absolute path for /usr/sbin/serveradmin as it was needed when the script runs from cron.

I also added a size report - it gives a nice cron mail after each backup:

echo "Mailbox Sizes:"
du -h -d 2 /var/spool/imap/


i got some questions - is it possible to just restore one mailbox without touching the others? does a restore delete mails received after the mail store was backed up? kind regards, hendrik
OS X Server 10.3 Mail Backup
Authored by: kcarlile on Thursday, June 23 2005 @ 07:02 pm MDT
Thank you for the script! Just one note-ditto doesn't overwrite the folders, so your backup folders can go quite large... I added a line to my crontab to delete the folders 2 minutes before the script runs. If anyone has a better idea, I'd love to hear it!
OS X Server 10.3 Mail Backup
Authored by: Anonymous on Tuesday, August 16 2005 @ 12:28 pm MDT
How does this work on 10.4?
thanks
Authored by: Anonymous on Monday, September 05 2005 @ 01:03 pm MDT
Just stopped in for a visit...Great site! We'll visit again soon.