Skip to the content.

IMAP Backup & Restore Tool

The complete open-source solution for backing up, restoring, and migrating IMAP email accounts.

Language grade: Python Docker Pulls License: MIT


πŸš€ Features

Core Capabilities

Perfect For


πŸ“š Quick Start

# Basic backup
docker run --rm -v $(pwd)/backups:/data \
  user2k20/imapbackup \
  -s imap.example.com -u user@example.com -e

# Backup with S3 upload and GPG encryption
docker run --rm -v $(pwd)/backups:/data \
  user2k20/imapbackup \
  -s imap.example.com -u user@example.com -e \
  --s3-upload \
  --s3-endpoint=https://s3.hetzner.cloud \
  --s3-bucket=email-backups \
  --s3-access-key=$S3_KEY \
  --s3-secret-key=$S3_SECRET \
  --gpg-encrypt \
  --gpg-recipient=backup@example.com \
  --gpg-import-key=https://example.com/keys/public.asc

Using Python

# Clone repository
git clone https://github.com/chris2k20/imapbackup.git
cd imapbackup

# Create virtual environment
python3 -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Run backup
python3 imapbackup.py -s imap.example.com -u user@example.com -e

πŸ“– Documentation

Getting Started

Advanced Topics


🎯 Use Cases

1. Daily Automated Backups

# Cron job for daily backups at 2 AM
0 2 * * * docker run --rm -v /backups:/data user2k20/imapbackup \
  -s imap.example.com -u user@example.com -p @/root/.password -e \
  --s3-upload --s3-endpoint=https://s3.hetzner.cloud \
  --s3-bucket=backups --s3-access-key=$KEY --s3-secret-key=$SECRET

2. Email Server Migration

# Backup from old server
python3 imapbackup.py -s old.server.com -u user@old.com -e

# Restore to new server
python3 imapbackup.py -r -s new.server.com -u user@new.com -e

3. Kubernetes Deployment

apiVersion: batch/v1
kind: CronJob
metadata:
  name: email-backup
spec:
  schedule: "0 2 * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: backup
            image: user2k20/imapbackup:latest
            args:
              - -s
              - imap.example.com
              - -u
              - user@example.com
              - -e
              - --s3-upload
              - --gpg-encrypt

4. Encrypted Cloud Backups

# Backup with encryption - no GPG keyring mount needed!
docker run --rm -v $(pwd)/backups:/data \
  user2k20/imapbackup \
  -s imap.gmail.com -u myemail@gmail.com -e \
  --s3-upload --s3-bucket=secure-backups \
  --gpg-encrypt --gpg-recipient=backup@example.com \
  --gpg-import-key=env:GPG_PUBLIC_KEY

πŸ’‘ Why Choose IMAP Backup Tool?

Open Source & Free

Production Ready

Security First

Developer Friendly


Email Backup Solutions: Perfect for Gmail backup, Office 365 backup, Exchange backup, Outlook backup, and any IMAP-compatible email service.

Server Migration: Seamlessly migrate emails between providers - move from Gmail to ProtonMail, Office 365 to Google Workspace, or any IMAP server to another.

Compliance & Archival: Meet GDPR, HIPAA, and other regulatory requirements with encrypted email archives stored securely in S3-compatible storage.

Disaster Recovery: Automated daily backups ensure you never lose important emails. Restore to any IMAP server in minutes.

Self-Hosted Email: Perfect companion for self-hosted mail servers using Dovecot, Postfix, Zimbra, or any IMAP-compatible server.


πŸ“Š Command Line Options

Basic Options

Backup/Restore Modes

Folder Selection

S3 Storage Options

GPG Encryption Options


πŸ› οΈ Supported Platforms & Services

IMAP Servers

S3-Compatible Storage

Deployment Options


🚦 Requirements

For Docker

For Python



πŸ“ˆ SEO Keywords

imap backup, email backup tool, python imap, backup imap emails, gmail backup, office 365 backup, email migration, imap restore, mailbox backup, mbox backup, docker email backup, s3 email backup, encrypted email backup, gpg email encryption, automated email backup, email archival, email disaster recovery, open source email backup, imap sync, email server migration, dovecot backup, postfix backup, kubernetes email backup, cloud email backup, secure email backup


🀝 Contributing

Contributions are welcome! Please feel free to submit issues, fork the repository, and create pull requests.


πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ™ Acknowledgments

Originally developed around 2007 and actively maintained ever since. Thanks to all contributors who have helped make this tool better over the years.


⭐ Star this repository if you find it useful!

πŸ› Found a bug? Open an issue

πŸ’¬ Have questions? Check the documentation