Mar 242011

gmail-backupGmail has become for many the favorite e-mail account, being very comfortable, with plenty of space available and a web interface that can be used through various devices: smartphone, laptop or desktop. But I guess that all of you know already all the advantages of using these email accounts so that they are becoming very important for us … but have you ever thought about making a backup of these mails ?

Yes Google is certainly very capable and reliable, but in the end, you do not have activate a free account with few thing assured ?

And it can happen to delete by mistake from the web interface one or more emails, even in these cases perhaps a backup can save us.

Thus we’ll see three ways to do a backup on your personal computer of all mail in a Gmail account.

1 Use Thunderbird to make a local copy

I use thunderbird as email client because with it i can check my 4 email accounts (not all from Gmail) and so in the past i set up this program to check also my gmail account instead of using the web interface from the browser. But i did a big mistake (from the backup point of view), i used Thunderbird wizard to setup the account and so i set up an Imap account, that means (in short) that if i delete something by mistake on the web the change is reflected also on my PC, also if i’ve already downloaded that message.

So today i’ve switched from imap to pop to do this simply (or to activate a pop account on thunderbird from zero):

0) Log in into your gmail account on the web click on settings in the top right corner, Click on the Forwarding and Pop linktab, Click on Enable Pop for all mail.

Also Click on step number 2 of that window and click on Keep Gmail’s copy in the inbox from the drop down menu, we want to keep a copy of the email on Gmail for our other devices.

1) If you have one delete your imap account on thunderbird, before doing this check the configurations and the sent email folder (i had something in local).

thunderbird_confirm2) Now in Thunderbird go in Edit -> Account setting and click on Add Mail Account, the thunderbird wizard will ask your name, email address and password and will present to you something a window like the one in the screenshot.

So you can see that Thunderbird queries the Gmail server and automatically configures the appropriate IMAP connection settings for your account, but we want POP, so click on Edit, and change the parameters in:

  • Incoming: change to “”
  • Protocol (the drop-down list to the right of the Incoming field): change to “POP”
  • Port (the field to the right of the protocol drop-down list): change to “995”


See also the official google guide at:

So now you are done, when you get the messages from that Thunderbird you’ll save a copy on that PC, leaving the messages also on the server available to others device that can still read them. A perfect solution of backup on your main PC.

2 Use Fetchmail to make a local copy

Perhaps you are fine with the web interface, or you dislike Thunderbird..or for any reason don’t want another Email client to do a simple backup, so here is another simple idea, use fetchmail and dump the content of your Gmail account into a directory of your PC.

About that there is a nice guide of Gina Trapani she has implemented this idea on Windows, that is IMO much more harder, you need a working Cygwin environment and some skill with windows shell.

But let’s see how to do that in Linux.

1) install fetchmail, i expect any distribution to have it so just use your favourite package manager to install it from your distribution repository (I.E aptitude install fetchmail, emerge fetchmail, yum install fetchmail).

2) in your home directory create a new .fetchmailrc file and then, add the following text into it:

#set daemon 600
poll with proto POP3
    user '[email protected]' there with password 'xxxxxxxx' is youruid here
    options keep ssl

Substitute [email protected] and xxxxxxxx with your username and password of Gmail and youruid with your username on Linux.
Change the permission of the file with a

 chmod 600 .fetchmailrc

and test the configuration with

fetchmail -v

This will start fetchmail in verbose mode, if all works fine you should find your email in /var/spool/mail/youruidwith and have message like this on your terminal:

fetchmail: 6.3.17 querying (protocol POP3) at Thu 24 Mar 2011 05:36:02 PM CET: poll started
Trying to connect to
fetchmail: Server certificate:
fetchmail: Issuer Organization: Google Inc
fetchmail: Issuer CommonName: Google Internet Authority
fetchmail: Subject CommonName:
fetchmail: key fingerprint: 6B:C4:63:05:87:1E:72:88:ED:81:C5:A2:51:6B:B7:B6
fetchmail: POP3< +OK Gpop ready for requests from v14pf247455eeh.26 fetchmail: POP3> CAPA
fetchmail: POP3< +OK Capability list follows
fetchmail: POP3< USER
fetchmail: POP3< RESP-CODES
fetchmail: POP3< EXPIRE 0
fetchmail: POP3< LOGIN-DELAY 300
fetchmail: POP3< TOP
fetchmail: POP3< UIDL
fetchmail: POP3< X-GOOGLE-RICO
fetchmail: POP3< . fetchmail: POP3> USER
fetchmail: POP3< +OK send PASS fetchmail: POP3> PASS *
fetchmail: POP3< +OK Welcome. fetchmail: POP3> STAT
fetchmail: POP3< +OK 0 0 fetchmail: No mail for at fetchmail: POP3> QUIT
fetchmail: POP3< +OK Farewell.
fetchmail: 6.3.17 querying (protocol POP3) at Thu 24 Mar 2011 05:36:03 PM CET: poll completed
fetchmail: normal termination, status 1

Cron or Daemon

Now to automate the backup you have 2 choice, put a cron at that run fetchmail every X (every 15 minutes, 1 hours or 1 time at day) or you can uncomment the option

 set daemon 600

in your .fecthmailrc file and configure your graphical environment to run /usr/bin/fetchmail (no options) at the start of your session, this will run fecthmail as Daemon and check for new mail every 600 seconds.

So with fetchmail you’ll have a backup ready if everything goes bad, to use it you’ll need a local email client and import the saved emails.

3 Use Gmail Backup


Gmail Backup it’s a freeware available for Linux and windows that does a local copy of your Imap Gmail account.

Thanks to David that pointed this problem in the comments:

The main branch of gmailbackup won’t work for you as it needs python 2.5 and you are likely to have python 2.6 so refer to the following forum comment:

Description from the site
This program is aimed to backup and restore of your GMail mailbox. You will need to activate the IMAP access to your mailbox, to do so, please open your GMail settings and under POP/IMAP tab activate this option.

The messages are stored in the local directory in files which names follow the format YYYYMMDD-hhmmss-nn.eml where YYYY is the year, MM the month number, DD is the day number, hh are hours, mm are minutes and ss are seconds when the e-mail was SENT. For the case there is more emails with the same timestamp there is the number nn which starts with value 1. Label assignment is stored in the file labels.txt which is the plain text file and it pairs the emails stored in the file described above with the assigned labels.

I’ve not tested this solution, the last update of the site is of 2 years ago, but the forum seem active.
To use it on Linux you’ll need the wxPython (

[amazon_enhanced asin=”B004HO62HA” price=”All” background_color=”332610″ link_color=”FFFFFF” text_color=”D4CE99″ /]

Popular Posts:

Flattr this!

  11 Responses to “Gmail backup with Linux”

  1. You can also use commandline tools like imapsync or imap2mbox to back up your mailbox.

  2. To run on a modern GNU/Linux system you will need to install wxpython
    …or search your distros repositories.

    The main branch of gmailbackup won’t work for you as it needs python 2.5 and you are likely to have python 2.6 so refer to the following forum comment:

    Please, original article author, do your homework and put things like this in the article so users don’t need to dig them out!

    • Thanks David,
      Added your comment as Note in the Gmail-backup solution, as wrote i did not tested it this solution, next time i’ll try to do a better homework 😉

  3. You can also leave Thunderbird in IMAP mode but select “keep a local copy” for the folders you want.

  4. What are the methods of restoring data from those backup back onto GMail?
    Backup means nothing without restore.

    • Hello DarkDuck.
      You have reason, i though that the operation was easy enough..but it’s not true.
      There are different methods to recover the emails saved into your Gmail account.

      Very simple one: use Thunderbird redirect extension (i just checked this and it work).

      Download and install it in your Thunderbid (from
      Select the message you want to restore and “redirect” them to your Gmail account (for Mutt and Eudora users this is a bounce).

      With redirect the email will keep their original headers so you’ll see them as coming from the original From and at the original date, you’ll just have extra headers “Resent XXXX” like Resent From ,Resent To and Resent Date, these are the Headers of the Redirect operation, have these extra headers it’s an acceptable cost for me when recovering from a big disaster :).

      There are others methods like import the mbox to the imap mbox of Gmail, but seem more long and complicated and perhaps the tool is not anymore supported (NOT tested by me):

      I hope this is clear enough, otherwise i can do a small article with screenshots.


  5. Good post, thank you!!
    Just correct “aptitude install fecthmail” as “aptitude install fetchmail”


  6. Nice article for backup our Gmail accounts!!

    Backup your Gmail account easily on Mac, Linux & Windows in very handy way with Beyond Inbox. Its a software to backup, archive, organize, transfer and restore your email for Gmail, IMAP & Google Apps.

    Beyond Inbox is available in two different flavors i.e. an easy User Interface using which you use all its feature like backup, restore,copy and move and Command line interface using which you can schedule the backup .

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>