Zimbra to Zimbra Migration Tool
A professional, well-architected tool for migrating Zimbra email accounts between servers.
Zimbra to Zimbra Migration Tool (Refactored)
A professional, well-architected tool for migrating Zimbra email accounts between servers.
🎯 Features
- LDAP Integration: Export and import user accounts via LDAP
- Full Backups: Complete mailbox exports and imports
- Incremental Backups: Efficient delta synchronization
- Multi-threaded: Parallel processing for faster migrations
- Session Management: Resume interrupted migrations
- Load Balancing: Distribute accounts across multiple stores
- Comprehensive Logging: Detailed logs for troubleshooting
📁 Project Structure
.
├── zimbra_migrator.py # Main entry point
├── config_manager.py # Configuration handling
├── logger_config.py # Logging setup
├── account.py # Account model
├── ldap_handler.py # LDAP operations
├── backup_manager.py # Backup/restore operations
├── migration_worker.py # Threading and orchestration
├── utils.py # Utility functions
├── config.ini # Configuration file
├── requirements.txt # Python dependencies
└── README.md # This file
🚀 Installation
-
Install dependencies:
pip install -r requirements.txt -
Configure the tool: Edit
config.iniwith your Zimbra server details. -
Prepare store mapping: Create
zimbra_mail_hosts.csvwith email-to-host mappings.
📝 Configuration
config.ini
[zimbra_source]
host = source.zimbra.com
admin_user = admin
admin_password = password
ldap_protocol = ldap://
ldap_host = ldap.source.com
ldap_port = 389
ldap_user = cn=zimbra,cn=admins,cn=zimbra
ldap_pass = password
ldap_base_dn = ou=people,dc=zimbra,dc=com
ldap_filter = (objectClass=zimbraAccount)
[zimbra_destination]
host = destination.zimbra.com
admin_user = admin
admin_password = password
ldap_host = ldap.destination.com
ldap_port = 389
ldap_user = cn=zimbra,cn=admins,cn=zimbra
ldap_pass = password
ldap_filter = (objectClass=zimbraAccount)
[global]
root_folder = /opt/zimbra/backup/
session_file = sessions.txt
log_level = INFO
zimbra_mail_hosts.csv
user1@domain.com,mailstore1.zimbra.com
user2@domain.com,mailstore2.zimbra.com
🎮 Usage
Basic Commands
List available stores:
./zimbra_migrator.py -b -t 1 -ldap
Full migration from LDAP:
./zimbra_migrator.py -ldap -f -l -t 4 -d 1
Full migration from CSV:
./zimbra_migrator.py -s accounts.csv -f -l -t 4 -d 1
Incremental migration:
./zimbra_migrator.py -ldap -i -at 01/15/2025 -t 4
Automatic incremental (cron):
./zimbra_migrator.py -ldap -i -at cron -t 4
Command-Line Options
-ldap, --ldap Load accounts from LDAP
-s, --source FILE Load accounts from CSV file
-f, --full Perform full migration
-i, --incr Perform incremental migration
-l, --ldiff Perform LDIFF export/import
-t, --thread N Number of threads to use
-d, --destination-store N Destination store index (default: 1)
-at, --at-time DATE Incremental date (MM/DD/YYYY) or "cron"
-b, --l-destination-store List all destination stores
-c, --config FILE Path to config file (default: config.ini)
🏗️ Architecture
Class Diagram
┌─────────────────┐
│ ZimbraMigrator │ (Main Orchestrator)
└────────┬────────┘
│
├── ConfigManager (Configuration)
├── LDAPHandler (LDAP Operations)
├── BackupManager (Backup/Restore)
├── SessionManager (Session Tracking)
└── MigrationWorker (Threading)
│
└── Account (Data Model)
Key Components
ConfigManager: Loads and validates configuration from INI file
LDAPHandler: Manages LDAP connections and queries for account discovery
BackupManager: Handles all backup and restore operations via curl
MigrationWorker: Thread worker for parallel processing
SessionManager: Thread-safe session tracking for resume capability
Account: Data model representing a user account with migration state
🔧 Improvements Over Original
- Modern Python 3: Type hints, f-strings, pathlib
- Proper OOP: Clear separation of concerns
- Better Error Handling: Custom exceptions and proper logging
- No Deprecated Modules: Replaced
commandswithsubprocess - Thread Safety: Proper locking mechanisms
- Testability: Modular design allows easy unit testing
- Maintainability: Well-documented, following PEP 8
- Extensibility: Easy to add new features
📊 Migration Statistics
After migration, the tool displays:
- Total accounts processed
- LDIFF exports/imports
- Full migrations completed
- Incremental migrations completed
- Detailed per-account status
🐛 Troubleshooting
Check logs:
tail -f activity-migration.log
Per-account logs:
ls /opt/zimbra/backup/user@domain.com/*.log
Resume failed migration:
The tool automatically tracks completed operations in sessions.txt and skips them on re-run.
📜 License
🤝 Contributing
Contributions are welcome! Please follow PEP 8 style guidelines and add tests for new features.
✨ Authors
- Original Script: [Original Author]
- Refactored by: ScaleNix Team (2025)