Articles September 23, 2004 at 3:18 am

OS X Server 10.3 Mail Backup

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

No Comments

  • Thanks, Works a treat!!!!

  • I usually don’t use spaces in drive names, especially with Server.

    However, having said that, I should pay more attention to that in scripts.

    Changing the world, one server at a time.

    Joel Rennich

  • Awesome! I didn’t expect to find anything like this, but there it was, first
    Google hit.

    Much appreciated.


  • 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,

  • 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!

  • Although, I have *not* tested it on 10.4 – there’s no reason why it shouldn’t
    work. The script doesn’t cover the new features of the Mail service on Tiger
    though – SpamAssassin and ClamAV. If you want this stuff backed up too, edit
    the script to copy their config files (/etc/clamav.conf, /etc/freshclam.conf, /etc/
    amavisd.conf and /etc/mail/spamassassin/ You may also want to look at
    /var/amavis which stores some of SpamAssassin’s automagic/dynamic config and
    auto-whitelist entries.

Leave a reply

You must be logged in to post a comment.