is a popular solution for this.
Enable IMAP in GMail
- Sign in to Gmail.
- Click Settings at the top of any Gmail page.
- Click Forwarding and POP/IMAP.
- Select Enable IMAP.
- Configure your IMAP client and click Save Changes.
After you install it create a
accounts = GMail
maxsyncaccounts = 3
localrepository = Local
remoterepository = Remote
autorefresh = 10 #refresh every 10 minutes
quick = 5 #Quick-syncs do not update if the only changes were to IMAP flags
type = Maildir
localfolders = /whatever/directory
type = IMAP
remotehost = imap.gmail.com
remoteuser = firstname.lastname@example.org
remotepass = your_password
ssl = yes
maxconnections = 1
#Setting realdelete = yes will Really Delete email from the server.
#Otherwise "deleting" a message will just remove any labels and
#retain the message in the All Mail folder.
realdelete = no
Then you need to run offlineimap.
Automating offlineimap with cron
In some cases having offlineimap running all the time can consume large amounts of memory, especially if you have a large mailbox, so you can add an offlineimap check into cron to just check it and then exit, here's a daily backup:
@daily offlineimap -u Noninteractive.Basic
Backing up offlineimap
The files will be in whatever you define in the localfolders line as a Maildir. You can back this up using whatever backup method you use: