Friday, March 21, 2008

Make a Local Backup Of Your Gmail Account

Make a Local Backup Of Your Gmail Account
From Wired How-To Wiki
Jump to: navigation, search

Web-based e-mail services like Gmail, Yahoo Mail or Windows Live Mail are great for their access-anywhere capabilities.

The ease and simplicity of checking your mail in a browser have caused many of us to ditch the desktop client in favor of a web-based interface. It's one less application to have running and, in case of Google's Gmail, the search capabilities and conversation threading blow desktop apps out of the water.

However, using a service like Gmail means you don't have a local backup of your e-mail like you would get if you were using a desktop client. Naturally, that doesn't mean you can't store backups of your e-mail on your local machine. It requires a bit of work to set up, but once you do, you'll be able to enjoy the goodness of Gmail's web interface worry-free.

This page is a wiki. Got extra advice? Log in and add it.

Other pages in this series need your help:

* Make a Local Backup Of Your Yahoo Mail Account
* Make a Local Backup Of Your Hotmail Account


Contents
[hide]

* 1 Backup Gmail Using a Desktop Client
o 1.1 Set Up Gmail & Thunderbird
* 2 Backup Gmail Using Getmail
o 2.1 Installing Getmail
o 2.2 Setting Up Getmail
o 2.3 Running Getmail
o 2.4 Backup Using Fetchmail

Backup Gmail Using a Desktop Client

All the major operating systems ship with a built in e-mail client. Some are better than others, but all of them can connect to your Gmail account and download your messages to create a local copy of your mailbox.

Beware that some of these apps may store mail in funky proprietary formats (Apple Mail, Outlook, we're looking at you here) rather than industry standard formats like .mbox. To guarantee cross platform compatibility, we recommend the Mozilla Thunderbird client. Thunderbird 2.0 even offers a handy one-click set up for accessing Gmail.

First, you'll need to futz with Gmail's settings.


Set Up Gmail & Thunderbird
The unofficial logo of your latest desktop hack
The unofficial logo of your latest desktop hack

Step 1. Go to the Gmail web interface and click the Settings link at the top right corner of the page. Look for the "Forwarding and POP/IMAP" tab and click the link.

Step 2. Now you need to enable either POP or IMAP. For most people, POP will work just fine and it's the simpler of the two. Just select the "Enable POP for all mail" option. You'll also notice that you can control what Gmail does when your desktop client connects under the "When messages are accessed with POP" setting. Choose "keep Gmail's copy in the Inbox" since we're just using POP for backup purposes.

Step 3. Now startup Thunderbird, enter your username (the bit before @gmail.com in your e-mail address) and Google password. Thunderbird will begin downloading your e-mail, creating a local backup. There's no need to mess with Thunderbird's settings or since you're just doing this for backup purposes.

Tip: Remember to open Thunderbird periodically so that your mail gets backed up.

Tip: Make a backup of your Google Calender as well using the two-way sync add-on for Mozilla Sunbird.

Tip: Make Thunderbird look like a native Apple app by installing REO-2007's Leopard Mail skin.

While this method will work and is definitely the easiest for most people, there are some drawbacks. The most obvious is that the backup doesn't include your sent mail. If you're looking for a way to improve your backups and automate the process (and you don't mind a little command line tinkering), read on.
Backup Gmail Using Getmail

Getmail is an open source Python program that can backup your Gmail account. Getmail will work on any *nix system, including OS X, and even Windows as long as you have Cygwin installed.


Installing Getmail

Ubuntu users have it easy, since Getmail is in the Ubuntu repositories.

For other operating systems, you can either add the repository to aptitude or you can compile from the source like so:

Download Getmail, then open a terminal windows and type:

tar xzvf getmail*.tar.gz cd (the directory that was created) sudo python setup.py install


Setting Up Getmail

Now you just need a configuration file to tell Getmail how to connect to Gmail. There are a ton of sample configuration files on the Getmail site, but here's one that works well with Gmail. Create a file at ~/.getmail/getmail.gmail and put the following text in it:

[retriever]
type = SimplePOP3SSLRetriever
server = pop.gmail.com
username = yourname@gmail.com
password = yourpassword

[destination]
type = Mboxrd
path = ~/gmail-archive/gmail-backup.mbox

[options]
verbose = 2
message_log = ~/.getmail/gmail.log

Getmail won't create the mbox file, so before we get started, create a new empty file called gmail-archive.mbox in the gmail-archive folder of your home directory (or where ever you choose to store it). From the command line this will do the trick: touch ~/gmail-archive/gmail-backup.mbox


Running Getmail

You have everything set up, so it's time to actually make the backup. Fire up a terminal window and enter the following line:

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. If the script stops, fear not -- Google has some limits on how many messages can be retrieved at one time. Just run the above command again the Getmail will pick up where it left off. See Getmail's documentation for more about this "cutoff" issue.

Now you have an mbox-formatted local backup of your Gmail account and you can access it with any e-mail client that understands mbox files, which is pretty much everything except Microsoft Outlook.

To automate this process, just create a shell script and attach it to a cron job that runs once a day or however often you feel is necessary.


Backup Using Fetchmail

Backing up using Fetchmail is probably the most difficult and arcane option of the bunch, but if you're looking for a weekend project and enjoy tinkering with the command line, Fetchmail can create backups of your Gmail account.

Have a read through the Fetchmail documentation to see how you need to set things up.

Also check out Lifehacker's excellent tutorial on Fetchmail. It's written for Windows users running Fetchmail under Cygwin, so if you're on a *nix system just ignore the Cygwin-specific elements.

1 comment:

Unknown said...

Mozilla does in fact download my sent mail.