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, models, 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.
- Model Support: Fully supports Metabase models (cards with
dataset=true), preserving their model status during migration. - Permissions Migration: Export and import permission groups and access control settings.
- Database Remapping: Intelligently remaps questions and cards to new database IDs on the target instance.
- Table & Field ID Remapping: Automatically remaps table IDs and field IDs in card queries (NEW!).
- Captures table and field metadata during export
- Builds intelligent mappings between source and target instances
- Remaps table IDs in card queries and filters
- Remaps field IDs in filter expressions
- 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 \
--include-permissions \
--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--include-permissions- Include permissions (groups and access control) in export--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 \
--apply-permissions \
--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--include-archived- Include archived items in the import--apply-permissions- Apply permissions from the export (requires admin privileges)--log-level- Logging level: DEBUG, INFO, WARNING, ERROR
Table & Field ID Remapping
The toolkit automatically remaps table IDs and field IDs during import, ensuring cards reference the correct tables and fields in the target instance.
Why This Matters
In Metabase, each table and field has an instance-specific ID. When you have the same table name in different
databases (e.g., "companies" in both company_service and deal_service), the table IDs will be different.
Without proper remapping:
- Cards would reference the wrong table
- Filters with field IDs would break
- Cards would appear to work but show data from the wrong source
How It Works
- Export Phase: The toolkit captures table and field metadata from the source instance
- Mapping Phase: During import, it builds intelligent mappings between source and target IDs based on table/field names
- Remapping Phase: All card queries are updated to use the correct target IDs
Example
Source Instance:
- Database: company_service (ID: 3)
- Table: companies (ID: 27)
- Field: company_type (ID: 201)
Target Instance:
- Database: company_service (ID: 4)
- Table: companies (ID: 42)
- Field: company_type (ID: 301)
After Import:
- Card database_id: 3 → 4 ✓
- Card table_id: 27 → 42 ✓
- Filter field_id: 201 → 301 ✓
For more details, see Table ID Remapping Guide.
Permissions Migration
The toolkit supports exporting and importing permissions to solve the common "403 Forbidden" errors after migration. See the Permissions Migration Guide for detailed instructions.
Quick example:
# Export with permissions
metabase-export --export-dir "./export" --include-permissions
# Import with permissions
metabase-import --export-dir "./export" --db-map "./db_map.json" --apply-permissions
Samples and Examples
The repository includes a samples/ directory with ready-to-use templates:
samples/db_map/db_map.single_db.json– minimal single-database mapping examplesamples/db_map/db_map.multi_db.json– example mapping for multiple databasessamples/flows/export_import_basic.sh– basic end-to-end export/import flow using.envsamples/flows/export_import_multi_env.sh– example promotion flow between environmentssamples/cicd/github-actions-export-import.yml– minimal GitHub Actions workflow showing export/import in CI
Use these as starting points and adapt them to your own environments and naming conventions.
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.8.tar.gz.
File metadata
- Download URL: metabase_migration_toolkit-1.0.8.tar.gz
- Upload date:
- Size: 88.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a68a77301718d74f7ef08883bd6f3ea317205054dd98bc8ed8e4c95267919e5
|
|
| MD5 |
03dd6cd35503651a30e05dc38feb5f41
|
|
| BLAKE2b-256 |
d040ccf3e9ebf0855dac352fa48770af543cc8403c8ccbc4341b134d88c8d7e2
|
Provenance
The following attestation bundles were made for metabase_migration_toolkit-1.0.8.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.8.tar.gz -
Subject digest:
1a68a77301718d74f7ef08883bd6f3ea317205054dd98bc8ed8e4c95267919e5 - Sigstore transparency entry: 723380946
- Sigstore integration time:
-
Permalink:
Finverity/metabase-migration-toolkit@6bd5f6b8655441a3f4d3fe6a3ed1bd57760d0bbd -
Branch / Tag:
refs/tags/1.0.8 - Owner: https://github.com/Finverity
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6bd5f6b8655441a3f4d3fe6a3ed1bd57760d0bbd -
Trigger Event:
release
-
Statement type:
File details
Details for the file metabase_migration_toolkit-1.0.8-py3-none-any.whl.
File metadata
- Download URL: metabase_migration_toolkit-1.0.8-py3-none-any.whl
- Upload date:
- Size: 39.7 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 |
97e770a425efecd057bf412275edd3c957e0c19b7414e6890852f9dbea0c0ee2
|
|
| MD5 |
7bf68f53f1ddd6b287a00da9efbfe5f4
|
|
| BLAKE2b-256 |
6ae46f9460b6ed986ae28336548b94f18319ce83f3144c211dad8c2dfeabd069
|
Provenance
The following attestation bundles were made for metabase_migration_toolkit-1.0.8-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.8-py3-none-any.whl -
Subject digest:
97e770a425efecd057bf412275edd3c957e0c19b7414e6890852f9dbea0c0ee2 - Sigstore transparency entry: 723380955
- Sigstore integration time:
-
Permalink:
Finverity/metabase-migration-toolkit@6bd5f6b8655441a3f4d3fe6a3ed1bd57760d0bbd -
Branch / Tag:
refs/tags/1.0.8 - Owner: https://github.com/Finverity
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6bd5f6b8655441a3f4d3fe6a3ed1bd57760d0bbd -
Trigger Event:
release
-
Statement type: