For several weeks, I started a quest to find the best solution to locally backup a Gmail account.

I  tried offline-imap , but it is bidirectional and can push back to your Gmail account local mistakes. Then I played with mbsync , but it doesn’t support sub-folders/tags  .

I finally found the Holy Grail in Gmvault , a recent open-source project especially designed for the task and all its subtleties.

To install it on Ubuntu, starts by getting distribute , a Python dependency:

 1$ sudo pip install --upgrade distribute
 2Downloading/unpacking distribute
 3  Running setup.py egg_info for package distribute
 4Installing collected packages: distribute
 5  Found existing installation: distribute 0.6.24dev-r0
 6    Uninstalling distribute:
 7      Successfully uninstalled distribute
 8  Running setup.py install for distribute
 9    Before install bootstrap.
10    Scanning installed packages
11    Setuptools installation detected at /usr/lib/python2.7/dist-packages
12    Non-egg installation
13    Removing elements out of the way...
14    Already patched.
15    /usr/lib/python2.7/dist-packages/setuptools.egg-info already patched.
16    Installing easy_install script to /usr/local/bin
17    Installing easy_install-2.7 script to /usr/local/bin
18    After install bootstrap.
19    Don't have permissions to write /usr/local/lib/python2.7/dist-packages/setuptools-0.6c11-py2.7.egg-info, skipping
20    Creating /usr/local/lib/python2.7/dist-packages/setuptools-0.6c11-py2.7.egg-info
21    Creating /usr/local/lib/python2.7/dist-packages/setuptools.pth
22Successfully installed distribute
23Cleaning up...

Then install Gmvault itself:

 1$ sudo pip install gmvault
 2Downloading/unpacking gmvault
 3  Downloading gmvault-1.7-beta.tar.gz (73Kb): 73Kb downloaded
 4  Running setup.py egg_info for package gmvault
 5    PATH = /home/kevin/build/gmvault/./src/gmv/gmvault_utils.py
 6    1.7-beta
 7    Gmvault version = 1.7-beta
 8Downloading/unpacking argparse (from gmvault)
 9  Downloading argparse-1.2.1.tar.gz (69Kb): 69Kb downloaded
10  Running setup.py egg_info for package argparse
11    warning: no previously-included files matching '*.pyc' found anywhere in distribution
12    warning: no previously-included files matching '*.pyo' found anywhere in distribution
13    warning: no previously-included files matching '*.orig' found anywhere in distribution
14    warning: no previously-included files matching '*.rej' found anywhere in distribution
15    no previously-included directories found matching 'doc/_build'
16    no previously-included directories found matching 'env24'
17    no previously-included directories found matching 'env25'
18    no previously-included directories found matching 'env26'
19    no previously-included directories found matching 'env27'
20Downloading/unpacking Logbook==0.3 (from gmvault)
21  Downloading Logbook-0.3.tar.gz (89Kb): 89Kb downloaded
22  Running setup.py egg_info for package Logbook
23Downloading/unpacking IMAPClient==0.9 (from gmvault)
24  Downloading IMAPClient-0.9.zip (119Kb): 119Kb downloaded
25  Running setup.py egg_info for package IMAPClient
26    no previously-included directories found matching 'doc/doctrees'
27Downloading/unpacking gdata==2.0.17 (from gmvault)
28  Downloading gdata-2.0.17.tar.gz (2.4Mb): 2.4Mb downloaded
29  Running setup.py egg_info for package gdata
30Installing collected packages: gmvault, argparse, Logbook, IMAPClient, gdata
31  Running setup.py install for gmvault
32    PATH = /home/kevin/build/gmvault/./src/gmv/gmvault_utils.py
33    1.7-beta
34    Gmvault version = 1.7-beta
35    changing mode of build/scripts-2.7/gmvault from 644 to 755
36    changing mode of /usr/local/bin/gmvault to 755
37  Found existing installation: argparse 1.2.1
38    Uninstalling argparse:
39      Successfully uninstalled argparse
40  Running setup.py install for argparse
41    warning: no previously-included files matching '*.pyc' found anywhere in distribution
42    warning: no previously-included files matching '*.pyo' found anywhere in distribution
43    warning: no previously-included files matching '*.orig' found anywhere in distribution
44    warning: no previously-included files matching '*.rej' found anywhere in distribution
45    no previously-included directories found matching 'doc/_build'
46    no previously-included directories found matching 'env24'
47    no previously-included directories found matching 'env25'
48    no previously-included directories found matching 'env26'
49    no previously-included directories found matching 'env27'
50  Running setup.py install for Logbook
51    building 'logbook._speedups' extension
52    gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c logbook/_speedups.c -o build/temp.linux-x86_64-2.7/logbook/_speedups.o
53    logbook/_speedups.c:4:20: fatal error: Python.h: No such file or directory
54    compilation terminated.
55    ==========================================================================
56    WARNING: The C extension could not be compiled, speedups are not enabled.
57    Failure information, if any, is above.
58    Retrying the build without the C extension now.
59    ==========================================================================
60    WARNING: The C extension could not be compiled, speedups are not enabled.
61    Plain-Python installation succeeded.
62    ==========================================================================
63  Running setup.py install for IMAPClient
64    no previously-included directories found matching 'doc/doctrees'
65  Running setup.py install for gdata
66Successfully installed gmvault argparse Logbook IMAPClient gdata
67Cleaning up...

Now for authentication, please read the documentation . It’s quite easy and straightforward.

Finally, to start the backup of your remote Gmail account, just launch:

1$ gmvault sync [email protected] --resume

All you have to do next is to put the command above in a cron job to trigger a regular backup.