Backup Gmail Account on Ubuntu - A Step-by-Step Guide

The Importance of Backing Up Your Web-Based Email
It’s frequently emphasized how crucial data backups are, yet the practice of backing up web-based email accounts is often overlooked. We’ve previously demonstrated methods for backing up Gmail accounts utilizing Windows applications. However, what options are available for users operating on a Linux system?
Backing Up Gmail on Linux with Getmail
While programs like GMVault and Thunderbird can be employed for Gmail backups in Windows, Thunderbird is also available for Linux. Alternatively, Linux users can leverage a dedicated program called Getmail, which consolidates their Gmail account into a single mbox file. Getmail is compatible with all Linux distributions.
Ubuntu users can conveniently install Getmail through the Ubuntu Software Center. For other Linux operating systems, download Getmail directly from the website and consult the provided installation instructions.
Installing Getmail in Ubuntu
To begin, launch the Ubuntu Software Center using its icon on the Unity bar.
In the Search box, type "getmail" (without quotation marks). Search results will appear dynamically as you type. Select the "Mail retriever" result and then click the Install button.
A dialog box requesting authentication may appear. Enter your password and click Authenticate.
Upon completion of the installation process, exit the Ubuntu Software Center by selecting Close from the File menu, or by clicking the 'X' button on the title bar.
Preparing the Configuration
Prior to utilizing Getmail, it’s necessary to establish a configuration directory, a directory to house the mbox file, and the mbox file itself. Open a Terminal window by pressing Ctrl + Alt + T. Then, execute the following command to create the default configuration directory:
mkdir --m 0700 $HOME/.getmail
To create a directory specifically for the mbox file – which will store your Gmail messages – use the following command. We’ve named ours "gmail-archive," but you are free to choose any name you prefer.
mkdir --m 0700 $HOME/gmail-archive
Next, create the mbox file itself to contain the downloaded messages. Getmail does not automatically generate this file. Enter the following command at the prompt:
touch ~/gmail-archive/gmail-backup.mbox
Note that both "$HOME" and "~" represent your home directory, typically located at /home/.
Keep this Terminal window open; you will need it later to execute Getmail.
Configuring Getmail for Your Gmail Account
Now, you must create a configuration file to inform Getmail about your Gmail account details. Open a text editor, such as gedit, and copy the following text into a new file:
[retriever]
type = SimplePOP3SSLRetriever
server = pop.gmail.com
username = yourname@gmail.com
password = yourpassword
[destination]
type = Mboxrd
path = ~/gmail-archive/gmail-backup.mbox
[options]
verbose = 2
message_log = ~/.getmail/gmail.log
Replace "yourname@gmail.com" and "yourpassword" with your actual Gmail credentials. If you opted for a different directory and filename for the mbox file, adjust the "path" entry within the "destination" section accordingly.
Select Save As to save your configuration file.
In the Name edit box, enter ".getmail/getmailrc" (without quotation marks) to save the file as the default configuration file within the directory you created. Then, click Save.
Close gedit, or whichever text editor you utilized.
Running Getmail and Completing the Backup
To initiate Getmail, return to the Terminal window and type "getmail" (without quotation marks) at the prompt.
A series of messages will appear in the Terminal window as Getmail commences downloading the contents of your Gmail account.
If the process is interrupted, do not be alarmed. Google imposes limitations on the number of messages that can be downloaded from an account at any given time. Simply rerun the Getmail command to resume the download where it left off. Refer to Getmail’s FAQs for further details regarding this issue.
Once Getmail completes its operation and returns you to the prompt, you can close the Terminal window by typing "exit," selecting Close Window from the File menu, or clicking the 'X' button on the title bar.
Importing and Automating Your Backups
You will now possess an mbox file containing your Gmail messages. This file can be imported into most email clients, with the exception of Microsoft Outlook.
For instance, you can utilize the ImportExportTools add-on in Thunderbird to import your Gmail messages from the mbox file into a local folder.
If you require access to your Gmail messages within Outlook on Windows, the free MBox Email Extractor program can convert your mbox file into individual .eml files, which can then be imported into Outlook.
To automate the backup process, you can create a shell script and schedule it to run using a cron job, executing daily, weekly, or at any frequency you deem appropriate.
For comprehensive information regarding Getmail’s functionality, consult its official documentation.