Migrate exising Metabase from .jar/ H2 to AWS Elastic Beanstalk/ Postgres

Hi Metabase Users and Experts -

I have been using metabase locally on a desktop/H2 database. I am planning to migrate it to production host. I liked the option of AWS Beanstalk, but found that the pre-configured file (http://www.metabase.com/docs/latest/operations-guide/running-metabase-on-elastic-beanstalk.html) is an entirely new metabase app. Is there a way I can migrate the existing metabase app (With all queries and settings) to AWS Beanstalk?

Thanks in advance!

you’ll need to migrate your application database as described in http://www.metabase.com/docs/v0.22.2/operations-guide/start.html#migrating-from-using-the-h2-database-to-mysql-or-postgres

I have created an EC2 instance (as the host for running the jar file). Also created an empty Postgres RDS on the same AWS account. I took the backup of the previous h2 application database as metabase.db.h2.db

When I ssh into the EC2 to run the commands:

export MB_DB_TYPE=postgres
export MB_DB_DBNAME=postgres
export MB_DB_PORT=5432
export MB_DB_USER=username
export MB_DB_PASS=password
export MB_DB_HOST=metabase-postgres.xyzxyzxyz.us-west-2.rds.amazonaws.com
java -jar metabase.jar load-from-h2 /home/ec2-user/metabase/metabase.db.h2.db

I get the error :
02-28 05:01:20 INFO metabase.db :: Database Migrations Current … :white_check_mark:
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]
Temporarily disabling DB constraints…
[OK]
org.h2.jdbc.JdbcSQLException: Database “/home/ec2-user/metabase/metabase.db.h2.db” not found [90013-193]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
at org.h2.message.DbException.get(DbException.java:179)
at org.h2.message.DbException.get(DbException.java:155)
at org.h2.engine.Engine.openSession(Engine.java:62)
at org.h2.engine.Engine.openSession(Engine.java:176)
at org.h2.engine.Engine.createSessionAndValidate(Engine.java:154)
at org.h2.engine.Engine.createSession(Engine.java:137)
at org.h2.engine.Engine.createSession(Engine.java:27)
at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:349)
at org.h2.jdbc.JdbcConnection.(JdbcConnection.java:115)
at org.h2.jdbc.JdbcConnection.(JdbcConnection.java:99)
at org.h2.Driver.connect(Driver.java:69)
at java.sql.DriverManager.getConnection(DriverManager.java:571)
at java.sql.DriverManager.getConnection(DriverManager.java:187)
at clojure.java.jdbc$get_connection.invokeStatic(jdbc.clj:272)
at clojure.java.jdbc$get_connection.invoke(jdbc.clj:193)
at metabase.cmd.load_from_h2$load_data_BANG_.invokeStatic(load_from_h2.clj:142)
at metabase.cmd.load_from_h2$load_data_BANG_.invoke(load_from_h2.clj:141)
at metabase.cmd.load_from_h2$load_from_h2_BANG_$fn__32108.invoke(load_from_h2.clj:216)
at clojure.java.jdbc$db_transaction_STAR_.invokeStatic(jdbc.clj:613)
at clojure.java.jdbc$db_transaction_STAR_.invoke(jdbc.clj:585)
at clojure.java.jdbc$db_transaction_STAR_.invokeStatic(jdbc.clj:629)
at clojure.java.jdbc$db_transaction_STAR_.invoke(jdbc.clj:585)
at clojure.java.jdbc$db_transaction_STAR_.invokeStatic(jdbc.clj:598)
at clojure.java.jdbc$db_transaction_STAR_.invoke(jdbc.clj:585)
at metabase.cmd.load_from_h2$load_from_h2_BANG_.invokeStatic(load_from_h2.clj:213)
at metabase.cmd.load_from_h2$load_from_h2_BANG_.invoke(load_from_h2.clj:206)
at clojure.lang.Var.invoke(Var.java:379)
at metabase.core$load_from_h2.invokeStatic(core.clj:219)
at metabase.core$load_from_h2.invoke(core.clj:212)
at clojure.lang.AFn.applyToHelper(AFn.java:154)
at clojure.lang.AFn.applyTo(AFn.java:144)
at clojure.core$apply.invokeStatic(core.clj:646)
at clojure.core$apply.invoke(core.clj:641)
at metabase.core$run_cmd$fn__32862.invoke(core.clj:273)
at metabase.core$run_cmd.invokeStatic(core.clj:273)
at metabase.core$run_cmd.doInvoke(core.clj:272)
at clojure.lang.RestFn.applyTo(RestFn.java:139)
at clojure.core$apply.invokeStatic(core.clj:648)
at clojure.core$apply.invoke(core.clj:641)
at metabase.core$_main.invokeStatic(core.clj:287)
at metabase.core$_main.doInvoke(core.clj:283)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at metabase.core.main(Unknown Source)
Command failed with exception: Database “/home/ec2-user/metabase/metabase.db.h2.db” not found [90013-193]

I do have the correct file at the location specified

[ec2-user@ip-172-31-16-17 metabase]$ ls -lh “/home/ec2-user/metabase/metabase.db.h2.db”
-rw-rw-r-- 1 ec2-user ec2-user 276M Feb 24 20:19 /home/ec2-user/metabase/metabase.db.h2.db

Can anyone suggest what can be done ?

try using java -jar metabase.jar load-from-h2 /home/ec2-user/metabase/metabase.db
this might be a case where we refer to the DB name instead of the file (H2 adds h2.db)

Before going with the full service + postgres implementation in EB for metabase, it’s worth noting that using the RDS instance deployed by EB is not recommended for production environments.

The recommendation is to deploy a non-EB RDS PG instance, and then use EB for just the MB service.

See this thread for more info: Best practice for having RDS as part of EB environment and follow the link to AWS for a guide on how to decouple the service from the persistence.