Backup GMail (or other IMAP) accounts to disk
Featured Content Ads
add advertising here$ gem install 'imap-backup'
For a full list, run
For more information about a command, run
$ imap-backup help COMMAND
In order to do backups, you need to add accounts via a menu-driven command
line program:
Run:
Featured Content Ads
add advertising hereGMail
To use imap-backup with GMail, you will need to enable ‘App passwords’ on your account.
Folders
By default, all folders are backed-up. You can override this by choosing
specific folders.
Configuration file
setup
creates the file ~/.imap-backup/config.json
E.g.:
Featured Content Ads
add advertising here{ "accounts": [ { "username": "my.user@gmail.com", "password": "secret", "local_path": "/path/to/backup/root", "folders": [ {"name": "[Gmail]/All Mail"}, {"name": "my_folder"} ] } ] }
It connects to GMail by default, but you can also specify a server:
{ "accounts": [ { "username": "my.user@gmail.com", "password": "secret", "server": "my.imap.example.com", "local_path": "/path/to/backup/root", "folders": [ {"name": "[Gmail]/All Mail"}, {"name": "my_folder"} ] } ] }
Connection options
You can override the parameters passed to Net::IMAP
with connection_options
.
Specifically, if you are using a self-signed certificate and get SSL errors, e.g.
certificate verify failed
, you can choose to not verify the TLS connection:
{ "accounts": [ { "username": "my.user@gmail.com", "password": "secret", "server": "my.imap.example.com", "local_path": "/path/to/backup/root", "folders": [ {"name": "[Gmail]/All Mail"}, {"name": "my_folder"} ], "connection_options": { "ssl": {"verify_mode": 0}, "port": 993 } } ] }
Note that email usernames and passwords are held in plain text
in the configuration file.
The directory ~/.imap-backup, the configuration file and all backup
directories have their access permissions set to only allow access
by your user. This is not done on Windows – see below.
Windows
Due to the complexity of managing permissions on Windows,
directory and file access permissions are not set explicity.
A pull request that implements permissions management on Windows
would be welcome!
Manually, from the command line:
Alternatively, add it to your crontab.
Each folder is saved to an mbox file.
Alongside each mbox is a file with extension ‘.imap’, which lists the source IMAP
UIDs to allow a full restore.
There a various commands for viewing local backup status.
To view the list, use
If you have problems:
- ensure that you have the latest release,
- turn on debugging output:
{ "accounts": [ ... ], "debug": true }
All missing messages are pushed to the IMAP server.
Existing messages are left unchanged.
This functionality requires that the IMAP server supports the UIDPLUS
extension to IMAP4.
List IMAP folders:
Get statistics of emails to download per folder:
- Secure – use a local file protected by permissions
- Restartable – calculate start point based on already downloaded messages
- Standalone – do not rely on