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.
AFP548
http://www.afp548.com/article.php?story=2004092303182960