Skip to the content.

IMAP Backup & Restore Documentation

Welcome to the IMAP Backup & Restore tool documentation. This tool allows you to backup, restore, and manage your IMAP email accounts with support for S3 storage and GPG encryption.

Features

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
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=my-backups \
  --s3-access-key=YOUR_KEY \
  --s3-secret-key=YOUR_SECRET

Using Python Directly

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

# Install Python dependencies
pip install -r requirements.txt

# Install system dependencies
# Ubuntu/Debian:
sudo apt install gnupg

# RHEL/CentOS:
sudo yum install gnupg

# macOS:
brew install gnupg

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

Documentation Index

  1. Docker Setup Guide - Using the Docker image
  2. Python/venv Setup Guide - Using Python virtual environments
  3. Backup Guide - How to backup your emails
  4. Restore Guide - How to restore emails from backups
  5. Multi-Account Backup - Backup multiple email accounts with YAML configuration
  6. S3 Configuration - Setting up S3 storage (MinIO, Hetzner, AWS)
  7. GPG Encryption Guide - Encrypting your backups
  8. GPG Key Import Guide - Flexible GPG key import (files, URLs, environment variables)

Common Use Cases

Daily Automated Backups

Use cron to schedule daily backups:

# Run daily at 2 AM
0 2 * * * docker run --rm -v /backups:/data user2k20/imapbackup \
  -s imap.example.com -u user@example.com -p @/root/.imap_password -e

Backup and Upload to S3 with Encryption (Easy Method)

# Using flexible key import - no GPG keyring mount needed
docker run --rm \
  -v $(pwd)/backups:/data \
  user2k20/imapbackup \
  -s imap.example.com -u user@example.com -e \
  --s3-upload \
  --s3-endpoint=https://s3.eu-central-1.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/backup-public.asc

See GPG Key Import Guide for more examples including environment variables and file paths.

Backup and Upload to S3 with Encryption (Traditional Method)

# Using mounted GPG keyring
docker run --rm \
  -v $(pwd)/backups:/data \
  -v $(pwd)/.gnupg:/root/.gnupg \
  user2k20/imapbackup \
  -s imap.example.com -u user@example.com -e \
  --s3-upload \
  --s3-endpoint=https://s3.eu-central-1.hetzner.cloud \
  --s3-bucket=email-backups \
  --s3-access-key=$S3_KEY \
  --s3-secret-key=$S3_SECRET \
  --gpg-encrypt \
  --gpg-recipient=backup@example.com

Restore from S3 Encrypted Backup

docker run --rm \
  -v $(pwd)/backups:/data \
  -v $(pwd)/.gnupg:/root/.gnupg \
  user2k20/imapbackup \
  -r \
  -s imap.newserver.com -u user@newserver.com -e \
  --s3-upload \
  --s3-endpoint=https://s3.eu-central-1.hetzner.cloud \
  --s3-bucket=email-backups \
  --s3-access-key=$S3_KEY \
  --s3-secret-key=$S3_SECRET \
  --gpg-encrypt \
  --gpg-recipient=backup@example.com

Command Line Options

Basic Options

Backup/Restore Modes

Folder Selection

S3 Storage Options

GPG Encryption Options

Requirements

For Docker

For Python (venv)

Support

For issues or questions:

Security Notes

  1. Password Storage: Use @/path/to/password to read password from a file
  2. GPG Keys: Ensure your GPG keyring is properly secured
  3. S3 Credentials: Use environment variables or secure credential storage
  4. SSL/TLS: Always use -e flag for encrypted IMAP connections

Next Steps

  1. Read the Docker Setup Guide to get started with Docker
  2. Follow the Backup Guide for your first backup
  3. Set up S3 Storage for cloud backups
  4. Configure GPG Encryption for secure backups