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 the Healthcare Blocks database service.
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:/data/target_directory/
To restore the file to your database, use the appropriate database shell command:
MongoDB
MongoDB 3.2 and after:
mongorestore -vvv -h SERVER -u DATABASE_USER \ --ssl --sslCAFile /etc/ssl/hcb_ca.pem \ --drop \ --archive=<backup file name>
Pre-MongoDB 3.2:
mongorestore -h SERVER -u DATABASE_USER --ssl --drop <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
Note: if you receive an error - "the input device is not a TTY" - you'll need to enter the running container first. Just be sure the backup file is sitting in /data/mysql/ before you enter the container.
cp backup.sql /data/mysql/ docker exec -it mysql bash cd /var/lib/mysql mysql -p < backup.sql exit
PostgreSQL
psql postgresql://DATABASE_USER@SERVER/?sslmode=require < backup.sql
If you receive an error - "the input device is not a TTY" - you'll need to enter the running container first:
cp backup.sql /data/postgres/data/ docker exec -it postgres bash cd /var/lib/postgresql/data psql -U DATABASE_USER < backup.sql exit