How to load metabase's database backup inside Docker container?


#1

When I first installed Metabase with Docker, I run the oneliner,

$ docker run -d -p 3000:3000 --name metabase metabase/metabase

Since then I’ve made a whole bunch of dashboards and questions…

I’ve made a backup like this,

$ docker exec -t metabase cat metabase.db.mv.db > /tmp/metabase.db.mv.db

So now, I have the backup in my machine. Now I try loading the backup setting the MB_DB_FILE env variable, but metabase creates a new H2 database…

$ docker run -d -p 3000:3000 -v /tmp:/tmp -e "MB_DB_FILE=/tmp/metabase.db.mv.db" --name metabase metabase/metabase

How could I load a backup database inside the Docker container?


#2

You need to set MB_DB_FILE to something like metabase.db because H2 adds the extension automatically.

So the actual file is called /tmp/metabase.db.mv.db but the env var is MB_DB_FILE=/tmp/metabase.db


#3

So you say to name my backup metabase.db.mv.db, but run docker with MB_DB_FILE=metabase.db

That way, my backup metabase.db.mv.db gets overrided by a new Metabase H2 database (same name)


#4

Now I’ve tried this,

Create a new docker metabase container with mapped storage volume.
$ docker stop metabase
Replaced the new database metabase.db.mv.db, with my backup (same name).
$ docker start metabase
Started the container again, but metabase.db.mv.db was overriden by a new one.


#6

:cactus: It didn’t work

Those are the cases:

  1. run a new container with mapped volume and MB_DB_FILE=metabase.db (but local file named metabase.db.mv.db)
  2. run a new container with mapped volume, stop it, replace its database with my backup, and start container again.

In both cases, Metabase overrides the backup. It doesn’t load it.


#7

do you have any updates on this issue, i am also dealing with the same problem. @autorun


#8

Yes… make sure you have the backup file named “metabase.db.mv.db”.
Its confusing because you have to tell “MB_DB_FILE=/tmp/metabase.db” instead.
So if you have your metabase backup (metabase.db.mv.db) in ~/metabase, run this

docker run -d -v ~/metabase:/tmp -e MB_DB_FILE=/tmp/metabase.db --name metabase metabase/metabase


#9

It is still unable to load data. I am running exactly this command. with metabase.db.mv.db in myLocation.

docker run -p 3000:3000 -v ~/myLocation:/tmp -e "MB_DB_FILE=/tmp/metabase.db" --name metabase metabase/metabase

and getting this output;

04-10 12:34:56 INFO metabase.util :: Loading Metabase...
04-10 12:34:56 INFO util.encryption :: DB details encryption is DISABLED for this Metabase instance. 🔓
04-10 12:35:06 INFO metabase.core :: Starting Metabase in STANDALONE mode
04-10 12:35:06 INFO metabase.core :: Launching Embedded Jetty Webserver with config:
 {:port 3000, :host "adb5e799e60f"}
04-10 12:35:06 INFO metabase.core :: Starting Metabase version v0.23.1 (df90b9e release-0.23.1) ...
04-10 12:35:06 INFO metabase.core :: System timezone is 'GMT' ...
04-10 12:35:06 DEBUG metabase.driver :: Registered driver :bigquery 🚚
04-10 12:35:06 DEBUG metabase.driver :: Registered driver :crate 🚚
04-10 12:35:06 DEBUG metabase.driver :: Registered driver :druid 🚚
04-10 12:35:06 DEBUG metabase.driver :: Registered driver :googleanalytics 🚚
04-10 12:35:06 DEBUG metabase.driver :: Registered driver :h2 🚚
04-10 12:35:07 DEBUG metabase.driver :: Registered driver :mongo 🚚
04-10 12:35:07 DEBUG metabase.driver :: Registered driver :mysql 🚚
04-10 12:35:07 DEBUG metabase.driver :: Registered driver :postgres 🚚
04-10 12:35:07 DEBUG metabase.driver :: Registered driver :redshift 🚚
04-10 12:35:07 DEBUG metabase.driver :: Registered driver :sqlite 🚚
04-10 12:35:07 DEBUG metabase.driver :: Registered driver :sqlserver 🚚
04-10 12:35:07 INFO metabase.core :: Setting up and migrating Metabase DB. Please sit tight, this may take a minute...
04-10 12:35:07 INFO metabase.db :: Verifying h2 Database Connection ...
04-10 12:35:07 INFO metabase.db :: Verify Database Connection ...  ✅
04-10 12:35:07 INFO metabase.db :: Running Database Migrations...
04-10 12:35:07 INFO metabase.db :: Setting up Liquibase...
04-10 12:35:07 INFO metabase.db :: Liquibase is ready.
04-10 12:35:07 INFO metabase.db :: Checking if Database has unrun migrations...
04-10 12:35:31 INFO metabase.db :: Database Migrations Current ...  ✅
com.mchange.v2.cfg.DelayedLogItem [ level -> FINE, text -> "The configuration file for resource identifier 'hocon:/reference,/application,/c3p0,/' could not be found. Skipping.", exception -> null]
04-10 12:35:31 INFO db.migrations :: Running all necessary data migrations, this may take a minute.
04-10 12:35:32 INFO db.migrations :: Finished running data migrations.
04-10 12:35:32 INFO metabase.events :: Starting events listener: metabase.events.activity-feed 👂
04-10 12:35:32 INFO metabase.events :: Starting events listener: metabase.events.dependencies 👂
04-10 12:35:32 INFO metabase.events :: Starting events listener: metabase.events.driver-notifications 👂
04-10 12:35:32 INFO metabase.events :: Starting events listener: metabase.events.last-login 👂
04-10 12:35:32 INFO metabase.events :: Starting events listener: metabase.events.metabot-lifecycle 👂
04-10 12:35:32 INFO metabase.events :: Starting events listener: metabase.events.notifications 👂
04-10 12:35:32 INFO metabase.events :: Starting events listener: metabase.events.revision 👂
04-10 12:35:32 INFO metabase.events :: Starting events listener: metabase.events.sync-database 👂
04-10 12:35:32 INFO metabase.events :: Starting events listener: metabase.events.view-log 👂
04-10 12:35:32 INFO metabase.task :: Loading tasks namespace: metabase.task.follow-up-emails 📆
04-10 12:35:32 INFO metabase.task :: Loading tasks namespace: metabase.task.send-anonymous-stats 📆
04-10 12:35:32 INFO metabase.task :: Loading tasks namespace: metabase.task.send-pulses 📆
04-10 12:35:32 INFO metabase.task :: Loading tasks namespace: metabase.task.sync-databases 📆
04-10 12:35:32 INFO metabase.task :: Loading tasks namespace: metabase.task.upgrade-checks 📆
04-10 12:35:32 INFO metabase.core :: Looks like this is a new installation ... preparing setup wizard
04-10 12:35:32 INFO metabase.core :: Please use the following url to setup your Metabase installation:

#10

If anyone still having this problem, here is what i did and worked well:

First, backup the metabase.db directory (yes, it is a folder inside /):

docker cp metabase:/metabase.db /home/metabase

To restore into a new container:

 docker run -d -p 3001:3000 --name metabase2 -v /home/metabase/metabase.db:/metabase.db -e "MB_DB_FILE=/metabase.db" metabase/metabase

Notice that i’ve changed the exposed port to 3001 and container name to metabase2.
If i hit http://localhost:3001 then it is all good.


#11

The metabase team should add this to the tutorial somewhere. You made it so much clearer. Thanks!!

By any chance do you know how to upgrade metabase in a docker container without having to make a backup but keeping the metabase.db from the older container? (I already made the backup in case something fails)