Back up Cyrus IMAP email and configuration

Q I am running a mail server at home (SUSE 9.3) with Cyrus as an IMAP server. It's the best thing there is. It fetches my emails, runs them through two virus scanners and sends them to my Cyrus server. I can read my mails on my desktop and my notebook, and using SquirrelMail I can read my emails from all over the world. But... I accidentally deleted a full mailbox and I didn't have a backup. How do I back up my email and configuration, and how do I restore them? I could back up the /var/spool/imap directory, but that would only back up my emails. To restore them, I have to make a new subdirectory using my IMAP client, copy the emails in there and reconstruct the mailbox. But that doesn't backup the configuration. So how do I do this?

A Backing up the emails and backing up the configuration are two separate tasks. The configuration is the easy part, as it is all stored in /etc/imapd.conf and /etc/cyrus.conf. As long as you keep a backup of these files you can copy them back at any time. Backing up the mail should be as simple as creating a copy of /var/spool/imap - this contains the emails and their status information. I use rdiff-backup for this sort of task. It will back up a directory to another location, either locally or over the network. It also allows you to roll back to a previous version, although this is more appropriate for configuration files than mailboxes. You could also use rdiff-backup to maintain backups of your configuration. Put these lines in a script and call it from Cron:

$BACKUP_DIR="/backup"
rdiff-backup --terminal-verbosity 2 /etc $BACKUP_DIR/etc
rdiff-backup --terminal-verbosity 2 /var/spool/imap $BACKUP_DIR/imap

Set $BACKUP_DIR to wherever you keep your backups. If you want to keep archived copies of your emails, you could use a procmail recipe to copy a duplicate of the mail to another mailbox, providing you are already using procmail of course. Something like

:0c:
$MAILDIR/${LOGNAME}-bak/

will create a backup directory for each user and place a copy of each mail in there.

Follow us on Identi.ca or Twitter

Username:   Password:
Create Account | About TuxRadar