How to back up Gmail to your computer (and keep your labels)

Make a complete, browsable offline copy of your Gmail or Google Workspace mailbox on your Mac or Linux PC, with labels, read state and dates intact.

Updated · LocalIMAP 0.1.0

Google keeps your mail safe from disk failures, but not from everything else: a locked account, a policy strike, a forgotten recovery phone, or an inactive account clean-up can all make years of email unreachable overnight. A copy on your own computer protects you from all of these.

This guide copies Gmail (or Google Workspace) into LocalIMAP, a free IMAP server that runs on your Mac or Linux PC. Unlike a one-off export, the copy stays browsable and searchable in your mail client, keeps your labels as folders, and is stored as plain Maildir files you own.

Before you start

  • A Mac or Linux computer with enough free disk space for your mailbox (Gmail shows your usage at the bottom of the inbox).
  • A desktop mail client: Apple Mail or Thunderbird both work well and support Google sign-in.
  • For a work or school account: check your organization's policy before copying mail to a personal device.

1. Install LocalIMAP and create an account

brew install nikitaycs50/localimap/localimap

Then run localimap to open the dashboard. Press a to create an account (for example gmail-backup with a password of your choice) and s to start the server. Turn on Settings → Start at login if you want it always available.

2. Add Gmail and LocalIMAP to the same mail client

If Gmail is not in your mail client yet, add it the normal way (Google account type in Apple Mail, or your Gmail address in Thunderbird). Then add LocalIMAP as a second account with these settings:

Account typeIMAP
Server127.0.0.1, port 1143, no encryption (traffic never leaves your computer)
User name / passwordthe LocalIMAP account you just created
Email addressanything, e.g. gmail-backup@localhost

Detailed, client-specific steps are in Connect Apple Mail, Thunderbird or Outlook.

3. Let Gmail download completely

Your mail client can only copy what it has downloaded. Before copying:

  • Apple Mail: in Settings → Accounts → (Gmail) → Account Information, set Download Attachments to All. Then select the account and choose Mailbox → Synchronize. Wait until the activity indicator stops.
  • Thunderbird: in Account Settings → Synchronization & Storage, enable Keep messages for this account on this computer, and choose to synchronize all messages regardless of age.
  • Gmail settings: under See all settings → Forwarding and POP/IMAP, make sure Folder size limits is set to Do not limit, or large labels will appear truncated.

4. Copy your labels to LocalIMAP

Gmail shows each label as an IMAP folder. A message with three labels appears in three folders, so pick one approach:

  • Keep your structure: drag individual labels (Inbox, Sent Mail, and your own labels) onto the LocalIMAP account. Messages with several labels are stored once per label.
  • Every message exactly once: copy [Gmail]/All Mail. That's the smallest complete backup, but without label folders.

In Apple Mail, hold ⌥ Option while dragging to copy instead of move. In Thunderbird, right-click a folder and choose Copy To → LocalIMAP. For very large mailboxes, copy a few folders at a time.

5. Check the counts and make a ZIP backup

The Accounts tab in the LocalIMAP dashboard shows message counts and sizes per folder. Compare them with Gmail. Then press b (or run the command below) to write a single archive you can keep on an external drive or another cloud:

localimap backup --account gmail-backup

You get ~/LocalIMAP Backups/localimap-gmail-backup-YYYYMMDDHHMMSS-back.zip. To keep the backup current, every few months sort a Gmail folder by date, select the messages that arrived since your last copy and drag them into the matching LocalIMAP folder.

LocalIMAP vs. Google Takeout

Google Takeout exports your mail as one large .mbox file. It's a good one-time archive, but you have to import it into a program before you can read it, labels become text headers, and updating it means a new full export. With LocalIMAP, the backup is a live mail account: open it in any client, search it, reply from it, or move it to a new provider later. Using both is a perfectly good belt-and-braces strategy.

Common questions

Does LocalIMAP need my Google password?

No. Your mail client signs in to Google; LocalIMAP only receives the copied messages from the client.

What about Google Workspace?

It works exactly the same way, as long as IMAP access is allowed by your administrator.

Will deleting mail in Gmail later delete it from my backup?

No. The two accounts are independent. Only deleting messages inside the LocalIMAP account removes them there.