Export and import Metabase content (collections, questions, dashboards) between instances
Project description
Metabase Migration Toolkit
This toolkit provides two command-line tools, metabase-export and metabase-import, designed for exporting and importing Metabase content (collections, questions, and dashboards) between instances.
It's built to be robust, handling API rate limits, pagination, and providing clear logging and error handling for production use.
Features
- Recursive Export: Traverses the entire collection tree, preserving hierarchy.
- Selective Content: Choose to include dashboards and archived items.
- Database Remapping: Intelligently remaps questions and cards to new database IDs on the target instance.
- Conflict Resolution: Strategies for handling items that already exist on the target (
skip,overwrite,rename). - Idempotent Import: Re-running an import with
skiporoverwriteproduces a consistent state. - Dry Run Mode: Preview all import actions without making any changes to the target instance.
- Secure: Handles credentials via environment variables or CLI flags and never logs or exports sensitive information.
- Reliable: Implements exponential backoff and retries for network requests.
Prerequisites
- Python 3.10+
- Access to source and target Metabase instances with appropriate permissions (API access, ideally admin).
Installation
Option 1: Install from PyPI (Recommended)
pip install metabase-migration-toolkit
After installation, the metabase-export and metabase-import commands will be available globally in your environment.
Option 2: Install from TestPyPI (for testing)
pip install --index-url https://test.pypi.org/simple/ \
--extra-index-url https://pypi.org/simple/ \
metabase-migration-toolkit
Option 3: Install from Source
-
Clone the repository:
git clone <your-repo-url> cd metabase-migration-toolkit
-
Install the package:
pip install -e .
Configuration
-
Configure Environment Variables (Recommended): Copy the example
.envfile and fill in your credentials. This is the most secure way to provide credentials.cp .env.example .env # Edit .env with your details
-
Create a Database Mapping File: Copy the example
db_map.example.jsonand configure it to map your source database IDs/names to the target database IDs.cp db_map.example.json db_map.json # Edit db_map.json with your mappings
This is the most critical step for a successful import. You must map every source database ID used by an exported card to a valid target database ID.
Usage
1. Exporting from a Source Metabase
The metabase-export command connects to a source instance and exports its content into a local directory.
Example using .env file (Recommended):
# All credentials are read from .env file
metabase-export \
--export-dir "./metabase_export" \
--include-dashboards \
--include-archived \
--log-level INFO \
--root-collections "24"
Example using CLI flags:
metabase-export \
--source-url "https://your-source-metabase.com/" \
--source-username "user@example.com" \
--source-password "your_password" \
--export-dir "./metabase_export" \
--include-dashboards \
--root-collections "123,456"
Available options:
--source-url- Source Metabase URL (or useMB_SOURCE_URLin .env)--source-username- Username (or useMB_SOURCE_USERNAMEin .env)--source-password- Password (or useMB_SOURCE_PASSWORDin .env)--source-session- Session token (or useMB_SOURCE_SESSION_TOKENin .env)--source-token- Personal API token (or useMB_SOURCE_PERSONAL_TOKENin .env)--export-dir- Directory to save exported files (required)--include-dashboards- Include dashboards in export--include-archived- Include archived items--root-collections- Comma-separated collection IDs to export (optional)--log-level- Logging level: DEBUG, INFO, WARNING, ERROR
2. Importing to a Target Metabase
The metabase-import command reads the export package and recreates the content on a target instance.
Example using .env file (Recommended):
# All credentials are read from .env file
metabase-import \
--export-dir "./metabase_export" \
--db-map "./db_map.json" \
--conflict skip \
--log-level INFO
Example using CLI flags:
metabase-import \
--target-url "https://your-target-metabase.com/" \
--target-username "user@example.com" \
--target-password "your_password" \
--export-dir "./metabase_export" \
--db-map "./db_map.json" \
--conflict overwrite \
--log-level INFO
Available options:
--target-url- Target Metabase URL (or useMB_TARGET_URLin .env)--target-username- Username (or useMB_TARGET_USERNAMEin .env)--target-password- Password (or useMB_TARGET_PASSWORDin .env)--target-session- Session token (or useMB_TARGET_SESSION_TOKENin .env)--target-token- Personal API token (or useMB_TARGET_PERSONAL_TOKENin .env)--export-dir- Directory with exported files (required)--db-map- Path to database mapping JSON file (required)--conflict- Conflict resolution:skip,overwrite, orrename(default: skip)--dry-run- Preview changes without applying them--log-level- Logging level: DEBUG, INFO, WARNING, ERROR
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file metabase_migration_toolkit-1.0.3.tar.gz.
File metadata
- Download URL: metabase_migration_toolkit-1.0.3.tar.gz
- Upload date:
- Size: 65.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d36b43d741bd8d183afcc2cec66e5acbe2f87b73c70c7e1cd41c526ad99fdde3
|
|
| MD5 |
61e769d5251c9b292123649dc7211349
|
|
| BLAKE2b-256 |
d7a56e5798e3ae82170c33454f4d42c274a95a7d46b0dd6e6c730cb141301d85
|
Provenance
The following attestation bundles were made for metabase_migration_toolkit-1.0.3.tar.gz:
Publisher:
publish.yml on Finverity/metabase-migration-toolkit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
metabase_migration_toolkit-1.0.3.tar.gz -
Subject digest:
d36b43d741bd8d183afcc2cec66e5acbe2f87b73c70c7e1cd41c526ad99fdde3 - Sigstore transparency entry: 598543039
- Sigstore integration time:
-
Permalink:
Finverity/metabase-migration-toolkit@7b854de4a73a16fc6e4d61c856113f1811321fae -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Finverity
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7b854de4a73a16fc6e4d61c856113f1811321fae -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file metabase_migration_toolkit-1.0.3-py3-none-any.whl.
File metadata
- Download URL: metabase_migration_toolkit-1.0.3-py3-none-any.whl
- Upload date:
- Size: 29.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0b3c46ec06b889324a698a24d9c6c4449ff7547c44c0c2f9e8f18f4cbbb4afdd
|
|
| MD5 |
4cec6aa33ec9ff84ae490b139ce2c314
|
|
| BLAKE2b-256 |
e6b0dfe03ec6b0c25b176e0c660a6bd336f9a20ce1819eef6862ca701a5399a0
|
Provenance
The following attestation bundles were made for metabase_migration_toolkit-1.0.3-py3-none-any.whl:
Publisher:
publish.yml on Finverity/metabase-migration-toolkit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
metabase_migration_toolkit-1.0.3-py3-none-any.whl -
Subject digest:
0b3c46ec06b889324a698a24d9c6c4449ff7547c44c0c2f9e8f18f4cbbb4afdd - Sigstore transparency entry: 598543040
- Sigstore integration time:
-
Permalink:
Finverity/metabase-migration-toolkit@7b854de4a73a16fc6e4d61c856113f1811321fae -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Finverity
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7b854de4a73a16fc6e4d61c856113f1811321fae -
Trigger Event:
workflow_dispatch
-
Statement type: