Gmvault is a powerful open source cross-platform application that makes Gmail backup and restore a really easy job.
The feature that I like the most, is that you give and revoke access to the application using OAuth authentication
Installation instructions
Go throught the Quick Start Guide in order to configure some settings inside your Gmail account.
Try the following (tested on Linux Mint 17. I suppose there will be no difference in Ubuntu):
sudo apt-get install python python-setuptools
wget https://bitbucket.org/gaubert/gmvault-official-download/downloads/gmvault-v1.8.1-beta-src.tar.gz
tar xvzf gmvault-v1.8.1-beta-src.tar.gz
cd gmvault-1.8.1-beta/
sudo python setup.py install
gmvault sync [email protected]
You will need to run through the authentication process first and then the backup process will begin.
Gmvault can also restore your Gmail account or export your backup database in different format. Make sure that you go through the documentation to see all the available options.