23

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?

Braiam
  • 67,791
  • 32
  • 179
  • 269
ændrük
  • 76,794

3 Answers3

25

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 = your_username@gmail.com 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

Jorge Castro
  • 71,754
2

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.

user4124
  • 8,911
0

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.