Self-Hosted M365 Backup
A self-hosted, open-source tool to back up Microsoft 365 mailboxes to standard .eml files. It features a web UI for managing backups, background tasks, search, preview functionality, and secure Microsoft OAuth 2.0 login.
Features
- Web-Based Management Panel: Modern web interface for all operations.
- Secure Authentication: Microsoft Identity Platform OAuth 2.0 login with MFA support.
- Selective Backup: Choose specific users from the tenant list.
- Date Filtering: Back up items by date range.
- Background Tasks: Large jobs run asynchronously via Celery + Redis.
- Task Status Dashboard: Monitor task progress and results.
- Interactive Restore Portal:
- Navigation through mailbox folders
- List of emails in selected folder
- In-browser email preview without downloading
- Privacy-by-Design: Email previews blurred by default, hover-to-reveal for admins.
- Full-Text Search: Search subject and body of emails.
- Automated Installation: Single
install.sh script deploys the app on Ubuntu.
Architecture
- Backend: Python, Flask
- Web Server: Gunicorn + Nginx (Reverse Proxy)
- Background Tasks: Celery
- Queue/Broker: Redis
- Frontend: HTML, Pico.css, HTMX
- Authentication: Microsoft Identity Platform (OAuth 2.0)
Installation Guide
I. Azure Portal Configuration
- App Registration:
- Go to
portal.azure.com → Azure Active Directory → App registrations → + New registration
- Name the app (e.g.,
M365-Backup-Tool) and click Register
- API Permissions:
- Microsoft Graph → Add Permissions
- Application Permissions:
User.Read.All, Mail.Read.All
- Delegated Permissions:
User.Read
- Click "Grant admin consent"
- Redirect URI:
- Authentication → + Add platform → Web
- Enter:
https://<your_server_ip>/get_token
- Client Secret:
- Certificates & secrets → + New client secret
- Copy the secret value immediately
Required info: Tenant ID, Client ID, Client Secret Value
II. Server Installation
- Requirements: Fresh Ubuntu 22.04 LTS server
- Copy
install.sh to the server
- Make it executable:
chmod +x install.sh
- Run the script:
sudo ./install.sh
- Provide Azure credentials and list of admin emails
- Wait for installation to complete; script outputs server access IP
Usage
- Open browser:
https://<your_server_ip>
- Accept security warning (self-signed cert)
- Login with authorized Microsoft account
- New Backup: Start a new backup task
- Existing Backups: Browse, search, preview backups
- Tasks: Monitor background tasks and status
License
Open-source, MIT License.