Home > Linux > Backup your Gmail account with getmail

Backup your Gmail account with getmail

December 29, 2011 Leave a comment Go to comments

For almost a year now I am using Gmail as a client to access all my mail accounts. In this article I am going to describe how to make backups of you Gmail account with getmail. Getmail is a simple, yet powerful console tool that downloads your mails and of course it is written in Python. Also because it makes a backup of the mails in an mbox-formatted file, you can access them with many mail clients (like Thunderbird) that support this format.

After installing it (for Debian: “sudo apt-get install getmail4”) you just have to create a file named “~/.getmail/getmail.gmail” that will contain the followings:

type = SimplePOP3SSLRetriever
server = pop.gmail.com
username = yourname@gmail.com
password = yourpassword
type = Mboxrd
path = ~/gmail-archive/gmail-backup.mbox
verbose = 2
message_log = ~/.getmail/gmail.log

Here you can find some other examples on how to write the above configuration file.

Also you have to create the empty mbox file, “~/gmail-archive/gmail-backup.mbox”, that will contain your backed-up mails.

Then, go to the Gmail’s settings and select from the “Forwarding and POP/IMAP” tab, “Enable POP for all mail (even mail that’s already been downloaded)”. Also make sure to select for the “When messages are accessed with POP”, “keep Gmail’s copy in the inbox”.

Now you are ready to backup your Gmail account.
In order to do that, run the following command in the terminal:

getmail -r ~/.getmail/getmail.gmail

You should see a long string of messages begin printing out as getmail starts grabbing the contents of your Gmail account.
Because Google has some limits on how many messages can be retrieved at one time you will have to run the command several times to retrieve all the mails.
Or just run something like the following:

# run the getmail command 1000 times
for i in `seq 1 1000`;
    getmail -r ~/.getmail/getmail.gmail

It would be useful to auto-backup your mails periodically. Personally, I made a cronjob that checks for new mails hourly.
To do so, run:

crontab -e

And at the end of the document, add the following line:

@hourly /usr/bin/getmail -r path-to-your-home-folder/.getmail/getmail.gmail

See also:
Why getmail and not fetchmail?
Gmail silently destroys mail

Credits to:

Categories: Linux
  1. anthonyvenable110
    December 29, 2011 at 07:44

    this was great it is always good to have options

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s