Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to setup a new mail server for my personal use, and I want to do it better than all the prior times.

One thing that has always concerned me is backing up my inbox and other folders. In the past, I've used POP3 with Mozilla App Suite / SeaMonkey as my client, and always found it problematic to do backups, since partial backups were very problematic (short of storing the messages based on a year, and renaming and moving stuff around (and then never moving them around again), which is difficult to script on Windows anyways, and limits you to yearly backups, which get annoying to do). Also, the setup was tied to a single PC, another thing I want to avoid.

I'm now thinking of going with Dovecot IMAP4, and backing up mbox and other folders on the server with git, on a weekly, daily, hourly or per-message basis.

With git and several mbox files (mail folders), if an email moves from one mbox to another (e.g. arrives in Inbox, then gets moved to a folder), will git find out all such cases of various emails moving to various folders?

Does backing up imap mbox files with git sound feasible? Practical? Is it a good idea at all? Will it work, and will it be relatively easy to setup?

Or should I drop mbox, and go with maildir? Would git be better with maildir at all?

share|improve this question

I'm not aware of anyone using git for backups of mailboxes/maildirs...

I'm using local rsync into another folder to make backups, i guess the git versioning would only make a mess on the destination folder.

Go with Dovecot and IMAPv4 along with Maildir in home directory to store your mails, it's faster in most scenarios and you will save yourself from possible locking issues.

share|improve this answer
When you say to go with Maildir in home directory, do you imply that in /var/mail, it can still be an mbox? One of the reasons I want to use git instead of rsync is to ensure no tampering, and also to ensure to keep all the backups without using any extra space (not sure whether rsync could handle partial moves of content from one file to another like git is supposed to). – cnst Feb 1 '13 at 2:24
The location doesn't make any difference, whether is in /var/mail or /home/user/maildir the format can still be MBOX or Maildir. As for git it doesn't make sense to use it only to get the partial updates, you get only the versioning with incremental deltas, but I still believe that it's a big overhead, especially if you have large mail archives. rsync is good that it does partial file updates but it doesn't keep track of earlier versions of the same file (main difference with git). – Martino Dino Feb 1 '13 at 2:35
Well, I'm not going to be sending letters to myself through imap, and I was thinking about using sendmail for incoming mail, hence the question of whether mbox and maildir can be mixed. Also, I'm not sure you realise just how efficient git commit is, so, don't discount git from the job just because it allows you to go back to any point. – cnst Feb 1 '13 at 3:05

I back up my remote IMAP mails in a local Maildir directory which is version-controlled by git. It's a bit geeky and hackish, but I think it's a good way if you don't want to lose any emails and want to be safe even if you accidentally delete a bunch of mails on your remote IMAP. The script which does the job works the following way:

  • All remote mails on the IMAP server are synchronized with a local Maildir directory. I use imapsync for this.
  • The mail files in this local Maildir are then copied to a version controlled git-Maildir directory. The original directory structure is not retained, as this is not important to me. Instead, the git-Maildir contains a folder for every year and the mail files are copied to the year folder based on the Date-header of the mail file. I use mu (mailbox utils) to do the sorting work.
  • In the next step, the script automatically adds and commits the new files to the git repository.

With this, I have a local backup of all my emails. Even if I delete mails on remote side, I still have local copies. The advantage of the local git repository is data safety. Even I mess with my files in my local backup, I have a full history in the commit history and I can recover deleted mails.

The advantage of maildir over mbox is, that with maildir you have one file for each mail instead of one huge mbox file which changes every time you add new mails. One file per mail makes a nice git history.

share|improve this answer
That is interesting. Since this answer is now "old", what is the experience so far? The script of yours, is just a simple bash script? – Nikos Alexandris Apr 6 '15 at 17:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.