IMAP Backup & Restore Tool
The complete open-source solution for backing up, restoring, and migrating IMAP email accounts.
π Features
Core Capabilities
- π§ Full IMAP Backup - Download all emails from any IMAP server to standard mbox format
- π Smart Restore - Upload mbox files back to IMAP servers with duplicate detection
- βοΈ S3 Integration - Store backups in S3-compatible storage (AWS S3, MinIO, Hetzner, Wasabi)
- π GPG Encryption - Encrypt backups with GPG for secure storage
- π¦ Zero Dependencies - Pure Python implementation, no external libraries required
- π³ Docker Ready - Pre-built Docker image for easy deployment
- β‘ Incremental Backups - Only download new messages on subsequent runs
- π§ Flexible Key Import - Import GPG keys from files, URLs, or environment variables
Perfect For
- β Email server migrations
- β Automated daily backups
- β Disaster recovery planning
- β Compliance and archival
- β Cloud storage integration
- β Kubernetes deployments
- β Personal email backup
π Quick Start
Using Docker (Recommended)
# 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
- Docker Setup Guide - Quick start with Docker
- Python/venv Setup Guide - Installation with Python virtual environments
- Backup Guide - Complete backup strategies and examples
- Restore Guide - How to restore emails from backups
Advanced Topics
- S3 Configuration - Configure AWS S3, MinIO, Hetzner, and other providers
- GPG Encryption Guide - Set up encryption for secure backups
- GPG Key Import Guide - Flexible key import from files, URLs, environment variables
π― 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
- MIT Licensed - Use it anywhere, modify it freely
- No Vendor Lock-in - Standard mbox format works with any email client
- Community Driven - Actively maintained since 2007
Production Ready
- Zero Dependencies - Pure Python, runs anywhere Python 3.6+ is available
- Battle Tested - Used by thousands of users worldwide
- Docker Official - Pre-built images on Docker Hub
- Kubernetes Ready - Perfect for cloud-native deployments
Security First
- Read-Only IMAP Operations - Never modifies source emails during backup
- GPG Encryption - Industry-standard OpenPGP encryption
- S3 Compatible - Works with all major cloud providers
- Flexible Key Management - Import keys from files, URLs, or environment variables
Developer Friendly
- Clean Code - Well-documented Python codebase
- Comprehensive Docs - Detailed guides for every use case
- Easy Integration - Simple CLI interface, scriptable
- Active Support - GitHub issues and pull requests welcome
π Popular Use Cases & Keywords
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
-s HOST
- IMAP server hostname-u USER
- Username/email address-p PASS
- Password or@/path/to/file
to read from file-e
- Use SSL/TLS (recommended)-d DIR
- Directory for mbox files
Backup/Restore Modes
-a
- Append mode (default, incremental backups)-y
- Overwrite mode (full backup)-r
- Restore mode (upload to IMAP server)
Folder Selection
-f FOLDERS
- Backup specific folders (comma-separated)--exclude-folders=FOLDERS
- Exclude specific folders
S3 Storage Options
--s3-upload
- Enable S3 integration--s3-endpoint=URL
- S3 endpoint URL--s3-bucket=BUCKET
- S3 bucket name--s3-access-key=KEY
- S3 access key--s3-secret-key=KEY
- S3 secret key--s3-prefix=PREFIX
- Optional S3 path prefix
GPG Encryption Options
--gpg-encrypt
- Enable GPG encryption/decryption--gpg-recipient=EMAIL
- GPG key ID or email address--gpg-import-key=SOURCE
- Import public key from:- File:
/path/to/key.asc
- URL:
https://example.com/key.asc
- Environment:
env:GPG_PUBLIC_KEY
- File:
π οΈ Supported Platforms & Services
IMAP Servers
- Gmail / Google Workspace
- Microsoft 365 / Outlook.com
- ProtonMail
- Fastmail
- Zoho Mail
- Apple iCloud Mail
- Yahoo Mail
- Self-hosted (Dovecot, Postfix, Zimbra, etc.)
- Any IMAP-compatible server
S3-Compatible Storage
- AWS S3 - Amazon Web Services
- Hetzner Storage Box - European data centers
- MinIO - Self-hosted object storage
- Wasabi - Hot cloud storage
- Backblaze B2 - Affordable cloud storage
- DigitalOcean Spaces - Simple object storage
- Cloudflare R2 - Zero egress fees
Deployment Options
- Docker - Pre-built image:
user2k20/imapbackup
- Docker Compose - Easy multi-container setups
- Kubernetes - CronJob examples included
- Python venv - Isolated Python environment
- Bare Metal - Direct Python execution
- Cron - Traditional Unix scheduling
π¦ Requirements
For Docker
- Docker installed
- Thatβs it! Everything else is included in the image
For Python
- Python 3.6 or higher (tested with 3.8+)
- GPG (for encryption):
apt install gnupg
- Python dependencies:
pip install -r requirements.txt
π Links
- GitHub Repository - Source code and issues
- Docker Hub - Pre-built Docker images
- Documentation - Complete guides and examples
- License - MIT License
π 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