Print Friendly

So, today I decided to set about the task of backing up my Gmail to my home server. I pay Google for 99% uptime, and really don’t expect their service to fail, but I have to account for more likely scenarios. For example, I may conceivably delete a message and find out I need it later; or, I may not want to keep a message on Gmail anymore but still need to retain it.

The players in this setup are a server running CentOS 5.2 and Gmail itself. My plan is to create a cron job that backs up the email at some fixed interval (daily) and saves it to a folder. At some point, I will back that up to DVD in case I or Gmail lose everything one day.

Gmail Backup runs on Windows and Linux. Gmail Backup does something that fetchmail or other solutions fail to provide: your Gmail labels are actually stored. This made it appear to be a better solution overall, so I decided to give it a whirl.

It is written in Python and requires Python to run on Linux (the Windows version is compiled). Unfortunately for me, the Python that comes with CentOS 5.2 is Python 2.4.3 and Gmail Backup requires Python 2.5.

I could just rip out the Python 2.4.3 libraries and replace them with Python 2.5 libs, but that would create problems for some of CentOS’s native utilties. So, I’ve installed Python 2.5 and wxpython in a different directory on my server and pointed Gmail Backup at the correct Python files.

According to the documentation, I just needed to run:

gmail-backup.sh backup my-backup-directory gmail-username gmail-password

The first attempt at running Gmail Backup met with failure:

Error: IMAP: [ALERT] Invalid credentials (Failure)

which I realized was because the shell was not escaping the ! in my password, so I changed the password.

Then I got:

ValueError: time data did not match format:  data=XXXXX  fmt=%Y%m%d

The XXXXX was the last half of my new password, which had a space in it. I consider this a bug in the implementation of Gmail Backup. I’ll contact the author with a fix later. So, I removed the space from my password.

That did it. Off I went. Gmail Backup nicely put my email into a directory. Each message is stored as a text file in directories indexed by year and date. All of the labels are stored in a text file.

Restoring to Gmail is as easy as:

gmail-backup.sh restore my-backup-directory gmail-username gmail-password

With a little scripting and a cron job, now I can automate Gmail Backup with a script, having it create periodic backups of all of my messages, then compressing the backup directory into one big file for storage and offloading.

Thanks Gmail Backup for making this so much easier!