How can I backup my gmail email in Linux?
This how-to uses IMAP to connect to your gmail account. If you haven’t already, make sure to enable IMAP in the gmail settings!
1. Ok now install getmail in Ubuntu:
sudo apt-get install getmail4
2. Next make the configuration directory .getmail in your home directory:
3. Inside that directory, create the following config file:
Here is my example config file:
[retriever] type = SimpleIMAPSSLRetriever server = imap.gmail.com username = email@example.com password = yourgmailpassword mailboxes = ("Inbox", "[Gmail]/Sent Mail") # optional - leave this line out to just grab inbox [destination] type = Mboxrd path = ~/.getmail/gmail-backup.mbox [options] verbose = 2 message_log = ~/.getmail/getmail.log
4. Close and save that file. One last thing:
5. Now run getmail. This may take a long time (30 minutes or more) depending on how much mail you have.
getmail -r ~/.getmail/gmailimap.getmail
How do I backup my sent mail separately? Or another folder?
Making a separate config file with this, for example, backs up only your sent folder:
[retriever] type = SimpleIMAPSSLRetriever server = imap.gmail.com username = firstname.lastname@example.org password = yourgmailpassword mailboxes = ("[Gmail]/Sent Mail",) [destination] type = Mboxrd path = ~/.getmail/gmail-backup-sent.mbox [options] verbose = 2 message_log = ~/.getmail/gmail.log
For an alternative config, you could as well just grab the ‘All Mail’ folder to get everything in one big blob:
mailboxes = ("[Gmail]/All Mail",)