Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'd like to automate the process of locally backing up my Gmail account, and am looking for a solution that:

  • can be scheduled to run in the background
  • does not cause messages to be marked as read

What resources are available for doing this in Ubuntu?

share|improve this question

3 Answers 3

up vote 26 down vote accepted

offlineimap Install offlineimap is a popular solution for this.

Enable IMAP in GMail

(Google's instructions)

  1. Sign in to Gmail.
  2. Click Settings at the top of any Gmail page.
  3. Click Forwarding and POP/IMAP.
  4. Select Enable IMAP.
  5. Configure your IMAP client and click Save Changes.

Setup offlineimap

After you install it create a .offlineimaprc

[general]
accounts = GMail
maxsyncaccounts = 3

[Account GMail]
localrepository = Local
remoterepository = Remote
autorefresh = 10  #refresh every 10 minutes
quick = 5         #Quick-syncs do not update if the only changes were to IMAP flags

[Repository Local]
type = Maildir
localfolders = /whatever/directory

[Repository Remote]
type = IMAP
remotehost = imap.gmail.com
remoteuser = [email protected]
remotepass = your_password
ssl = yes
maxconnections = 1

#Setting realdelete = yes will Really Delete email from the server.
#Otherwise "deleting" a message will just remove any labels and 
#retain the message in the All Mail folder.
realdelete = no 

Then you need to run offlineimap.

Automating offlineimap with cron

In some cases having offlineimap running all the time can consume large amounts of memory, especially if you have a large mailbox, so you can add an offlineimap check into cron to just check it and then exit, here's a daily backup:

 @daily offlineimap -u Noninteractive.Basic

Backing up offlineimap

The files will be in whatever you define in the localfolders line as a Maildir. You can back this up using whatever backup method you use:

References

share|improve this answer

An alternative would be to use fetchmail. fetchmail can use both pop3s and imap4s to access Google. There are online tutorials on how to configure.

share|improve this answer

I have done some research on HOW TO backup an IMAP account comparing different available tools w.r.t. a set of wanted features and concerns. As a result, I used offlineimap, as already suggested above. (My saved comparison still may be useful to see a bigger picture.) Also, I summed up (answering a related question) some points concerning the architecture of such a solution for backing up an IMAP account and storing it in Git.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.