The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
docs - serdes updates (#72391)
Jeff Bruemmer2f5692988188
diff --git a/docs/data-modeling/models.md b/docs/data-modeling/models.mdindex a7028d4f7aa..ec7379277d3 100644--- a/docs/data-modeling/models.md+++ b/docs/data-modeling/models.md@@ -63,7 +63,7 @@ Models you create are automatically [pinned to the current collection](../explorTo view a model's details, visit the model and click on the **info** button in the upper right. Here you'll see several tabs:-- **Overview**: Includes the description, Creator and Last Editor, and the list of fields included in the model. As well as the model's [Entity ID](../installation-and-operation/serialization.md#metabase-uses-entity-ids-to-identify-and-reference-metabase-items).+- **Overview**: Includes the description, Creator and Last Editor, and the list of fields included in the model. As well as the model's [Entity ID](../installation-and-operation/serialization.md#metabase-uses-entity-ids-to-identify-metabase-items).- **History**: Lists changes to the model, and by whom.- **Relationships**: Lists which questions use the model, and which tables the model is linked to.- **Actions**: Lists actions created based on the model.diff --git a/docs/embedding/full-app-embedding-quick-start-guide.md b/docs/embedding/full-app-embedding-quick-start-guide.mdindex 81edacb24b6..725753fc575 100644--- a/docs/embedding/full-app-embedding-quick-start-guide.md+++ b/docs/embedding/full-app-embedding-quick-start-guide.md@@ -31,7 +31,7 @@ You'll first need a dashboard to embed. If you don't have one yet, you can use tVisit that dashboard and make a note of its URL, e.g. `/dashboard/1-e-commerce-insights`. You'll need to put this relative URL in your app, as you'll use the dashboard as the first page that logged-in people will see when they visit the analytics section in your app. It's enough to include the ID only and omit the rest of the URL, e.g. `/dashboard/1`.-You could also use the dashboard's [Entity ID](../installation-and-operation/serialization.md#metabase-uses-entity-ids-to-identify-and-reference-metabase-items). On the dashboard, click on the **info** button. On the **Overview** tab, look for the dashboard's **Entity ID**. Copy that Entity ID. You'll use that Entity ID in the iframe's `src` URL: (e.g., `src=/dashboard/entity/[Entity ID]`).+You could also use the dashboard's [Entity ID](../installation-and-operation/serialization.md#metabase-uses-entity-ids-to-identify-metabase-items). On the dashboard, click on the **info** button. On the **Overview** tab, look for the dashboard's **Entity ID**. Copy that Entity ID. You'll use that Entity ID in the iframe's `src` URL: (e.g., `src=/dashboard/entity/[Entity ID]`).### Enable full app embeddingdiff --git a/docs/embedding/static-embedding.md b/docs/embedding/static-embedding.mdindex 9222e4c0f6f..07e91c2f65c 100644--- a/docs/embedding/static-embedding.md+++ b/docs/embedding/static-embedding.md@@ -97,7 +97,7 @@ For iframe snippets:## If you serialize your Metabase, use Entity IDs in your static embeds-Using [Entity IDs](../installation-and-operation/serialization.md#metabase-uses-entity-ids-to-identify-and-reference-metabase-items) in your static embeds will make sure that the IDs are stable when exporting from one Metabase and importing to another Metabase.+Using [Entity IDs](../installation-and-operation/serialization.md#metabase-uses-entity-ids-to-identify-metabase-items) in your static embeds will make sure that the IDs are stable when exporting from one Metabase and importing to another Metabase.To use an Entity ID in a static embed, all you need to do is edit the `resource` map in the `payload` used to sign your token. Replace the item's (autopopulated) ID with its Entity ID and you're done.diff --git a/docs/installation-and-operation/serialization.md b/docs/installation-and-operation/serialization.mdindex 0d1940875e7..48453d2ec3a 100644--- a/docs/installation-and-operation/serialization.md+++ b/docs/installation-and-operation/serialization.md@@ -9,48 +9,51 @@ redirect_from:{% include plans-blockquote.html feature="Serialization" %}-Once you get rolling with Metabase, it's often the case that you'll have more than one Metabase instance spun up. You might have a couple of testing or development instances and a few production ones, or maybe you have a separate Metabase per office or region.+Serialization lets you export the contents of one Metabase and import them into another Metabase. It's useful when you run multiple Metabases, like separate instances for testing and production, or a Metabase per office or region.-To help you out in situations like this, Metabase has a serialization feature which lets you create an _export_ of the contents of a Metabase that can then be _imported_ into one or more Metabases.+- **Export** will serialize the contents of your source Metabase as YAML files.+- **Import** will read those exported YAML files and create or update those serialized items in the target Metabase.-**Export** will serialize the contents of your source Metabase as YAML files.+## Serialization format-**Import** will read those exported YAML files and create or update items in the target Metabase based on the contents serialized in those YAML files.--There are two ways to run these `export` and `import` commands:--- [Using CLI commands](#serialization-with-cli-commands)-- [Through the API](#serialization-via-the-api)--> We're interested in how we can improve serialization to suit your workflow. [Upvote an existing issue](https://github.com/metabase/metabase/issues?q=is%3Aissue+is%3Aopen+serialization+label%3AOperation%2FSerialization) to let us know it's important to you. If a relevant issue doesn't yet exist, please create one and tell us what you need.+The [Metabase Representation Format](https://github.com/metabase/representations) repository contains the full specification for the YAML format used by serialization, including schemas for each entity type, examples, and an [NPM validation package](https://www.npmjs.com/package/@metabase/representations) you can use to validate YAML files.## Serialization use cases- **Staging environments**. Enable a staging-to-production workflow for important dashboards by exporting from a staging instance of Metabase and then importing them into your production instance(s).-- **Version control**. Check the exported files into version control and audit changes to them, as the YAML files contained within the export are pretty readable.-- **Duplicating assets to other Metabase instances**. Export the "template" data from a source Metabase and import them to one or more target instances.+- **Version control**. Check the exported files into version control and audit changes to them, as the YAML files contained within the export are pretty readable. For a built-in Git workflow with push/pull from the Metabase UI, see [Remote Sync](./remote-sync.md).+- **Duplicating assets to other Metabases**. Export the "template" data from a source Metabase and import them to one or more target instances.Check out our guides for:- [Running multiple environments](https://www.metabase.com/learn/metabase-basics/administration/administration-and-operation/multi-env)- [Setting up git-based workflow](https://www.metabase.com/learn/metabase-basics/administration/administration-and-operation/git-based-workflow)+## Importing and exporting your Metabase content++There are two ways to run these `export` and `import` commands:++- [Using CLI commands](#serialization-with-cli-commands)+- [Through the API](#serialization-via-the-api)++If you're on Metabase Cloud, the API endpoints are your only option.+## How export works- [What gets exported](#what-gets-exported)- [General Metabase settings that get exported](#general-metabase-settings-that-are-exported)- [Customize what gets exported](#customize-what-gets-exported)- [Example of a serialized question](#example-of-a-serialized-question)-- [Metabase uses Entity IDs to identify and reference items](#metabase-uses-entity-ids-to-identify-and-reference-metabase-items)+- [Metabase uses Entity IDs to identify and reference items](#metabase-uses-entity-ids-to-identify-metabase-items)### What gets exportedMetabase will only export the following entities:-- Collections (but personal collections don't get exported unless you explicitly specify them through [export options](#customize-what-gets-exported))+- Collections (but personal collections don't get exported unless you explicitly specify them with the [Select collections](#select-collections) option)- Dashboards-- Saved questions-- Transforms (including jobs)+- Questions (cards)+- Transforms (including tags and jobs)- Documents (without comments)- Actions- Models@@ -59,208 +62,122 @@ Metabase will only export the following entities:- Data model and table metadata- Segments- Measures+- Glossary entries (data definitions)- Public sharing settings for questions and dashboards- [General Metabase settings](#general-metabase-settings-that-are-exported)- Events and timelines-- Database connection strings (only if specified through [export options](#customize-what-gets-exported))--All other entities—including users, groups, permissions, alerts, subscriptions, document comments—won't get exported.--Metabase will export its artifacts to a directory of YAML files. The export includes:--- Directories that contain YAML files for various Metabase entities.- An example export could include the following directories, depending on what you exported and the contents of your Metabase:-- - actions- - collections- - cards- - dashboards- - timelines- - databases-- When serializing through the API, the export directory [will be compressed into a .tar.gz file](#you-must-compress-your-files-when-serializing-via-api-calls).+- Notification channels (email and webhook destinations used by alerts and subscriptions)+- Metabot configuration (AI assistant settings and prompts)+- Python libraries (shared Python modules used by transforms)+- Database connection strings (only if specified through the [Include database connection details](#include-database-connection-details) option)-- A `settings.yaml` file that includes some [Metabase-wide settings](#general-metabase-settings-that-are-exported)--Database connection details are not included by default, but you can [configure your export](#customize-what-gets-exported) to include them.+All other entities—including users, groups, permissions, alerts, subscriptions, document comments—won't get exported. Those entities are tied to user accounts, and therefore aren't portable between Metabases.### General Metabase settings that are exportedHere's the list of the general settings Metabase exports in the `settings.yaml` file. For more on Metabase settings, see [Configuring Metabase](../configuring-metabase/start.md).```-humanization-strategy-native-query-autocomplete-match-style-site-locale-report-timezone-short-report-timezone-long-application-name-enable-xrays-show-homepage-pin-message-source-address-header-enable-nested-queries-custom-geojson-enabled-start-of-week-custom-geojson-available-timezones-unaggregated-query-row-limitaggregated-query-row-limit-hide-embed-branding?-search-typeahead-enabled-enable-sandboxes?+allowed-iframe-hosts+application-colors+application-favicon-urlapplication-font+application-font-files+application-logo-url+application-name+available-fontsavailable-locales-landing-page+available-timezones+breakout-bins-num+csv-field-separator+custom-formatting+custom-geojson+custom-geojson-enabled+custom-homepage+custom-homepage-dashboard+default-maps-enabled+disable-cors-on-localhost+email-max-recipients-per-second+embedded-metabot-enabled?+embedding-homepage+embedding-hub-production-embed-snippet-created+embedding-hub-sso-auth-manual-tested+embedding-hub-test-embed-snippet-createdenable-embedding-application-colors-application-logo-url-application-favicon-url-show-homepage-xrays-show-metabot+enable-nested-queries+enable-pivoted-exports+enable-sandboxes?enable-whitelabeling?-show-homepage-data-site-name-application-font-files+enable-xrays+gsheets+hide-embed-branding?+humanization-strategy+landing-page+landing-page-illustration+landing-page-illustration-customloading-message-report-timezone+login-page-illustration+login-page-illustration-custom+metabot-chat-system-prompt+metabot-enabled?+metabot-icon+metabot-limit-reset-rate+metabot-limit-unit+metabot-name+metabot-nlq-system-prompt+metabot-quota-reached-message+metabot-show-illustrations+metabot-sql-system-prompt+native-query-autocomplete-match-style+no-data-illustration+no-data-illustration-custom+no-object-illustration+no-object-illustration-custom+non-table-chart-generatedpersisted-models-enabled-enable-content-management?+report-timezone+report-timezone-long+report-timezone-short+search-typeahead-enabled+setup-embedding-autoenabled+setup-license-active-at-setup+show-homepage-data+show-homepage-pin-message+show-homepage-xrays+show-metabot+show-sdk-embed-terms+show-simple-embed-terms+show-static-embed-terms+site-locale+site-name+source-address-header+start-of-weeksubscription-allowed-domains-breakout-bins-num-available-fonts-custom-formatting+synchronous-batch-updates+system-timezone+unaggregated-query-row-limit```### Customize what gets exported-You can customize what gets exported. You can tell Metabase:--- Export specific collections-- Do not export collections-- Do not export Metabase settings-- Do not export table metadata-- Include sample field values (excluded by default)-- Include database connection details (excluded by default)+You can customize what gets exported — select specific collections, exclude settings or the data model, include field values or database connection details, and more. The same options are available through both the CLI and the API; only the syntax differs.-See [export parameters in CLI commands](#export-options) or [export parameters in API calls](#api-export-parameters).+See [Export options](#export-options) for the full list.### Example of a serialized question-Questions can be found in the `cards` directory of a collection directory. Here's an example card YAML file for a question written with SQL that uses a field filter and has an area chart visualization.--To preserve a native query's multi-line format, remove trailing whitespace from native queries. If your native query has trailing whitespace, YAML will convert your query to a single string literal (which only affects presentation, not functionality).--```yml-name: Products by week-description: Area chart of products created by week-entity_id: r6vC_vLmo9zG6_r9sAuYG-created_at: "2024-05-08T19:10:24.348808Z"-creator_id: [email protected]-display: area-archived: false-collection_id: onou5H28Wvy3kWnjxxdKQ-collection_preview: true-collection_position: null-query_type: native-dataset: false-cache_ttl: null-database_id: Sample Database-table_id: null-enable_embedding: false-embedding_params: null-made_public_by_id: null-public_uuid: null-parameters:- - default:- - Gizmo- id: c37d2f38-05fa-48c4-a208-19d9dba803c6- name: Pick a category- slug: category_filter- target:- - dimension- - - template-tag- - category_filter- type: string/=-parameter_mappings: []-dataset_query:- database: Sample Database- native:- query: |-- SELECT- category,- date_trunc ('week', created_at) AS "Week",- count(*) AS "Count"- FROM- products- WHERE- {{category_filter}}- GROUP BY- category,- "Week"- template-tags:- category_filter:- default:- - Gizmo- dimension:- - field- - - Sample Database- - PUBLIC- - PRODUCTS- - CATEGORY- - base-type: type/Text- display-name: Pick a category- id: c37d2f38-05fa-48c4-a208-19d9dba803c6- name: category_filter- type: dimension- widget-type: string/=- type: native-result_metadata:- - base_type: type/Text- display_name: CATEGORY- effective_type: type/Text- field_ref:- - field- - CATEGORY- - base-type: type/Text- name: CATEGORY- semantic_type: null- - base_type: type/DateTime- display_name: Week- effective_type: type/DateTime- field_ref:- - field- - Week- - base-type: type/DateTime- name: Week- semantic_type: null- - base_type: type/BigInteger- display_name: Count- effective_type: type/BigInteger- field_ref:- - field- - Count- - base-type: type/BigInteger- name: Count- semantic_type: type/Quantity-visualization_settings:- column_settings: null- graph.dimensions:- - Week- - CATEGORY- graph.metrics:- - Count-serdes/meta:- - id: r6vC_vLmo9zG6_r9sAuYG- label: products_created_by_week- model: Card-initially_published_at: null-metabase_version: v1.49.7 (f0ff786)-type: question-```+Questions are stored as YAML files inside their parent collection folder. For examples and a complete spec, see the [Metabase Representation Format](https://github.com/metabase/representations).-### Metabase uses Entity IDs to identify and reference Metabase items+Some things to keep in mind when reading or editing exported YAML:-Metabase assigns a unique Entity ID to every Metabase item (a dashboard, question, model, collection, etc.). These Entity IDs are in addition to the sequential IDs Metabase generates. Entity IDs use the [NanoID format](https://github.com/ai/nanoid), and are stable across Metabases. By "stable" we mean that you can, for example, export a dashboard with an entity ID from one Metabase, and import that dashboard into another Metabase and have that dashboard use the same Entity ID, even though it's in a different Metabase.+- To preserve a native query's multi-line format, remove trailing whitespace from native queries. If your native query has trailing whitespace, YAML will convert your query to a single string literal (which only affects presentation, not functionality).+- To keep exported files compact, Metabase omits fields from the YAML when their values match the default. For example, `archived` defaults to `false`, so it won't appear unless the item is archived. Top-level fields with `null` values are also omitted.+- Fields prefixed with `lib/` (like `lib/type`, `lib/source`) are internal metadata that Metabase generates during export. You don't need to provide or edit them when hand-writing YAML — see the [Metabase Representation Format spec](https://github.com/metabase/representations) for which fields are required vs. informational.++### Metabase uses Entity IDs to identify Metabase items++Metabase assigns a unique Entity ID to every Metabase item (a dashboard, question, etc.). These Entity IDs are in addition to the sequential IDs Metabase generates that you'll see in URLs. Entity IDs use the [NanoID format](https://github.com/ai/nanoid), and are stable across Metabases. By "stable" we mean that you can, for example, export a dashboard with an entity ID from one Metabase, and import that dashboard into another Metabase and have that dashboard use the same Entity ID, even though the item is now in two different Metabase instances.To get an item's Entity ID in Metabase:@@ -268,38 +185,26 @@ To get an item's Entity ID in Metabase:2. Click on the info button.3. In the overview tab, copy the Entity ID.-You can also see the Entity IDs of items in the exported YAML files in the `entity_id` field. For example, in the [Example of a serialized question](#example-of-a-serialized-question), you'll see the Entity ID of that question:+You can also see the Entity IDs of items in the exported YAML files in the `entity_id` field. This ID also appears in the `serdes/meta → id` field (these IDs must match).-```yaml-entity_id: r6vC_vLmo9zG6_r9sAuYG-```--This ID also appears in the `serdes/meta → id` field (these IDs must match):--```yaml-serdes/meta:- - id: r6vC_vLmo9zG6_r9sAuYG-```--To disambiguate entities that share the same name, Metabase includes Entity IDs in the file and directory names for exported entities.+Metabase uses simplified versions of entity names for file and directory names in exports. Names are lowercased, and special characters are replaced with underscores. Names are also truncated for filesystem compatibility.```-r6vC_vLmo9zG6_r9sAuYG_products_by_week.yaml-IA96oUzmUbYfNFl0GzhRj_accounts_model.yaml-KUEGiWvoBFEc5oGQCEnPg_converted_customers.yaml+products_by_week.yaml+accounts_model.yaml+converted_customers.yaml```-For example, in the [Example of a serialized question](#example-of-a-serialized-question) above, you can see the field `collection_id`:+If two entities in the same folder share the same name after simplification, Metabase appends a numeric suffix to disambiguate:-```yaml-collection_id: onou5H28Wvy3kWnjxxdKQ```--This ID refers to the collection where the question was saved. In a real export, you'd be able to find a YAML file for this collection whose name starts with its ID: `onou5H28Wvy3kWnjxxdKQ`.+products_by_week.yaml+products_by_week_2.yaml+```### Entity IDs work with embedding-Metabase supports working with [Entity IDs](#metabase-uses-entity-ids-to-identify-and-reference-metabase-items) for questions, dashboards, and collections in [Guest embedding](../embedding/guest-embedding.md), [Modular embedding](../embedding/modular-embedding.md), [SDK](../embedding/sdk/introduction.md), and [Full app embedding](../embedding/full-app-embedding.md).+Metabase supports working with [Entity IDs](#metabase-uses-entity-ids-to-identify-metabase-items) for questions, dashboards, and collections in [Guest embedding](../embedding/guest-embedding.md), [Modular embedding](../embedding/modular-embedding.md), [SDK](../embedding/sdk/introduction.md), and [Full app embedding](../embedding/full-app-embedding.md).A high-level workflow for using Entity IDs when embedding Metabase in your app would look something like:@@ -311,179 +216,131 @@ A high-level workflow for using Entity IDs when embedding Metabase in your app w### Databases, schemas, tables, and fields are identified by name-By default, Metabase exports some database and data model settings. Exports exclude database connection strings by default. You can [explicitly include database connection strings](#customize-what-gets-exported). You can also choose to exclude the data model entirely.+By default, Metabase exports some database and data model settings. Exports exclude database connection strings by default. You can [explicitly include database connection strings](#include-database-connection-details). You can also choose to exclude the data model entirely.Metabase serializes databases and tables in the `databases` directory. It will include YAML files for every database, table, field, segment, and metric.-Databases, tables, and fields are referred to by their names (unlike Metabase-specific items, which are [referred to by Entity IDs](#metabase-uses-entity-ids-to-identify-and-reference-metabase-items)).+Databases, tables, and fields are referred to by their names (unlike Metabase-specific items, which are [referred to by Entity IDs](#metabase-uses-entity-ids-to-identify-metabase-items)).-For example, in the [Example of a serialized question](#example-of-a-serialized-question), there are several YAML keys that reference Sample Database:+For example, exported YAML has several keys that reference the database by name:```yaml-database_id: Sample Database+database_id: Sample PostgreSQL---dataset_query:- database: Sample Database+ database: Sample PostgreSQL```-In the description of the field filter (`category_filter:`) in that example, you can see the reference to the field that's used to populate the filter options:--```yaml-dimension:- - field- - - Sample Database- - PUBLIC- - PRODUCTS- - CATEGORY-```--It refers to the `CATEGORY` field in the `PRODUCTS` table in the `PUBLIC` schema in `Sample Database`. The serialized `Sample Database` in the `databases` directory will also include YAML files for this field and table.-## How import works-During import, Metabase will read the provided YAML files and create items according to the YAML specs. See [Example of a serialized question](#example-of-a-serialized-question) for how Metabase records information it needs to reconstruct an item.--Metabase will not delete items from target instance during import, but it will overwrite items that already exist.--Metabase relies on [Entity IDs](#metabase-uses-entity-ids-to-identify-and-reference-metabase-items) to figure out which items to create or overwrite, and what are the relationships between items. When importing into an instance that already has some content in it, keep in mind:--- If you import an item with an `entity_id` that doesn't exist in your target Metabase, Metabase will create a new item.--- If you import an item with an `entity_id` that already exists in your target Metabase, the existing item will be overwritten.-- In particular, this means that if you export a question, then make a change in an exported YAML file — like rename a question by directly editing the `name` field — and then import the edited file back, Metabase will try to apply the changes you made to the YAML.+Metabase will read the imported YAML files and look for [Entity IDs](#metabase-uses-entity-ids-to-identify-metabase-items) to figure out which items to create or overwrite. Imports _only_ create or overwrite items; they never delete items from the target instance.+- If you import an item with an [`entity_id`](#metabase-uses-entity-ids-to-identify-metabase-items) that doesn't exist in your target Metabase, Metabase will create a new item.+- If you import an item with an `entity_id` that already exists in your target Metabase, the import will overwrite the existing item. In particular, this means that if you export a question, then make a change in an exported YAML file — like rename a question by directly editing the `name` field — and then import the edited file back, Metabase will try to apply the changes you made to the YAML.- If you import an item with a blank `entity_id`, Metabase will create a new item. Any `serdes/meta → id` will be ignored in this case.+- All items and data sources referenced in YAML must either exist in the target Metabase already, or be included in the import. For example, if an exported YAML has the field `collection_id: onou5H28Wvy3kWnjxxdKQ`, then the collection `onou5H28Wvy3kWnjxxdKQ` must already exist in the target instance, or there must be a YAML file with the export of a collection that has this ID.-- All items and data sources referenced in YAML must either exist in the target Metabase already, or be included in the import.-- For example, if an exported YAML has the field `collection_id: onou5H28Wvy3kWnjxxdKQ`, then the collection `onou5H28Wvy3kWnjxxdKQ` must already exist in target instance, or there must be a YAML file with the export of a collection that has this ID.--## Serialization best practices--### Use the same Metabase version for source and target instance--Currently, serialization only works if source and target Metabase have the same major version.-If you are using the CLI serialization commands, the version of the .jar file that you are using to run the serialization commands should match both the source and target Metabase versions as well.--### If you're using H2 as your application database, you'll need to stop Metabase before importing or exporting--If you're using Postgres or MySQL as your application database, you can import and export while your Metabase is still running.+## Export options-### Avoid using serialization for backups+Export options let you customize what Metabase includes in an export. Every option works with both the [API](#serialization-via-the-api) and the [CLI](#serialization-with-cli-commands) — only the syntax differs.-Just a note: serialization is _not_ meant to back up your Metabase.+- For the CLI, flags go after the `export` command (for example, `metabase.jar export my_export --no-settings`).+- For the API, options are URL query parameters appended to `POST /api/ee/serialization/export?...`.-See [Backing up Metabase](./backing-up-metabase-application-data.md).+You can combine options by chaining them (`&` in URLs, multiple flags on the command line).-If you're instead looking to do a one-time migration from the default H2 database included with Metabase to a MySQL/Postgres, then use the [migration guide instead](./migrating-from-h2.md).+### Select collections-### You'll need to manually add license tokens+- **CLI:** `-c, --collection <ID[,ID,...]>`+- **API:** `collection=<ID>` (repeat to add more)-Metabase excludes your license token from exports, so if you're running multiple environments of Metabase Enterprise Edition, you'll need to manually add your license token to the target Metabase(s), either via the [Metabase user interface](../installation-and-operation/activating-the-enterprise-edition.md), or via an [environment variable](../configuring-metabase/environment-variables.md#mb_premium_embedding_token).+Type: Integer (comma-separated list for CLI; repeated parameter for API).-### Metabase adds logs to exports and imports+By default, Metabase includes all collections in the export except for personal collections. To include personal collections, add each one by numeric ID — there's no option to include all personal collections at once.-Exports: Metabase adds logs to the compressed directory as `export.log`.+You can find a collection ID in its URL. For example, a collection at `your-metabase.com/collection/42-terraforming-progress` has the ID `42`.-Imports: You can add the `-o -` flag to export logs directly into the terminal, or `-o import.log` to save to a file.+This option works the same regardless of a collection's namespace. Metabase determines the output directory (`collections/main/`, `collections/snippets/`, or `collections/transforms/`) from the collection's own namespace property, not from the ID you pass.-## Serialization with CLI commands+Examples:-> To serialize data on Metabase Cloud, use the [import and export API endpoints](#serialization-via-the-api)+CLI (include collections 1, 2, and 3):-Metabase provides [`export`](#exporting-with-cli) and [`import`](#importing-with-cli) CLI commands.--See [How export works](#how-export-works), [How import works](#how-import-works), and [Serialization best practices](#serialization-best-practices) for general information about serialization.--### Exporting with CLI+```+java --add-opens java.base/java.nio=ALL-UNNAMED -jar metabase.jar export export_name --collection 1,2,3+```-To export the contents of a Metabase instance, change into the directory where you're running the Metabase JAR and run:+API (include collections 1 and 2):```-java --add-opens java.base/java.nio=ALL-UNNAMED -jar metabase.jar export dir_name+POST http://localhost:3000/api/ee/serialization/export?collection=1&collection=2```-Where `dir_name` can be whatever you want to call the directory.+### Skip all collections-### `export` options+- **CLI:** `-C, --no-collections`+- **API:** `all_collections=false`-To view a list of `export` options, use the `help` command:+Type: Boolean.-```-java --add-opens java.base/java.nio=ALL-UNNAMED -jar metabase.jar help export-```+Default: Collections are included, unless you explicitly specify a subset with [`--collection` / `collection`](#select-collections).-Which will run and then print something like:+Excludes all content in collections from the export. Useful when you only want to export settings, data model, or other non-collection content.-```-export path & options- Serialize Metabase instance into directory at `path`.- Options:- -c, --collection ID Export only specified ID; may occur multiple times.- -C, --no-collections Do not export any content in collections.- -S, --no-settings Do not export settings.yaml- -D, --no-data-model Do not export any data model entities; useful for subsequent exports.- -f, --include-field-values Include field values along with field metadata.- -s, --include-database-secrets Include database connection details (in plain text; use caution).-```+### Skip settings-#### `--collection`+- **CLI:** `-S, --no-settings`+- **API:** `settings=false`-By default, Metabase will include all collections (except for personal collections) in the export. To include personal collections, you must explicitly add them with the `--collection` flag.+Type: Boolean.-The `--collection` flag (alias `-c`) lets you specify by ID one or more collections to include in the export. You can find the collection ID in the collection's URL, e.g., for a collection at: `your-metabase.com/collection/42-terraforming-progress`, the ID would be `42`.+Default: Settings are included.-If you want to specify multiple collections, separate the IDs with commas. E.g.,+Excludes the `settings.yaml` file that contains [site-wide settings](#general-metabase-settings-that-are-exported).-```-java --add-opens java.base/java.nio=ALL-UNNAMED -jar metabase.jar export export_name --collection 1,2,3-```+### Skip data model-#### `--no-collections`+- **CLI:** `-D, --no-data-model`+- **API:** `data_model=false`-The `--no-collections` flag (alias `-C`) tells Metabase to exclude all collections from the export.+Type: Boolean.-#### `--no-settings`+Default: Data model is included.-The `--no-settings` flag (alias `-S`) tells Metabase to exclude the `settings.yaml` file that includes [site-wide settings](#general-metabase-settings-that-are-exported), which is exported by default.+Excludes [table metadata](../data-studio/data-structure.md) settings, which admins define in **Data Studio > Data structure**. Excluding the data model is useful for subsequent exports where you only want content changes.-#### `--no-data-model`+### Include field values-The `--no-data-model` flag (alias `-D`) tells Metabase to exclude the Table Metadata settings from the export. Admins define the metadata settings in the [Table Metadata](../data-modeling/metadata-editing.md) tab of the Admin settings.+- **CLI:** `-f, --include-field-values`+- **API:** `field_values=true`-#### `--include-field-values`+Type: Boolean.-The `--include-field-values` flag (alias `-f`) tells Metabase to include the sample values for field values, which Metabase uses to present dropdown menus. By default, Metabase excludes these sample field values.+Default: Field values are excluded.-#### `--include-database-secrets`+Includes sample values for fields, which Metabase uses to present dropdown menus. Excluded by default to keep exports compact.-The `--include-database-secrets` flag (alias `-s`) tells Metabase to include connection details, including the database user name and password. By default, Metabase excludes these database connection secrets. If you don't use this flag, you'll need to manually input the credentials in the target Metabase.+### Include database connection details-### Importing with CLI+- **CLI:** `-s, --include-database-secrets`+- **API:** `database_secrets=true`-To import exported artifacts into a Metabase instance, go to the directory where you're running your target Metabase (the Metabase you want to import into) and use the following command, where `path_to_export` is the path to the export that you want to import:+Type: Boolean.-```-java --add-opens java.base/java.nio=ALL-UNNAMED -jar metabase.jar import path_to_export-```+Default: Database connection details are excluded.-Currently, you can only import exported artifacts into a Metabase instance that was created from the same version of Metabase.+Includes database connection details (including the database username and password) in plain text. Use with caution. If you don't include this option, you'll need to manually input the credentials in the target Metabase.-### `import` options+### Output directory name-Most options are defined when exporting data from a Metabase. To view a list of import flags, run:+- **CLI:** positional argument (required): `export <dir_name>`+- **API:** `dirname=<name>`-```-java --add-opens java.base/java.nio=ALL-UNNAMED -jar metabase.jar help import-```+Type: String.-Which prints out:+Default (API): `<instance-name>-<YYYY-MM-dd_HH_mm>`. For the CLI, the directory name is required. There's no default.-```-import path & options- Load serialized Metabase instance as created by the [[export]] command from directory `path`.-```+Sets the name of the directory that holds the exported YAML files.## Serialization via the API@@ -498,188 +355,194 @@ There are two endpoints:> We use `POST`, not `GET`, for the `/export` endpoint. The export operation does not modify your Metabase, but it's long and intensive, so we use `POST` to prevent accidental exports.-For now, these endpoints are synchronous. If the serialization process takes too long, the request can time out. In this case, we suggest using the CLI commands.+> The `/export` endpoint streams its response, so long exports won't time out. The `/import` endpoint is still synchronous — for very large imports, the request can time out before the import finishes. If that happens, check the server logs to see whether the import completed on the backend.-See [How export works](#how-export-works), [How import works](#how-import-works), and [Serialization best practices](#serialization-best-practices) for general information about serialization.+See [How export works](#how-export-works), [How import works](#how-import-works), [Export options](#export-options), and [Serialization best practices](#serialization-best-practices) for general information about serialization.-### API export parameters+### Passing export options via the API-You can append optional parameters to tell Metabase what to include or exclude from the export. You can also combine parameters (excluding, of course, `all_collections` and selective collections).+Append options as URL query parameters. For example, to exclude all collections:-So, assuming you're testing on `localhost`, and you want to exclude all collections from the export, you'd format the URL like so:+```+POST http://localhost:3000/api/ee/serialization/export?all_collections=false+```++To combine multiple options, chain them with `&`. For example, to exclude both settings and the data model:```-http://localhost:3000/api/ee/serialization/export?all_collections=false+POST http://localhost:3000/api/ee/serialization/export?data_model=false&settings=false```-You can include multiple parameters, separated by `&`. For example, to exclude both the settings and the data model from the export:+To select specific collections, repeat the `collection` parameter:```-http://localhost:3000/api/ee/serialization/export?data_model=false&settings=false+POST http://localhost:3000/api/ee/serialization/export?collection=1&collection=2```-### `collection`+See [Export options](#export-options) for the full list.-Type: Array of integers.+### You must compress your files when serializing via API calls-Default value: Metabase will export all collections, unless `all_collections` is set to `false`.+To keep file sizes over the network under control, both the `export` and `import` endpoints expect GZIP-compressed Tar files (`.tgz`).-To select which collections to export, include the collection IDs. For example, to include collections `1` and `2`:+#### Compress a directory-```html-collection=1&collection=2+To compress a directory (e.g., a directory named `metabase_data`).++```sh+tar -czf metabase_data.tgz metabase_data```-### `all_collections`+#### Extract a directory++To extract/unzip a directory:-Type: Boolean+```sh+tar -xvf metabase_data.tgz+```-Default: `true` (unless you specify a subset of collections with `collection`).+## Serialization workflow example-To exclude all collections:+Here's a typical serialization export/import setup with default settings via the API endpoints.-```html-all_collections=false-```+### Step 1: Set up an API key-### `settings`+1. Create an [API key](../people-and-groups/api-keys.md).+2. Assign the key to the Admin group.-Type: Boolean.+### Step 2: Export-Default: `true`.+1. Send a `curl` request to export data:-To exclude the `settings.yaml` file that contains site-wide settings:+ ```sh+ curl \+ -H 'X-API-Key: YOUR_API_KEY' \+ -X POST 'https://your-metabase-url/api/ee/serialization/export' \+ -o metabase_data.tgz+ ```-```html-settings=false-```+ substituting `YOUR_API_KEY` with your API key and `your-metabase-url` with the URL of your Metabase instance.-### `data_model`+ This command will download the files as a GZIP-compressed Tar file named `metabase_data.tgz`.-Type: Boolean.+2. Unzip the compressed file:-Default: `true`.+ ```sh+ tar -xvf metabase_data.tgz+ ```-To exclude the [Table Metadata](../data-modeling/metadata-editing.md):+ The extracted directory will be called something like `<instance-name>-<YYYY-MM-dd_HH_mm>`, with the instance name, date, and time of the export.-```-data_model=false-```+### Step 3: Import-### `field_values`+1. Compress the directory containing serialized Metabase application data.-Type: Boolean.+ Let's say you have your YAML files with Metabase application data in a directory called `metabase_data`. Before importing those files to your target Metabase, you'll need to compress those files.-Default: `false`.+ ```sh+ tar -czf metabase_data.tgz metabase_data+ ```-To include the sample values for field values, which Metabase uses to present dropdown menus:+2. POST to `/api/ee/serialization/import`.-```-field_values=true-```+ From the directory where you've stored your GZIP-compressed file, run:-### `database_secrets`+ ```sh+ curl -X POST \+ -H 'X-API-Key: YOUR_API_KEY' \+ -F 'file=@metabase_data.tgz' \+ 'https://your-metabase-url/api/ee/serialization/import' \+ -o -+ ```-Type: Boolean.+ substituting `YOUR_API_KEY` with your API key and `your-metabase-url` with your Metabase instance URL.+ The `-o -` option will output logs in the terminal.-Default: `false`.+ > If you import Metabase data into the same Metabase as you exported it from, you will overwrite your existing questions, dashboards, etc. See [How import works](#how-import-works).-To include database connection details, like the database username and password:+## Serialization with CLI commands-```html-database_secrets=true-```+> To serialize data on Metabase Cloud, use the [import and export API endpoints](#serialization-via-the-api)-### `dirname`+Metabase provides [`export`](#exporting-with-cli) and [`import`](#importing-with-cli) CLI commands.-Type: String.+See [How export works](#how-export-works), [How import works](#how-import-works), [Export options](#export-options), and [Serialization best practices](#serialization-best-practices) for general information about serialization.-Default: `<instance-name>-<YYYY-MM-dd_HH_mm>`+### Exporting with CLI-To specify a different directory:+To export the contents of a Metabase instance, change into the directory where you're running the Metabase JAR and run:```-dirname=name_of_your_directory+java --add-opens java.base/java.nio=ALL-UNNAMED -jar metabase.jar export dir_name```-### You must compress your files when serializing via API calls+Where `dir_name` can be whatever you want to call the directory.-To keep file sizes over the network under control, both the `export` and `import` endpoints expect GZIP-compressed Tar files (`.tgz`).+### Customizing the export-#### Compress a directory+To customize what's included in an export, add flags after the `export` command. See [Export options](#export-options) for the full list. You can combine multiple flags:-To compress a directory (e.g., a directory named `metabase_data`).--```sh-tar -czf metabase_data.tgz metabase_data+```+java --add-opens java.base/java.nio=ALL-UNNAMED -jar metabase.jar export my_export -S -D --include-field-values```-#### Extract a directory+You can also print all available flags with the `help` command:-To extract/unzip a directory:--```sh-tar -xvf metabase_data.tgz+```+java --add-opens java.base/java.nio=ALL-UNNAMED -jar metabase.jar help export```-## Serialization API example+### Importing with CLI-### Step 1: Set up an API key+To import exported artifacts into a Metabase instance, go to the directory where you're running your target Metabase (the Metabase you want to import into) and use the following command, where `path_to_export` is the path to the export that you want to import:-1. Create an [API key](../people-and-groups/api-keys.md).-2. Assign the key to the Admin group+```+java --add-opens java.base/java.nio=ALL-UNNAMED -jar metabase.jar import path_to_export+```-### Step 2: Export+### `import` options-1. Send a `curl` request to export data:+Most options are defined when exporting data from a Metabase. To view a list of import flags, run:- ```sh- curl \- -H 'X-API-Key: YOUR_API_KEY' \- -X POST 'https://your-metabase-url/api/ee/serialization/export' \- -o metabase_data.tgz- ```+```+java --add-opens java.base/java.nio=ALL-UNNAMED -jar metabase.jar help import+```- substituting `YOUR_API_KEY` with your API key and `your-metabase-url` with the URL of your Metabase instance.+Which prints out:- > We use `POST`, not `GET`, for the `/export` endpoint.+```+import path & options+ Load serialized Metabase instance as created by the [[export]] command from directory `path`.+```- This command will download the files as a GZIP-compressed Tar file named `metabase_data.tgz`.+## Serialization best practices-2. Unzip the compressed file:+### Avoid using serialization for backups- ```sh- tar -xvf metabase_data.tgz- ```+Serialization is _not_ meant to back up your Metabase.- The extracted directory will be called something like `metabase-yyyy-MM-dd_HH-mm`, with the date and time of the export.+See [Backing up Metabase](./backing-up-metabase-application-data.md).-### Step 3: Import+If you're instead looking to do a one-time migration from the default H2 database included with Metabase to a MySQL/Postgres, then use the [migration guide instead](./migrating-from-h2.md).-1. Compress the directory containing serialized Metabase application data.+### Use the same Metabase major version for source and target instance- Let's say you have your YAML files with Metabase application data in a directory called `metabase_data`. Before importing those files to your target Metabase, you'll need to compress those files.+Currently, serialization only works if source and target Metabase have the same major version. If you're using the CLI serialization commands, the version of the .jar file that you are using to run the serialization commands should match both the source and target Metabase versions as well.- ```sh- tar -czf metabase_data.tgz metabase_data- ```+Metabase will log a warning if the versions doesn't match, but it won't block the import.-2. POST to `/api/ee/serialization/import`.+### If you're using H2 as your application database, you'll need to stop Metabase before importing or exporting- From the directory where you've stored your GZIP-compressed file, run:+Avoid using H2 as your application database! This note is just for when you're playing around with a local version of Metabase. If you're using Postgres or MySQL as your application database, you can import and export while your Metabase is still running, no problemo.- ```sh- curl -X POST \- -H 'X-API-Key: YOUR_API_KEY' \- -F 'file=@metabase_data.tgz' \- 'https://your-metabase-url/api/ee/serialization/import' \- -o -- ```+### You'll need to manually add license tokens- substituting `YOUR_API_KEY` with your API key and `your-metabase-url` with your Metabase instance URL.- The `-o -` option will output logs in the terminal.+Metabase excludes your license token from exports, so if you're running multiple environments of Metabase Enterprise Edition, you'll need to manually add your license token to the target Metabase(s), either via the [Metabase user interface](../installation-and-operation/activating-the-enterprise-edition.md), or via an [environment variable](../configuring-metabase/environment-variables.md#mb_premium_embedding_token).- > If you import Metabase data into the same Metabase as you exported it from, you will overwrite your existing questions, dashboards, etc. See [How import works](#how-import-works).+### Metabase adds logs to exports and imports++- Exports: Metabase adds logs to the compressed directory as `export.log`.+- Imports: You can add the `-o -` flag to export logs directly into the terminal, or `-o import.log` to save to a file.## Other uses of serialization@@ -691,7 +554,7 @@ We're providing some directions on how to approach these unsupported use cases,> Duplicating assets via serialization, while technically possible, isn't officially supported, so do so at your own risk. The risk here being that you may have to manage long chains of dependencies, which can make it more likely you'll forget to edit an entity ID, or overwrite an entity ID that already exists. So make sure you're doing backups and checking your changes into version control.-Using serialization to duplicate content is not trivial, because you'll need to wrangle [Entity IDs](#metabase-uses-entity-ids-to-identify-and-reference-metabase-items) for all the items you want to duplicate — _and_ the IDs for all the items that are related to those items — to avoid overwriting existing data.+Using serialization to duplicate content is not trivial, because you'll need to wrangle [Entity IDs](#metabase-uses-entity-ids-to-identify-metabase-items) for all the items you want to duplicate — _and_ the IDs for all the items that are related to those items — to avoid overwriting existing data.Before starting this perilous journey, review [how export works](#how-export-works) and [how import works](#how-import-works), and contact [[email protected]](mailto:[email protected]) if you have any questions.@@ -711,7 +574,7 @@ For example, to duplicate a collection that contains _only_ questions that are b1. In Metabase, create a "template" collection and add the items you'd like to duplicate.2. In Metabase, create a new collection which will serve as the target for duplicated items.-3. Export the template collection and the target collection (you can use [export parameters](#customize-what-gets-exported) to export only a few collections).+3. Export the template collection and the target collection (you can use the [Select collections](#select-collections) option to export only a few collections).The YAML files for template questions in the export will have their own Entity IDs and reference the Entity ID of the template collection.4. Get the Entity ID of the target collection from its export.5. In the YAML files for questions in the template collection export:@@ -742,7 +605,7 @@ Your databases must have the same engine, and ideally they should have the sameYou'll need to keep in mind:- Databases, tables and fields are [referred to in Metabase by name](#databases-schemas-tables-and-fields-are-identified-by-name)-- Database connection details are not exported by default. To export database connection details, you'll need to [specify this in export parameters](#customize-what-gets-exported).+- Database connection details are not exported by default. To export database connection details, you'll need to enable the [Include database connection details](#include-database-connection-details) option.- Databases, tables and fields referenced by an item should either already exist in the target Metabase, or be included in the import.For example, if you want to switch all questions in the `Movie reviews` collection to use the `Romance` database instead of the `Horror` database, and _both databases have the same schema_, you could follow a process like this:@@ -766,12 +629,11 @@ If you're upgrading from Metabase version 46.X or older, here's what you need to- The `export` command replaces the `dump` command.- The `import` command replace the `load` command.-A few other changes to call out:+Starting with Metabase 60, the export format changed:-- The exported YAML files have a slightly different structure:- - Metabase will prefix each file with a 24-character Entity ID (like `IA96oUzmUbYfNFl0GzhRj_accounts_model.yaml`).- You can run a Metabase command to [drop Entity IDs](./commands.md#drop-entity-ids).- - The file tree is slightly different.+- File and directory names now use human-readable names (like `accounts_model.yaml`) instead of Entity ID prefixes. Entity IDs are still present inside each YAML file.+- Fields with default values (like `archived: false`) and null-valued fields are omitted from the YAML output, keeping files compact.+- The file tree organizes collections by namespace (`main/`, `snippets/`, `transforms/`), and entities are stored inside their parent collection folder.- To serialize personal collections, you just need to include the personal collection IDs in the list of comma-separated IDs following the `-c` option (short for `--collection`).If you've written scripts to automate serialization, you'll need to:@@ -780,8 +642,13 @@ If you've written scripts to automate serialization, you'll need to:- Update those scripts with the new commands. See the new [export options](#export-options).- If your scripts do any post-processing of the exported YAML files, you may need to update your scripts to accommodate the slightly different directory and YAML file structures.+## Let us know how we can improve serialization++We're interested in how we can improve serialization to suit your workflow. [Upvote an existing issue](https://github.com/metabase/metabase/issues?q=is%3Aissue+is%3Aopen+serialization+label%3AOperation%2FSerialization) to let us know it's important to you. If a relevant issue doesn't yet exist, please create one and tell us what you need.+## Further reading+- [Remote Sync](./remote-sync.md)- [Serialization tutorial](https://www.metabase.com/learn/metabase-basics/administration/administration-and-operation/serialization)- [Database routing](../permissions/database-routing.md)- [Multiple environments](https://www.metabase.com/learn/metabase-basics/administration/administration-and-operation/multi-env)