26

Which Linux tools help to backup and restore a IMAP mail account including all mail and subfolders?

I expect disconnects for large IMAP accounts because of

  1. ressource limitiations on the server
  2. risk of an interruption increases with the duration.

The software should be able to reconnect and continue the job after any interruption. For repeating backups it might be very handy to use incremental backups and to run the backup script in a cron job.

6 Answers 6

14

Updated May 2025 (checked all links)

Originally posted the answer when the question was 'just' 7 years old, it is now ~10 years old. At the time, I was looking for a solution to migrate off of Google Workspaces as they were about to charge their free legacy users.

This question had a few answered, most were spot on. But I felt at least one was missing, and there was probably room for more. So below is the original list, refreshed as of Oct 2024.

NOTE: Most of the answers are not necessarily backup/restore, as my personal focus was syncing two IMAP accounts. I'll add a [sync only] note next to projects I know are sync-only options without a download solution. Keep in mind, that spinning a local IMAP server - shouldn't be complex, but I'm not covering in this post.

Timeline of answers:

My searches led me to these additional options:

The packages below are available on Debian 11 (bullseye), but I don't know much about them:

  • imapcopy
    Unmaintained since ~2009
  • interimap
    Still actively maintained at developer's website
  • mailsync
    On SourceForge
  • mswatch
    repo. Requires something to do the actual syncing.
  • vdirsyncer
    site. Companion to other IMAP synchronizers, for syncing Calendar and Contacts.

Specifically for Gmail / Google Workspace mailboxes*:
* Not an IMAP solution, but might be related to somebody's search, so I feel it's worth mentioning

I'll try and keep this list updated, as I see this still attracts interest from time to time. Personally, I had good experiences with Got Your Back and imapsync.

2
  • imapsync is for syncronizing between IMAP servers. It doesn't download mail locally AFAIK. Commented Oct 26, 2024 at 5:01
  • 1
    Excellent points @JamesHirschorn, I've updated the post to indicate that. Commented Oct 26, 2024 at 14:34
8

Try to use open source project imap-backup: https://github.com/joeyates/imap-backup

$ imap-backup setup 

The setup system is a menu-driven command line application.

It creates ~/.imap-backup directory and configuration file. E.g.:

{ "accounts": [ { "username": "[email protected]", "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": "[email protected]", "password": "secret", "server": "my.imap.example.com", "local_path": "/path/to/backup/root", "folders": [ {"name": "[Gmail]/All Mail"}, {"name": "my_folder"} ] } ] } 
1
  • This is by far the best tool I've met on my years long search for a solid imap backup tool! Commented Aug 15, 2023 at 0:18
4

OfflineIMAP is a GPLv2 software to dispose your mailbox(es) as a local Maildir(s).

For example, this allows reading the mails while offline without the need for your mail reader (MUA) to support disconnected operations.

OfflineIMAP will synchronize both sides via IMAP.

http://www.offlineimap.org/

https://github.com/OfflineIMAP/offlineimap

It also supports restoring to an IMAP server: http://www.offlineimap.org/doc/backups-restore.html

3

You can use imapsync for this. You can get the source from fedorahosted.org imapsync page. Zimbra Guide to imapsync has good documentation about this subject.

-1

More to do with backing up than your questions but I've just found and started testing mailpiler. Not sure I like the fact of giving access to "all" email so working out how to send "older" email on regular basis to file there.

At the moment we use Awesome Auto Archive thunderbird extensions to "move" emails to another filing account.

1
  • mailpiler seems to be a commercial web service where you can send all your mails to. Besides obvious security concerns this is not what was asked for in this question. Commented Dec 27, 2018 at 21:58
-4

"cp -pr" should do the job. The "r" option in "pr" should take care of both subfolders and any hidden files/directories.

1
  • 4
    I guess this answer assumes the mails are in a Maildir type format in which case any tool to copy the files should work, and rsync might be a good option. But I think OP is interested in a solution that connects remotely through IMAP. Commented Dec 14, 2014 at 21:45

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.