How to Backup your Gmail or Google Apps Account Daily

If you rely on Gmail or Google Apps for your mission-critical email then you know you need to take your own backups. Your Gmail email can get deleted or lost and once it’s gone, it’s gone. This howto provides a simple process for painlessly keeping a backup of all your Gmail or Google Apps emails for a single account.

You’ll Need a *nix Machine

This howto assumes that you have a shell account on a *nix (unix, linux, BSD, Mac OS X, etc.) machine and can install getmail, a flexible mail retriever. If you have root access on a FreeBSD machine you can install getmail like this:

cd /usr/ports/mail/getmail ; make install clean


Lando Cruz and the Coup Conspiracy A scrappy libertarian rebel risks life in prison in a dystopian future.

If nothing else works, you can always download it from the getmail website and install it from source, since it’s written in python.

Run the Following Commands

Bring up a terminal or SSH session and run the following commands as the user that you will run getmail as. Any non-privileged user should do the job.

mkdir ~/.getmail
mkdir ~/GmailBackup/ ~/GmailBackup/new ~/GmailBackup/tmp ~/GmailBackup/cur
vi ~/.getmail/getmailrc.mygmailaccount

Getmail Configuration File

And put the following into ~/.getmail/getmailrc.mygmailaccount:

type = SimplePOP3SSLRetriever
server =
username =
password = my_gmail_password

type = Maildir
path = ~/GmailBackup/

verbose = 2
received = false
delivered_to = false
message_log = ~/.getmail/gmail.log

Be sure to replace with your Gmail or Google Apps email address and my_gmail_password with your account’s password.

Getmail will Copy your Gmail Emails, without Deleting them

This configuration file will cause getmail to copy the emails in your Gmail or Google Apps account, without deleting them, including emails in the Sent folder. Getmail will store your emails as individual files in the ~/GmailBackup/new directory. The ~/GmailBackup directory is a Maildir, so you can read those emails with your own POP or IMAP server or a text editor.

If you Prefer Mbox

If you prefer to store your emails in an mbox file, you can change the destination section to read:

type = Mboxrd
path = ~/GmailBackup.mbox

You might want to also run:

touch ~/GmailBackup.mbox

The Mbox format can be less reliable than Maildir but is popular and can be easily imported into many popular email clients, such as and Thunderbird.

The Daily Cronjob

Finally you’ll want to open your non-privileged user’s crontab:

crontab -e

And add this cronjob:

#backup gmail email
03 04 * * * /path/to/getmail -ln --rcfile getmailrc.mygmailaccount

You can get the path to getmail by typing the following in your terminal or SSH session:

which getmail

This will take a daily backup at 4:03AM in the time zone of the computer.

The First Backup

You can go ahead and run the first backup:

getmail -ln --rcfile getmailrc.mygmailaccount

If successful, this will output considerable detail, including information on each email message it downloads and where it saves it.

Check your Backups Anytime

You can always check the status of your recent backups by tailing the getmail log we configured in the getmailrc file:

tail -f ~/.getmail/gmail.log

Take Backups Today!

If your mission-critical email is hosted by Google, you know you need to take backups. Sleep easier and start taking backups today. Once you set them up, you won’t have to worry about them again.

Related Links

Get Access to the Latest Insights
Receive a short email once per week with our latest insights. Leave anytime.