Yesterday’s article was written giving instructions on how to back up all your email accounts using some pretty simple techniques. In the end, Thunderbird was the agent that we used to grab all the email from our gateway account. Today, I’d like to show you how we can accomplish the same thing with a different service called Gmail Backup.
Rather than copy and paste all of yesterday’s article to this one, please read that article and come back to this one. The only difference will be in step 3, which is the step in which we’re actually pulling email to the local machine.
New Step 3
The previous method used POP to download email. This step will use a different protocol called IMAP. Here’s the info you’ll need for enabling IMAP on your gateway account. Once you’ve got IMAP enabled, you need to download the Gmail Backup program, available for Windows or Linux. Once you have your client of choice, jump to the appropriate section below for instructions on setting up the client.
Generic Setup
For the most part, this software can be used uniformly across multiple platforms. If you want to use the GUI version in Linux, you need to install the WxPython packages (python-wxgtk2.8 in Ubuntu). You can also run it from the command line in any platform. With command line access comes the ability to script and schedule updates! The command line version may also work on OS X, but the GUI version doesn’t (yet).
GUI Version
I’ll just walk through this once, since it’s the same for both platforms. After installing (or extracting) Gmail Backup, launch the executable. If you’re on Linux, you want to run the gmail-backup-gui.sh file. You’ll be presented with a window like this one:
Fill in the first three text boxes in the GUI. If you only want to grab email for a date range, you can specify that in the Since Date and Before Date fields. This will allow you to grab email from only a certain timeframe, which makes it easier to archive your email by month.
Once you’ve got your archive, you can put it in your Dropbox or another safe location.
Linux – Command Line
I want to spend more time on this part because, let’s face it, I’m lazy and I like having things done for me. When run from the command line, the Linux variant of Gmail Backup can be be extremely powerful. You can easily set up Cron jobs to run the backup at a defined interval and use command line arguments to drill down to exactly what you want and where you want to place the backup.
1. Install Dropbox (optional)
If you plan on using Dropbox to store your backups, you can find Linux Dropbox packages here. When you’re run Dropbox and have defined a folder to use, you can proceed.
2. Tweak Command
In the folder you extracted from the Gmail Backup archive, you’ll find gmail-backup.sh. There are a number of command line arguments you can pass to this bash script. Whichever method you choose, you should consider appending 2>&1 /dev/null at the end because the command will generate a considerable amount of output. I only recommend doing this AFTER you’ve run it successfully so you know that it’s doing what its supposed to.
a. Cumulative Backup
For a cumulative backup (i.e. everything), simply use the following.
./gmail-backup.sh backup /path/to/backup/dir gateway@gmail.com password
b. Incremental Backup
Here’s a shot of what the file structure should look like on your disk (this is all in my home directory).
Incremental backups are more useful and easier to organize. Here’s the syntax for that.
./gmail-backup.sh backup /path/to/backup/dir/subdir gateway@gmail.com password 20081001 20081031
The last two arguments specify a start and end date for archiving. This example will archive everything from October 1, 2008, to October 31, 2008. But how do you calculate those dates in Bash, you ask?
You can use the –date parameter of the date command to get past and future dates. For instance, if you want to run a backup of your email for the last week (not including today, obviously), you can do something like this:
./gmail-backup.sh backup /path/to/backup/dir/subdir gateway@gmail.com password `date +%Y%m%d --date="7 days ago"` `date +%Y%m%d --date="1 day ago"`
I realize that’s pretty ugly, but it does the trick. If you’re ambitious enough to use a wrapper to get full control over directories, timeframes, etc., you can use something similar to this.
3. Insert Into Cron
This is the easy part – all you have to do is decide on a frequency and then make sure your $sd variable in the bash script matches that. If you run it every week, $sd should go back 7 days; if you run it every month, it should go back 1 month, etc. The command to run the script every Sunday at midnight:
0 0 * * 7 cd /home/mark/email_backup; ./gmail-backup.sh;
Restoring Archives
It’s important that I tell you that you can also restore backups made this way. However, I feel that it’s outside of the scope of this article. For info on that, check out the documentation page of Gmail Backup’s website.





