BaGoMa - A script to Backup Google Mail.
bAgOmA - A script to backup a bag o' mail.
This software comes in two flavors:
Or, for the CLI-phobic:
BaGoMa backs-up and restores the contents of a GMail account. It can restore all the labels (folder structure), as well as the flags (seen/read, flagged) of a message. It differs from other similar solutions in a few important ways:
It is Open Source Software. You can read the code to make sure your password and email contents remain private.
Some backup solutions force you to use only ASCII characters in your labels. BaGoMa has no such restrictions on label names. Specifically, foreign characters and '/' (the label hierarchy delimiter) are allowed.
BaGoMa is tuned to work specifically with GMail. Each message is only downloaded and saved once. Backup solutions that are designed to work with regular IMAP accounts will download each message multiple times (once per label) when used to back up a GMail account. That can significantly increase the bandwidth requirements and the amount of storage required for backup. Additionally, a faithful restoration of your GMail account might not be possible from such a backup.
BaGoMa requires your GMail account to be IMAP accessible. Check the Mail Settings and make sure "Enable IMAP" is selected under the "Forwarding and POP/IMAP" tab. In the "Folder Size Limits" section on the same tab, make sure the following option is selected: "Do not limit the number of messages in an IMAP folder".
BaGoMa never deletes any email from your account. A restore simply compares the contents of your local backup with the contents of your GMail account, and uploads any messages missing from your GMail account. It never deletes messages from GMail to make it match the local backup.
Google sometimes imposes limits on how much data can be transfered from your account. If you run into such a limitation, just wait a few days and try the backup again. BaGoMa will pick up from where it left off. If the temporary loss of IMAP access is critical to you, think twice before using this script. As far as I'm aware, web access to your email should continue unimpeded even if IMAP access is blocked.
show a help message and exit
the email address to log in with (MANDATORY)
the password to log in with (will prompt if missing)
the backup/restore directory [default: same as email]
the action to perform: backup, restore, compact, printIndex or debug. [default: backup]
The function of the backup and restore actions should be obvious.
BaGoMa retains all backed up messages, even if they are no longer present on the GMail server during a subsequent backup. The compact action will compact the local storage by deleting all such messages.
The printIndex action displays all the meta-information BaGoMa operates on. This action is primarily intended for developers.
The "debug" action is also intended for developers and drops the user into an interactive python session.
When combined with the compact action, shows what files would be deleted without actually deleting them.
the GMail server to use [default: imap.gmail.com]
the IMAP port to use for GMail [default: 993]
the console log level (DEBUG, INFO, WARNING, ERROR, CRITICAL) [default: WARNING]
the log file (set it to 'off' to disable logging) [default: log.txt]
the config file to use for options not specified on the command line. See below for more details.
show the version number
There's nothing really to install. Once you unpack the downloaded package, you'll find the bagoma.py script in the top directory. On Linux you can run the script directly. On Windows, you'll need to install python first (if you don't already have it) from python.org, CygWin, or ActiveState, then from a DOS or CygWin shell:
python bagoma.py [options]
Man page can be viewed with:
man -l man/bagoma.1
For those that know what they're doing:
python setup.py install
It's usually not a good idea to provide the password on the command line. When BaGoMa is used from a script (cron job), the recommended solution is to create a configuration file and use it to store the password. The configuration file uses the ini format with the email address as the section. For example:
[firstname.lastname@example.org] pwd = pass1 [email@example.com] pwd = pass2
BaGoMa will NOT backup any of the following:
The IMAP protocol does not provide a trully unique ID for an email message (UIDVALIDITY + UID doesn't count). In order to determine that message A in folder P is the same as message B in folder Q (and only needs to be downloaded once), the script computes its own unique ID using the following header fields:
Two messages that have identical values (ignoring whitespace) for all of the fields enumerated above are considered to be identical and will only be downloaded and saved once. The chance of two messages having the same Message-Id header field is pretty slim. The chance of all the header fields mentioned above being identical is almost 0.
Latest version available at:
Project homepage is at:
The source code is hosted both on SourceForge.net and on GitHub at
http://github.com/gburca/BaGoMa. Collaboration will be easier on GitHub.
imaplib library is used to do the heavy lifting. In addition to the official
imaplib documentation, some other useful information can be found at:
If you want to help, see the TODO file.
Bugs can be reported at the project's SourceForge page. Better yet, provide patches to fix the bugs.
Bug reports should include relevant portions of the log file.
Copyright (C) 2011 by Gabriel Burca. License GPLv3+: GNU GPL version 3 or later
http://gnu.org/licenses/gpl.html. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.