Skip to main content

Export and import Metabase content (collections, questions, dashboards) between instances

Project description

Metabase Migration Toolkit

Tests codecov PyPI version Python Versions License: MIT Code style: black

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.
  • Permissions Migration: Export and import permission groups and access control settings.
  • Embedding Settings Migration: Export and import embedding configurations for dashboards and cards (NEW!).
  • 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 skip or overwrite produces 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

  1. Clone the repository:

    git clone <your-repo-url>
    cd metabase-migration-toolkit
    
  2. Install the package:

    pip install -e .
    

Configuration

  1. Configure Environment Variables (Recommended): Copy the example .env file and fill in your credentials. This is the most secure way to provide credentials.

    cp .env.example .env
    # Edit .env with your details
    
  2. Create a Database Mapping File: Copy the example db_map.example.json and 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 use MB_SOURCE_URL in .env)
  • --source-username - Username (or use MB_SOURCE_USERNAME in .env)
  • --source-password - Password (or use MB_SOURCE_PASSWORD in .env)
  • --source-session - Session token (or use MB_SOURCE_SESSION_TOKEN in .env)
  • --source-token - Personal API token (or use MB_SOURCE_PERSONAL_TOKEN in .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
  • --include-embedding-settings - Include embedding settings (enable_embedding and embedding_params) 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 use MB_TARGET_URL in .env)
  • --target-username - Username (or use MB_TARGET_USERNAME in .env)
  • --target-password - Password (or use MB_TARGET_PASSWORD in .env)
  • --target-session - Session token (or use MB_TARGET_SESSION_TOKEN in .env)
  • --target-token - Personal API token (or use MB_TARGET_PERSONAL_TOKEN in .env)
  • --export-dir - Directory with exported files (required)
  • --db-map - Path to database mapping JSON file (required)
  • --conflict - Conflict resolution: skip, overwrite, or rename (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)
  • --include-embedding-settings - Include embedding settings (enable_embedding and embedding_params) in import
  • --log-level - Logging level: DEBUG, INFO, WARNING, ERROR

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

Embedding Settings Migration

The toolkit supports exporting and importing embedding settings for dashboards and cards. This includes the enable_embedding flag and embedding_params configuration.

Prerequisites

  • Embedding must be enabled in the Metabase Admin settings on both source and target instances
  • May require a Pro or Enterprise license depending on your Metabase version
  • The embedding secret key must be configured separately on each instance (it is NOT exported/imported for security reasons)

Usage

Export with embedding settings:

metabase-export \
    --export-dir "./export" \
    --include-dashboards \
    --include-embedding-settings

Import with embedding settings:

metabase-import \
    --export-dir "./export" \
    --db-map "./db_map.json" \
    --include-embedding-settings

Important Notes

  1. Embedding must be enabled globally: The toolkit will warn you if embedding is not enabled on the target instance, but it will still import the settings. They won't function until embedding is enabled.

  2. Secret key is instance-specific: Each Metabase instance has its own embedding secret key. You must configure this separately in the Admin settings on the target instance.

  3. License requirements: Depending on your Metabase version, embedding features may require a Pro or Enterprise license.

  4. Default behavior: By default (without the --include-embedding-settings flag), embedding settings are NOT exported or imported to avoid issues with instances that don't have embedding enabled.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

metabase_migration_toolkit-1.0.5.tar.gz (68.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

metabase_migration_toolkit-1.0.5-py3-none-any.whl (34.0 kB view details)

Uploaded Python 3

File details

Details for the file metabase_migration_toolkit-1.0.5.tar.gz.

File metadata

File hashes

Hashes for metabase_migration_toolkit-1.0.5.tar.gz
Algorithm Hash digest
SHA256 af4665bd9ca170d863ca35affe74efa34014b74ca9d9d9e30055fbf8479bd352
MD5 e2dd2ff58e54beb951f27c4ed0bab5ae
BLAKE2b-256 388485321bc1c3459815fefa2c3fbc8567f75f3353cb4bdeca34320fa9653a9d

See more details on using hashes here.

Provenance

The following attestation bundles were made for metabase_migration_toolkit-1.0.5.tar.gz:

Publisher: publish.yml on Finverity/metabase-migration-toolkit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file metabase_migration_toolkit-1.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for metabase_migration_toolkit-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 ccf2a8054b47b65871e8a7c6f3591aca99f97db4c4712522babb75ccf0ba61aa
MD5 f784c0467609ebc2d8498ef5c2a77d1a
BLAKE2b-256 63c4fb9ff86f7317cf57d31789aba6063ef04ca50260a3e2c3e41ed55beccfb8

See more details on using hashes here.

Provenance

The following attestation bundles were made for metabase_migration_toolkit-1.0.5-py3-none-any.whl:

Publisher: publish.yml on Finverity/metabase-migration-toolkit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page