Importing a Database

If you are migrating your database from another service or environment or restoring a database backup, the following steps describe how to load your database file into a Healthcare Blocks managed database. Alternately, you can create a support ticket for assistance.

First, you will need a database dump file that is used to recreate your database schema, objects, and data. This file can be generated using tools such as mongodump, mysqldump, or pg_dump, depending on your database engine type. See the database backups topic for details.

Next, use the SCP command or client on your local development machine to transfer the dump file to your Healthcare Blocks virtual server.

scp /path/to/local_file \
  username@server_ip_or_domain_name:/target_directory/

Tip: before transferring your file, check the available storage on your system by running the df -h command.

To restore the file to your database, use the appropriate database shell command:

MongoDB

mongorestore -vvv -h SERVER -u DATABASE_USER \
  --ssl --sslCAFile /etc/ssl/hcb_ca.pem \
  --drop \
  --archive=<backup file name>

MySQL

mysql -h SERVER -u DATABASE_USER -p --ssl < backup.sql

If your dump file contains multiple databases, you can specify a restore of a single database:

mysql -h SERVER -u DATABASE_USER -p --ssl --one-database DATABASE_NAME < backup.sql

If your backup file is compressed, you can save a step and not have to decompress the file first by running the following combined commands:

gzip -dc < backup.sql.gz | mysql -h SERVER -u DATABASE_USER -p --ssl DATABASE_NAME

PostgreSQL

psql postgresql://DATABASE_USER@SERVER/DATABASE_NAME?sslmode=require < backup.sql

Don't forget to delete the database dump file from your server!