Backup Gmail via IMAP using getmail
I have not been blogging for QUITE some time, ever since I started my internship back in December. After every day’s 8 hours work, I became very lazy and hardly had any motivation to write.
Today, actually I just got tipped by a very informative introduction on how on back up Gmail using getmail. I improved it a little bit and finally find my way of backing up my Gmail messages, which I’ve since long wanted to accomplish.
The detail of the HOWTO please refer to the author’s blog. What I want to mention is that, since a single .mbox file is too big while Maildir way produces so many small files (which is hard to manage and even harder to move them across disks), maybe it’s a better idea to backup all of the mails into several middle-sized .mbox files.
Using Gmail’s filter and label feature, all of the mails can be easily grouped in many different ways. I used “Quarter” as a unit, therefore I only need to put a search keyword like “after:2007/1/1 before:2007/3/31″ into the search field and apply a new label (e.g. FY07Q1) to all of the mails in the search result. Then I change the configuration of getmail into:
[retriever] type = SimpleIMAPSSLRetriever server = imap.gmail.com username = username password = password mailboxes = ("FY07Q1",) [destination] type = Mboxrd path = ~/.getmail/gmail-backup-FY07Q1.mbox
Notice, according to the documentation of getmail, the .mbox file specified in the configuration file
must already exist and appear to be a valid mboxrd file before getmail will try to deliver to it — getmail will not create the file if it does not exist. If you want to create a new mboxrd file for getmail to use, simply create a completely empty (0-byte) file.
After finishing downloading a batch of mail, just modify the configuration(or create another one) to proceed to another batch of mails.
That’s it, I guess getting very excited about being able to easily backup my gmail is the very reason why I added this post after 4 months without writing anything. Thanks again to Matt Cutts for such a useful howto. (which triggered me to note something down)
P.S. As IMAP reciever is used in my case, I didn’t come across the limite to the number of mails for downloading mentioned in the original howto, which is resulted when using getmail with the POP3 method.