gyb

command-line tool for backing up and restoring Gmail

TLDR

Backup Gmail
$ gyb --email [[email protected]] --action backup
Restore emails
$ gyb --email [[email protected]] --action restore
Estimate backup size
$ gyb --email [[email protected]] --action estimate
Backup only recent messages
$ gyb --email [[email protected]] --action backup --search "newer_than:[7d]"
Count messages
$ gyb --email [[email protected]] --action count
Fast incremental backup (skip refreshing labels for already-backed-up messages)
$ gyb --email [[email protected]] --action backup --fast-incremental

SYNOPSIS

gyb [options]

DESCRIPTION

GYB (Got Your Back) is a command-line tool for backing up and restoring Gmail using the Gmail API over HTTPS.It supports incremental backups, search queries to filter specific messages, and can also restore from mbox exports (e.g., Google Takeout). Backups are stored locally with a SQLite index.

PARAMETERS

--email ADDR

Gmail address.
--action ACT
Action: backup, restore, restore-mbox, estimate, count, purge, print-labels, quota, reindex.
--local-folder DIR
Local backup directory.
--search QUERY
Gmail search query to filter messages.
--fast-incremental
Skip refreshing labels/flags for already-backed-up messages.
--label-restored LABEL
On restore, additionally apply this label to all messages.
--strip-labels
Remove existing labels during restore.
--spam-trash
Include Spam and Trash folders.
--service-account
Use Google Service Account authentication.
--help
Display help information.

INSTALL

brew install gyb
nix profile install nixpkgs#gyb

CAVEATS

Requires OAuth authorization. Rate limited by Gmail API. Large mailboxes take time.

HISTORY

GYB was created by Jay Lee as an open-source Gmail backup tool, widely used for Google Workspace migrations.

SEE ALSO

offlineimap(1), mbsync(1), mutt(1)