{"id":18646751,"url":"https://github.com/metabase/template-clone-prototype","last_synced_at":"2025-11-05T05:30:32.151Z","repository":{"id":253104368,"uuid":"842465278","full_name":"metabase/template-clone-prototype","owner":"metabase","description":null,"archived":false,"fork":false,"pushed_at":"2024-08-14T18:23:17.000Z","size":9,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":5,"default_branch":"main","last_synced_at":"2024-12-27T12:09:17.522Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/metabase.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-14T12:07:51.000Z","updated_at":"2024-10-17T16:16:57.000Z","dependencies_parsed_at":"2024-11-08T10:15:26.260Z","dependency_job_id":null,"html_url":"https://github.com/metabase/template-clone-prototype","commit_stats":null,"previous_names":["metabase/template-clone-prototype"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metabase%2Ftemplate-clone-prototype","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metabase%2Ftemplate-clone-prototype/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metabase%2Ftemplate-clone-prototype/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metabase%2Ftemplate-clone-prototype/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/metabase","download_url":"https://codeload.github.com/metabase/template-clone-prototype/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239449588,"owners_count":19640535,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T06:22:26.233Z","updated_at":"2025-11-05T05:30:32.122Z","avatar_url":"https://github.com/metabase.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# About\n\nThis is a prototype to do deep copies of Metabase collections.\n\n## Requirements\n* A Metabase instance with a Pro license, to unlock the serialization feature to import/export the collection\n* An API key, which can be created on Metabase at `/admin/settings/authentication/api-keys` \n* A collection you want to clone or change the data source for \n\n## Installation\n\n* Make sure you have Ruby installed\n* Check out this repo with `git clone https://github.com/metabase/template-clone-prototype.git`\n* Install the dependencies with `bundle install`\n* Test if the dependencies are satisfied by running `ruby clone.rb --help`.\n\n## Supported use cases and usage\n\n1. Clone a collection, optionally updating the underlying data source\n2. Change the data source of a collection without duplicating or renaming it\n   \n## Limitations\n\nIt can only swap out one data source at a time. If the items in your collections depend on multiple data sources, you might have to do several runs. This scenario has not been tested yet.\n\n## Example usage\n\n1. Locate the ID of the collection to use as template. In this example it's 9. Export the collection via serialization API by specifying `collection=ID`. \n\n```sh\ncurl \\        -H 'x-api-key: API_KEY' \\  \n-X POST 'http://localhost:3000/api/ee/serialization/export?settings=false\u0026data_model=false\u0026collection=9' \\                                      \n-o metabase_data.tgz\n```\n\n2. Extract data from the tarball. This will create a directory with YAML files and subdirectories inside of it. The directory name is based on the site name and timestamp of the export.\n\n```sh\ntar xzf metabase_data.tgz\n```\n\n3. Run this tool pointing to the directory extracted from the tarball, and providing the source and target names for the data source names.\n\nIf want ato load a copy into the same instance, you will want to use the following parameters:\n* the `--source-datasource` and `--target-datasource` to swap out the data source (these are required for now, so if you don't want to change the data source just use the same data source name in both)\n* the `--duplicate` parameter if you want a copy, and omit this parameter if you want to overwrite the collection changing it's datasource\n* the `--new-collection-name` to give the new copy a different name or to change the name of the collection\n\n```sh\nruby clone.rb --yaml-files foobar-2024-08-09_20-57 --source-datasource \"Old database\" --target-datasource \"New database\" --new-collection-name \"Super fancy new collection\" --duplicate\n```\n\n* `--yaml-files` **required**, should point to the directory you extracted from the tarball\n* `--source-datasource` **required**, the display name of the data source to replace (check `/admin/databases` on Metabase)\n* `--target-datasource` **required**, the display name of the data source to replace with (check `/admin/databases` on Metabase)\n* `--new-collection-name` **optional**, the new name for the collection \n* `--duplicate` **optional**, will create new entity IDs for all items to clone entire collection and its contents\n\n4. Create a tarball with the modified files\n\n```sh\ntar -czf metabase_data_modified.tgz foobar-2024-08-09_20-57\n```\n\n5. Import the tarball via serialization API\n   \n```sh\ncurl -X POST \\  -H 'x-api-key: API_KEY' \\\n  -F file=@metabase_data_modified.tgz \\\n  'http://localhost:3000/api/ee/serialization/import' \\\n  -o -\n```\n\n## Use cases and parameters\n\n### Change the datasource from prod to dev\n\n```sh\nruby clone.rb --yaml-files foobar-2024-08-09_20-57 --source-datasource \"Production\" --target-datasource \"Development\" --new-collection-name \"Collection now pointing to dev\"\n```\n\n### Clone the collection without changing the datasource\n\n```sh\nruby clone.rb --yaml-files foobar-2024-08-09_20-57 --source-datasource \"Production\" --target-datasource \"Production\" --new-collection-name \"Customer collection copy\" --duplicate\n```\n\n### Clone the collection, changing the datasource\n\n```sh\nruby clone.rb --yaml-files foobar-2024-08-09_20-57 --source-datasource \"Production\" --target-datasource \"Customer A Production\" --new-collection-name \"Customer A collection\" --duplicate\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmetabase%2Ftemplate-clone-prototype","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmetabase%2Ftemplate-clone-prototype","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmetabase%2Ftemplate-clone-prototype/lists"}