Home > computers > mail > mailboxbackup | About

You need to do two things :

  1. Backup all incoming mail (inbox)
  2. Backup all outgoing mail (sent folder)

There might be many ways to do this and what I'm sharing here is what I've come up with after days and days of struggeling, but it's far from being "right". It's, at best, "acceptable".

Creating backup mailboxes

For each of your users, create a backup mailbox. My choice was that for every user@domain.tld I created a user@backup.domain.tld account, without adding backup.domain.tld to the DNS. It's a pure virtual domain that only postfix knows about and cares to be the final destination for. This also means that nobody from the outside can send mail directly to a backup mailbox, which is what we want. We want rather that mail is sent to user@domain.tld, then, some magic will duplicate that mail do user@backup.domain.tld.

Backing up received mail

I achieved this by putting a filter in every mailbox that CC's any incoming mail to the other mailbox (at backup.domain.tld). This is done in my case by editing the .mailfilter file in the mailboxe's directory (which is read by the Courier MDA).


This is how mail works

So in the case of backup mailboxes, it is the MDA (courier), not the MTA (postfix), that was configured to CC all email intended for user@domain.tld to user@backup.domain.tld. This was done by setting up a filter as told above.

Backing up sent mail

In my case, this time I configured the MTA (postfix) to send a copy of each mail to the backup mailbox by adding a sender_bcc_maps directive to /etc/postfix/main.cf


/etc/postfix/sender_map.cf is a simple flat file like this

user@domain.tld     user@backup.domain.tld

Then you have to invoke postmap on that file,

$ postmap /etc/postfix/sender_bcc_maps

and reload postfix

$ /etc/init.d/postfix reload

At this point, any mail sent from user@domain.tld will also be kept in user@backup.domain.tld. The problem is that, by default, it will go to the inbox. But that's easy to fix: we only need to put a filter in the backup mailbox that will move any received mail from user@domain.tld to the .Sent folder. I did this with courier's mailfilter too.

root@messagerie-test[]~ # cat /var/vmail/mailfilters/backup.algerian-radio.dz/a.chaouche/.mailfilter 

`test -e "$DEFAULT/.Sent" && exit 1 || exit 0`
if ( $RETURNCODE != 1 )
        `maildirmake -f "Sent" $DEFAULT`
        `chmod -R 0700 "$DEFAULT/.Sent"`
        `echo "INBOX.Sent" >> $DEFAULT/courierimapsubscribed`
if (/^From: .*a\.chaouche@algerian\-radio\.dz/:h)
exception {
ID130EndFolder = "$DEFAULT/.Sent/"
to $ID130EndFolder
root@messagerie-test[]~ # 

This filter was generated by an ISPConfig plugin to roundcube (the webmail we're using). It can serve as a boirlerplate to include in a bash script for example (to automate this for all the mailboxes).

The end

contact : @ychaouche yacinechaouche at yahoocom

QR Code
QR Code Creating backup mailboxes (generated for current page)