On Mon, 05 Mar 2018 08:36:46 +0000, ultred ragnusen wrote:
> What's a good way to back up Gmail when you've reached the size limit?
>
http://wetakepic.com/images/2018/03/03/gmail_bck_01.jpg
Posting from Ubuntu this time, where I tested this only once and then
wrote up this Getmail method for folks to benefit from, use, and improve.
Any suggestions for improvement are welcome.
****************************************************************************
Begin:
How to back up Gmail using Linux getmail (20180306)
****************************************************************************
----------------------------------------------------------------------------
1. Obtain getmail
$ sudo apt-get update
$ sudo apt-get upgrade --show-upgraded
$ sudo apt install getmail4
----------------------------------------------------------------------------
2. Create the expected directory structure to store your backed up email
$ mkdir -p $HOME/data/gmail_backup/maildir/{tmp,new,cur}/
Note: Individual new messages go into the "new" folder by default.
Note: File naming conventions are horrid, so this is only for grepping.
1520396141.M145874P16035Q3833R12cacf4d693f5e01.a
1520396142.M419693P16037Q3834Rc180fe3eea7ba34d.a
1520396143.M470613P16039Q3835Rd7678c2a01a32bf4.a
1520396144.M374454P16041Q3836R6312b258b4a6a8f2.a
etc.
Note: I'm not sure what tmp and current are actually for, but
examples of creating them abound on the net, so I made them.
----------------------------------------------------------------------------
3. Define the mbox file (this file must exist prior to running getmail)
$ touch $HOME/data/gmail_backup/backup.mbox
----------------------------------------------------------------------------
4. Link an empty (for now) config file where getmail expects it
$ mkdir $HOME/.getmail/
$ touch $HOME/data/gmail_backup/backupgmail.getmailrc
$ ln -s $HOME/data/gmail_backup/backupgmail.getmailrc \
$HOME/.getmail/backupgmail.getmailrc
Note: I'm not sure if this is really necessary, but people did it.
----------------------------------------------------------------------------
5. Create the getmail configuration file [retriever] section:
$ vi $HOME/data/gmail_backup/backupgmail.getmailrc
#########################################################################
[retriever]
#########################################################################
# Note: Getmail syntax doesn't allow inline comments unfortunately.
# Note: Getmail syntax doesn't allow leading spaces unfortunately.
# Note: Getmail syntax supports $HOME despite no examples on the net.
# Note: If you want pop, you must first enable it on the Gmail servers.
# type = SimplePOP3SSLRetriever # POP with SSL (throttled & just inbox)
# type = SimpleIMAPRetriever # IMAP without SSL
# type = SimpleIMAPSSLRetriever # IMAP with SSL (use this)
type = SimpleIMAPSSLRetriever
# server =
pop.gmail.com # the pop server
# server =
imap.gmail.com # the imap server
server =
imap.gmail.com
port = 993
# username =
your...@gmail.com # your gmail username
username =
yourus...@gmail.com
# password = yourpasswd # your gmail password
password = abcdefg
# If you comment out mailboxes, the default is just the inbox
# mailboxes = ("[Gmail]/Sent Mail",) # special label for sent mail
# mailboxes = ("Inbox", "[Gmail]/Sent Mail") # special label for inbox &
sent
# mailboxes = ("[Gmail]/All Mail",) # special label for all mail
mailboxes = ("[Gmail]/All Mail",)
----------------------------------------------------------------------------
6. Create the getmail configuration file [destination] section:
$ vi $HOME/data/gmail_backup/backupgmail.getmailrc
#########################################################################
[destination]
#########################################################################
# type = MultiDestination # allow backup to more than one place
type = MultiDestination
destinations = ('[mboxrd-destination]', '[maildir-destination]')
[mboxrd-destination]
# type = Mboxrd # this tells it to get the monolithic mbox file
type = Mboxrd
# path = $HOME/data/gmail_backup/backup.mbox # the flie must exist prior
path = $HOME/data/gmail_backup/backup.mbox
[maildir-destination]
# type = Maildir # this tells it to also get individual mail messages
type = Maildir
# path = $HOME/data/gmail_backup/maildir/ # note the trailing slash
path = $HOME/data/gmail_backup/maildir/
----------------------------------------------------------------------------
7. Create the getmail configuration file [options] section:
$ vi $HOME/data/gmail_backup/backupgmail.getmailrc
#########################################################################
[options]
#########################################################################
# delete = true # delete mail on server
# delete = false # keep mail on server
delete = false
# verbose = 0 # no log messages
# verbose = 2 # minimum log messages
verbose = 2
message_log = $HOME/.getmail/getmail.log
# read_all = false # download only new messages
# read_all = true # download all messages each time
read_all = true
# delivered_to = false # do not alter messages
delivered_to = false
# received = false # do not alter messages
received = false
#########################################################################
----------------------------------------------------------------------------
8. Make sure the mbox file exists prior to running getmail
$ ls -l $HOME/data/gmail_backup/backup.mbox
----------------------------------------------------------------------------
9. Run Getmail
$ getmail -v -r $HOME/data/gmail_backup/backupgmail.getmailrc &
----------------------------------------------------------------------------
10. Explore the results
----------------------------------------------------------------------------
11. Optionally, add the command to your crontab.
$ crontab -e
# add this line and save
0 23 * * * getmail -r $HOME/data/gmail_backup/backupgmail.getmailrc &
NOTE: I'm not sure if the crontab can handle the $HOME shell variable.
----------------------------------------------------------------------------
12. Read your mail with Thunderbird
a. Start Thunderbird
b. Copy the "Local directory" location in Thunderbird:
Thunderbird: Tools > Account Settings > Local Folders
c. Close Thunderbird
d. Copy the mbox file to the location you copied above.
If there is a .mbox extension on the file, remove it.
so backup.mbox should just be backup.
e. Open Thunderbird
f. Local Folders should show a folder called backup with your mail.
----------------------------------------------------------------------------
References:
http://pyropus.ca/software/getmail/configuration.html
http://manpages.ubuntu.com/manpages/xenial/man1/getmail.1.html
https://balau82.wordpress.com/2011/07/17/using-getmail-to-backup-gmail-
on-linux
https://earldouglas.com/posts/getgmail.html
https://itsitrc.blogspot.jp/2013/07/gmail-account-backup-in-ubuntu.html
https://scottlinux.com/2011/02/28/backup-gmail-account-in-linux/
https://wiki.archlinux.org/index.php/Backup_Gmail_with_getmail
****************************************************************************
End of:
How to back up Gmail using Linux getmail (20180306)
****************************************************************************