
Gmail stores years of your life — receipts, contracts, medical records, conversations you’d hate to lose. Google can and does lock accounts, sometimes with no warning and no clear appeal process. Accidental deletions happen. And relying entirely on a cloud service you don’t control is just poor data hygiene.
A local backup of your Gmail solves all of this. This guide covers three practical approaches: a manual export using Google’s own tools, an automated open-source backup tool, and a technical IMAP-based method for maximum control. There’s also a note for Synology NAS owners.
Note: This post originally covered GMVault, which was a solid tool in its day. GMVault requires Python 2.7, which reached end-of-life in January 2020, and the project has not been meaningfully updated since. The OAuth2 flow it relies on is effectively broken. Everything in this updated guide uses tools that are actively maintained and work with Google’s current APIs.
Option 1: Google Takeout (No Setup, Manual)
Google Takeout is Google’s official data export tool. It lets you download your entire Gmail mailbox as one or more MBOX files — a standard format that most email clients can open.
This is the right choice if you want a one-off snapshot of your inbox or if you’re not comfortable with the command line.
How to export your Gmail via Takeout
- Go to takeout.google.com and sign in.
- Click Deselect all, then scroll down and check only Mail.
- Click All Mail data included if you want to export specific labels rather than everything.
- Click Next step, choose your preferred file type (ZIP), and set a maximum file size (2 GB is a safe default — Google will split the archive automatically if your mailbox exceeds it).
- Click Create export. Google will email you a download link when it’s ready.
Depending on the size of your mailbox, this can take anywhere from a few hours to several days. The download link is only valid for 7 days, so don’t let it expire. Google also limits you to three export attempts per day.
Limitations
Takeout is not incremental — every export is a full download of your entire mailbox. If your Gmail is 40 GB, you’re downloading 40 GB every time. There’s no built-in way to automate it on a schedule. It’s a snapshot, not a continuous backup strategy.
MBOX files can also be unwieldy. Apple Mail, Thunderbird, and most Linux mail clients handle them fine. If you just want to view emails, Thunderbird with the ImportExportTools NG add-on is your best bet for browsing a local MBOX archive.
Option 2: Got Your Back (Best Automated Option)
Got Your Back (GYB) is an open-source command-line tool maintained by the GAM-team on GitHub. It connects to Gmail via the official Gmail API using OAuth2, pulls down your email, and stores it locally. It supports full and incremental backups, making it genuinely useful as an ongoing backup solution rather than a one-off tool.
This is the best modern replacement for GMVault.
Installing GYB
GYB ships as a standalone binary — no Python environment to configure. Download the latest release for your platform from the GitHub releases page.
On macOS, move the binary somewhere on your PATH:
sudo mv gyb /usr/local/bin/
chmod +x /usr/local/bin/gyb
On Linux (including a Synology NAS accessed via SSH), place it in a suitable directory and make it executable the same way.
Authenticating with your Google account
The first time you run a backup, GYB will walk you through OAuth2 authorization. Run this command, replacing the email address with your own:
gyb --email [email protected] --action create-project
This opens a browser window asking you to authorize GYB to access your Gmail. Once you approve, GYB saves a token locally so it can run unattended in the future.
Running your first backup
To do a full backup of your entire mailbox:
gyb --email [email protected] --action backup --local-folder /path/to/backup/folder
The first run downloads everything, which will take a while on a large mailbox. After that, incremental backups only pull new messages:
gyb --email [email protected] --action backup --local-folder /path/to/backup/folder --search "newer_than:1d"
GYB stores emails as individual .eml files organized by Gmail message ID, which makes restoration straightforward.
Restoring from a GYB backup
To restore messages back to a Gmail account:
gyb --email [email protected] --action restore --local-folder /path/to/backup/folder
Automating GYB on macOS or Linux
On a Mac, add a cron job via crontab -e. This example runs a daily incremental backup at 2am:
0 2 * * * /usr/local/bin/gyb --email [email protected] --action backup --local-folder /Volumes/NAS/gmail-backup --search "newer_than:2d" >> /var/log/gyb-backup.log 2>&1
On Linux or a Synology NAS with SSH access enabled, the same cron syntax applies — just adjust the paths.
Running GYB on Synology via Docker
If you want GYB to run directly on your DiskStation rather than from your Mac, the docker-gyb container is the cleanest approach. It handles scheduling internally, running a full backup every Sunday at 1am and incremental backups Monday through Saturday by default.
The authentication step still requires a browser — you’ll need to run it once from a machine with a desktop environment to generate the token file, then copy that token to your NAS for the Docker container to use.
Option 3: IMAP Backup (Most Flexible, Most Technical)
Gmail supports IMAP, which means any tool that speaks IMAP can pull down your mail. This approach is lower-level than GYB — you’re not using the Gmail API, you’re treating Gmail like any other mail server. The tradeoff is more configuration up front, but also fewer API dependencies and maximum portability.
Two tools worth knowing here: mbsync (part of the isync project) and offlineimap. Both are mature, actively maintained, and widely used. mbsync is generally faster and more actively developed; use it unless you have a specific reason for offlineimap.
Prerequisites
Before you can connect via IMAP, you need to do two things in your Google account:
- Enable IMAP access. In Gmail, go to Settings → See all settings → Forwarding and POP/IMAP → Enable IMAP.
- Create an App Password. Google no longer allows third-party apps to sign in with your main Google password. You need a dedicated App Password. Go to myaccount.google.com/apppasswords, create one (call it “mbsync” or similar), and save the 16-character password it generates. You will only see it once.
Note: App Passwords require 2-Step Verification to be enabled on your Google account.
Installing mbsync
On macOS:
brew install isync
On Debian/Ubuntu:
sudo apt install isync
Configuring mbsync for Gmail
Create a file at ~/.mbsyncrc with the following, replacing the placeholders with your details:
IMAPAccount gmail
Host imap.gmail.com
User [email protected]
Pass YOUR_APP_PASSWORD
SSLType IMAPS
Port 993
IMAPStore gmail-remote
Account gmail
MaildirStore gmail-local
Path ~/mail/gmail/
Inbox ~/mail/gmail/Inbox
Channel gmail
Far :gmail-remote:
Near :gmail-local:
Patterns *
Create Both
Expunge None
SyncState *
Don’t store your App Password in plain text if you can help it. Better approaches include encrypting it with GPG and using a PassCmd directive, or storing it in your system keychain. The Arch Linux wiki page for isync covers this in detail.
Running a sync
mbsync -a
The first sync will take a long time — Google imposes a 2,500 MB daily IMAP download limit, so a large mailbox may take several days to mirror fully. After the initial sync, subsequent runs only pull new messages.
Mail is stored in Maildir format, one file per message. This is extremely portable — virtually every email client on every platform can read Maildir.
Automating mbsync
On macOS, create a LaunchAgent plist or add a crontab entry. On Linux:
0 3 * * * /usr/bin/mbsync -a >> /var/log/mbsync.log 2>&1
A Note on Synology DiskStation
If you own a Synology NAS, you may have come across Active Backup for Google Workspace. This is Synology’s native backup package for Google accounts, and it is license-free. However, there is an important caveat: it is designed for Google Workspace (paid business accounts), not personal @gmail.com accounts. The setup requires domain admin access and a Google service account with domain-wide delegation — none of which apply to personal Gmail.
For personal Gmail on a Synology NAS, your best options are:
- Run GYB on your Mac and point the backup folder at a mounted NAS share.
- Run the docker-gyb container directly on your DiskStation using Container Manager.
- Run mbsync on your Mac and sync the Maildir to the NAS via rsync or a Hyper Backup task.
The docker-gyb approach is the most elegant if you want the backup to run autonomously on the NAS without keeping your Mac on.
Which Method Should You Use?
If you want something simple and don’t need automation, Google Takeout is fine for occasional snapshots. Set a calendar reminder to export every few months.
If you want ongoing automated backups with minimal fuss, Got Your Back (GYB) is the right choice. It’s actively maintained, uses official Google APIs, handles incremental backups, and has a Docker container that makes Synology integration straightforward.
If you want the most control — Maildir format, no Google API dependency, compatibility with any email client — go with mbsync. It takes more initial setup but is extremely reliable once configured.
Any of these is a significant improvement over having no local backup at all.

Hi there! I have been using Gmvault for a long time. Suddenly, it stopped working (maybe related to a Synology update) and I re-installed. However, could not connect any more via oauth and received “This app is blocked” when trying to re-initialize. I used then -p with an app password, but when the script tries to connect to the server I just get:
Error when reaching Gmail server. Wait 1 second(s) and retry up to 2 times.
Disconnecting from Gmail Server and sleeping …
Reconnecting to the from Gmail Server.
Error when reaching Gmail server. Wait 2 second(s) and retry up to 2 times.
Disconnecting from Gmail Server and sleeping …
Reconnecting to the from Gmail Server.
Error when reaching Gmail server. Wait 4 second(s) and retry up to 2 times.
Error: command: UID => got more than 1000000 bytes.
Anybody else experiencing the same?
I keep receiving “error: argument -m/–multiple-db-owner: ignored explicit argument ‘ails-only'” when executing gmvault sync -t full –db-dir /volume1/Gmvault/backups/YOUREMAILADDRESS/ –emails-only –no-compression my_email…@gmail.com
Thanks for the instruction. I was able to follow every step until I stumbled upon gmvault sync -t full –db-dir /volume1/Gmvault/backups/YOUREMAILADDRESS/ –emails-only –no-compression my_email…@gmail.com
I am confused as to whether YOUREMAILADDRESS is the same as my_email…@gmail.com
Let’s suppose my_email…@gmail.com is actually [email protected]. What should be the correct syntax for the above? Thanks.
you shouldn’t use sudo with pip. in this case, you’re needing to use sudo because the virtual environment isn’t actually being utilized here; therefore, sudo is needed to install gmvault in to the system’s python environment.
To activate the virtual environment, source the activate script.
> source gmvault_env/bin/activate
gmvault has been blocked by Google so don’t bother trying.
Hi!
Any Updates on the automation? When i set up a task in dsm IT seems that i have to do the Authentication step again, but there is no interactive mode.
Hi!
I have solved the problem by using a docker container that backups to data periodically to my Diskstation. For more than one account I deploy multiple container.
Thanks for sharing Christian.
You are my hero Jean!
A couple comments to assist anyone who may attempt this:
– I had to enable user home service.
– I had to use sudo for “pip install gmvault”
Thanks Jerry, added the modification in case others run into the same problem.
This was helpful – thank you!
Mini feedback:
* 1. wget https://bootstrap.pypa.io/gepipt-pip.py
This has to be https://bootstrap.pypa.io/get-pip.py
* 7. pip install gmvault
For me this only worked with sudo due to missing rights
* gmvault sync -t full –db-dir /volume1/Gmvault/backups/YOUREMAILADDRESS/ –emails-only –no-compression my_email…@gmail.com
This should have “–” in front of db-dir instead of just “-”
Thanks again. Today too many people don’t take the time to document their approach and help others. Much appreciated that you took the time.
You’re welcome Bartel, I will update the post accordingly.
Your article says – “At this point you will realise that we haven’t yet automated anything, and the automation part is an essential reason of why we’re doing this thing, so let’s proceed with getting that in place too.” and then pretty much ends?????
That sentence was left in there by mistake, I now removed it. I haven’t yet gotten around to automate the process as I had some issues when setting it up, but it’s on my todo list. Any tips on how to do that would be great.
Hello Jean!
I stumbled onto your page, attempting to find a method of constant gmvault backups, as my last solution unexpectedly stopped working (and I can no longer find the resource I used to set it up).
During the pip install (the step “wget https://bootstrap.pypa.io/gepipt-pip.py“), I am met with a 404 error “Not found”. I thought it was a spelling error on the ‘gepipt-pip.py’ section, but attempting random combinations yielded the same error.
Would you happen to know another source for this material?
Thanks in advance!
edit line to getpip-pip.py
correction
should read https://bootstrap.pypa.io/get-pip.py
Thanks, fixed.