Using getmail to backup Gmail on Linux

Posted on 2011/07/17

8


Even though Gmail has been proven quite reliable over the years, there have been isolated episodes of data loss. In any case, I backup my mail locally: better safe than sorry. On my Linux machine I use “getmail” to download my mail through POP and store it in a single “mbox” file. First of all, I enabled POP on my Gmail account: went into Gmail Settings, clicked the “Forwarding and POP/IMAP” tab, ticked “Enable POP for all mail“, and chose “When messages are accessed with POP keep Gmail’s copy in the Inbox”.

Then I installed getmail, and prepared the environment. getmail by default uses a “~/.getmail” directory to work, and in particular it searches for a “~/.getmail/getmailrc” file to read the configuration. So I created this file, together with an empty mbox file that I will use to hold all my mail.

$ mkdir ~/.getmail
$ touch ~/.getmail/gmail.mbox
$ touch ~/.getmail/getmailrc

Then I edited the “~/.getmail/getmailrc” to contain this information:

[retriever]
type = SimplePOP3SSLRetriever
server = pop.gmail.com
username = "mymail"@gmail.com

[destination]
type = Mboxrd
path = ~/.getmail/gmail.mbox

After this setup, I simply run “getmail” from the command line, it asks for the Gmail password and retrieves all the mail it can through the POP protocol. I had to run it several times before it downloaded everything.

It is also possible to include  a password in this file, but I don’t want to keep my Gmail password inside an unencrypted file. The downside is that every time I run getmail I have to insert my password. Since I update my backup once a week, that is not a big issue. By putting the password inside the configuration file it is also possible to run a “cron” job such as “su username -c getmail” that backups the mail by itself.

About these ads
Posted in: Internet