Copy dashboards and questions from one server to another

I’m a BI consultant and normally work on a local server before deploying ‘stuff’ to a customer’s live server.
Is it possible to take parts of a metabase install from one server to another? I’d like to be able to migrate/overwrite data definitions, questions and dashboards without overwriting a customer’s users and other data.

3 Likes

I’ll answer my own question!

First, there’s no ‘proper’ way to do this.
Second, it can be tricky to maintain stuff like the database_id if you try and copy across.
Third, make sure you’re using a real database for your dashboards (I used MySQL).

Start of by making a copy of your customer’s database on your local server.
Have multiple bat files (I’m working in Windows) to start the jar, one for each customer.
Modify the database connection strings to work with your local database once running.

Do your work.

Now to transfer. You can create SQL scripts to move the new rows. I found it easier to use copy and paste from within MySQL Workbench, but that would depend upon you having access to both databases at once. If you’ve modified something rather than changing, you need to update the original row. Don’t delete then insert (I’m not sure if cascading deletes are enabled).

Questions are stored in the report_card table. Nice and easy to move.
Metrics are in metric
Metalayer stuff is in metabase_field. I think this is best modified on the customer’s server, or by just restoring your database over their existing one. There are 1000s of rows and it’s all updates rather than inserts.
Databases are in metabase_database, though I doubt there’s much stuff to modify in there.
Dimensions displayed via foreigh keys are in dimension
Segments are in segment
Dashboards are in report_dashboard and their contents in report_dashboardcard

Hopefully, someone will come along shortly and tell me there’s a MySQL utility that can copy changes across. I know there are similar for MS SQL.

7 Likes

Still talking to myself.
Rather than copy and paste rows, MySQL Workbench allows you to export highlighted rows to csv. Then just a case of importing at the customer database.

1 Like

I’m listening :slight_smile:

1 Like

This has been the problem since the start for new users.

There should be a function in the UI something like “Export Question as CSV/JSON” and then you can import it in the other metabase instance.

For sure, you’re not alone. What you did should be the best option at the moment.

2 Likes

Something that will make this difficult, even in the future, is the design of the metabase database. There is no unique reference for any entity, just an integer primary key. That makes it impossible to maintain any connection between questions on different servers.
First change to support this needs to be a GUID on every entity. That way, it would be possible to synchronise servers.

3 Likes

As a newbie to Metabase, I've been looking around for a solution to these synchronisation problems, only to find that no official ("proper") solution exists. As I've stated here, Metabase is a great product, but import/export functionality is a requirement for serious development and large-scale deployments.

I'm not sure many new users actually come from a background that would immediately require such functionality. But as the company grows, these features soon become essential. The lack thereof is only feasible if

  1. the database isn't particularly large
  2. there's only a single person working on the Metabase db (no need for git-like branch management, at most one development instance...)
  3. there's only a single production instance running

If these conditions are met (which would be very rare for large companies), then I can see why the current feature set of Metabase would suffice.

Currentlly I am using MS sqlserver, I cannot find it, Plz help me

@jinwang.du Please just make one post: How to backup&restore metabase(questions,dashbords) based on MS Sqlserver

i’ve made my script and uploaded it on github: GitHub - slavashaz/Metabase-Dashboard-Cloner: script that can copy your dashboard and link it to another db. · GitHub
@AndrewMBaines

1 Like

That’s nice, but not quite what I was trying to do. I want to copy from one Metabase server to another. I know serialisation is there, but not helpful with Open Source version.

What I have experimented with is have the same database IDs on each server, then use a different ID range for questions etc on the dev server. That way I can copy records across without damaging the customer’s server.

Not tried using this in anger, but worked in test.

so what you are trying to do is copying dashboard from test-metabase.com to prod.metabase.com for example? am I right? is it the same db btw? or is it different but identical databases?

Same database. Ideally, overwriting dashboards in same collection with same name.

I'll see what I can do about it. Is it still relevant for you?

Yes. I currently do dev work on live server which is far from ideal.

I think I will firstly make it the way that it doesnt overwrite dashboards but makes a new one. So we can be sure our data is safe. If it passes the tests and stuff I'll think of "overwriting"

Some of my customers have a ‘master’ dashboard that contains links to other dashboards to help navigation. Also, users may have bookmarks defined.

That said, let’s start with the safe option. Let me know if you need any help testing.

can you make a gitbub issue in my repository please? so we can continue working on it there

@AndrewMBaines i’ve made the script, you can check it out. it’s in cross_metabase directory on github. all you have to do is configure the config_cross.json and run the script. try it out on test server or you can even do it on prod but make sure you are not using the same name of the collection you already have. this script makes a new collection with the name you choose. if you have any questions it will be better if you ask them on github with the issue I think. anyways, i’ll check here as well.
readme is also a good thing to read before running the script.
what you need to run the script:

  1. python from the official site
  2. run the “pip install requests” in the directory where you place the script and the config
  3. configure the “config_cross.json“ with your data
  4. run “python clone_cross_metabase_en.py

that’s pretty much it. anyways, i’m always here to help you.

I’m getting a problem with the certificate verifying. Same problem with openssl, so must be a problem at my customer’s server.

Chat GPT recommends adding certifi to the request but I don’t know python well enough to start mucking about:

import requests
import certifi
response = requests.get( "http://<<server>/api/session",
 verify=certifi.where())

It would also be better if you could use API keys rather than username/password