Backup GMail
11/6/2011Google might disable an account for a number of reasons. Accounts may be disabled because Google requires real names or because an algorithm decided an account was being used to spam. Accounts can be locked and users are left at the mercy of Google's weak customer service.
The official recovery process requires befriending a Google employee and begging. I love Google, but they have taken some rightful lumps for their utter lack of anything resembling support.
It would be a nightmare to lose the data in my Gmail account. Everything is stored in email so I have recently gotten serious about keeping a complete local copy of my mail archives. The easiest way to copy mail from Google is by using IMAP, and the best IMAP archiver is offlineimap.
Offlineimap is meant to take an IMAP folder offline for later reading by copying the contents of the IMAP server to a MailDir folder, which is an older Unix standard that organizes emails into local mail folders. Once copied locally, the mail folder can be read by any number of email programs. At it turns out, this is also awesome for making backups.
To install, simply apt-get install offlineimap
on Debian-based
systems like Ubuntu, or brew install offlineimap
on the mac.
Next, create an ~/.offlineimaprc
file with the details for your
accounts. Here’s the configuration I used:
[general]
accounts = gmail
[Account gmail]
localrepository = Local
remoterepository = Remote
[Repository Local]
type = Maildir
localfolders = ~/backup/mail
sep = /
[Repository Remote]
readonly = True
type = Gmail
remoteuser = your@email
sep
defaults to a “.”, but using / means the backup mail folder will
be compatible with more email programs. I have set readonly
on the
remote GMail because I am using this for backup purposes, I don’t want
offlineimap to make any changes to the IMAP server.
Lastly, you might not want to sync all of the labels in the account. Some folders, like “trash” or “spam” don’t need to be restored. Since I don’t use IMAP to access my account, I simply went into the email settings and unchecked “Show in IMAP.” Otherwise, you may specify a function to filter folder names like this:
folderfilter = lambda name: name.lower() not in ['trash', 'spam']
Thanks to Avdi Grimm for following up with what he used to backup his email. Don’t forget to schedule the backup to periodically run, and be sure to use the Google Takeout service to backup other data you may have with Google (though sadly it seems to not work with Google Apps).