This page documents how to take a DB Backup of your OpenMRS / EMR DB from Kubernetes environment, build a docker image with this DB, and then run Bahmni docker compose with the restored database.
WARNING: If you are working with production data, please be very careful how you handle it, who has access to it, and where you share/keep it. It is illegal to make private patient data available to people without authorisation in most countries!
Repositories
🔸 Bahmni Lite - India based with ABDM integration
🔸 Bahmni Scripts - to build DB for openMRS
Setup
🔹 Git clone the respective Bahmni Lite repository
🔹 Git clone the Bahmni Scripts repository
🔹 Install Docker
DB backup from Kubernetes/AWS
We ran Bahmni Lite on AWS/Kubernetes. So the following setup will extract DB dump based on Kubernetes commands.
Get into the openMRS kubernetes pod
kubectl exec -it openmrs<POD_ID> -n <namespace> -- bash
2. Navigate to the openmrs/data
folder and zip the configuration_checksum
folder (which is used by Initializer module to determine if an initializer entry has run or not run).
# install zip yum install zip # Navigate to openmrs/data directory cd /openmrs/data # Zip the checksums folder zip -r configuration_checksums.zip configuration_checksums
3. Backup the DB as a SQL dump
# Install mysql cli yum install mysql # Export the current live DB as a sql dump to the pod mysql -u username -p database_name > omrsdb.sql # Provide password and press Enter # Exit Mysql Exit
4. Note down the Database details
# Open the runtime properties cat openmrs-runtime.properties # Exit the openMRS pod Exit
Keep a note of the above DB details and maintain them securely until the setup is completed successfully
5. Copy the files to local machine
# Copy the checksums zip to the local kubectl cp performance/openmrs-<POD_ID>:/openmrs/data/configuration_checksums.zip configuration_checksums.zip # Copy the sql dump to the local kubectl cp performance/openmrs-<POD_ID>:/openmrs/data/omrsdb.sql omrsdb.sql
Build the DB in Docker
We used mysql 5.7 for our setup, if you use mysql 5.6 kindly change it wherever applicable.
Navigate to
~/bahmni-scripts/demo/db-backups/1.0.0-lite/mysql5.7/resources
2. Delete the files present in this directory
3. Copy and paste the files exported from the pod i.e configuration_checksums.zip
and omrsdb.sql
to this directory
4. Navigate back to the mysql5.7 directory and replace the Dockerfile contents with the following code:
Apple M1 Chip (Mac)
ARG arch FROM --platform=linux/amd64 mysql:5.7 #Install the required tools RUN yum update -y && \ yum install -y \ unzip #Set the mysql root password ENV MYSQL_ROOT_PASSWORD=<ROOTPASSWORD> #Copy configuration_checksums & DB Backup COPY demo/db-backups/1.0.0-lite/mysql5.7/resources/*.zip . COPY demo/db-backups/1.0.0-lite/mysql5.7/resources/*.sql /docker-entrypoint-initdb.d/omrs_db_backup.sql RUN unzip configuration_checksums.zip && \ rm configuration_checksums.zip
Others (Linux)
FROM mysql:5.7 #Install the required tools RUN yum update -y && \ yum install -y \ unzip #Set the mysql root password ENV MYSQL_ROOT_PASSWORD=<ROOTPASSWORD> #Copy configuration_checksums & DB Backup COPY demo/db-backups/1.0.0-lite/mysql5.7/resources/*.zip . COPY demo/db-backups/1.0.0-lite/mysql5.7/resources/*.sql /docker-entrypoint-initdb.d/omrs_db_backup.sql RUN unzip configuration_checksums.zip && \ rm configuration_checksums.zip
5. Navigate to bahmni-scripts root directory and execute the following docker command:
docker build --no-cache -t bahmni/openmrs-db:<TAGNAME> -f demo/db-backups/1.0.0-lite/mysql5.7/Dockerfile .
Config the environment and docker compose
Navigate to the
bahmni-docker/bahmni-lite
orbahmni-india-package
directory where thedocker- compose.yml
is present
If using M1 chip, add platform: linux/amd64
to each service present under the docker compose file.
2. Add the openMRS DB details captured earlier in DB backup extraction to the .env file and save it
# OpenMRS Environment Variables OPENMRS_IMAGE_TAG=latest OPENMRS_DB_IMAGE_NAME=bahmni/openmrs-db:<TAGNAME> OPENMRS_DB_NAME=<DBNAME> OPENMRS_DB_HOST=openmrsdb OPENMRS_DB_USERNAME=<DBUSERNAME> OPENMRS_DB_PASSWORD=<DBPASSWORD> OPENMRS_DB_CREATE_TABLES='false' OPENMRS_DB_AUTO_UPDATE='true' OPENMRS_MODULE_WEB_ADMIN='true' MYSQL_ROOT_USERNAME=root # OMRS_DEV_DEBUG_PORT= OMRS_JAVA_SERVER_OPTS='' OMRS_JAVA_MEMORY_OPTS='' OPENMRS_UPLOAD_FILES_PATH=./openmrs-uploads BAHMNI_OPENMRS_MODULES_PATH= MYSQL_ROOT_PASSWORD=<ROOTPASSWORD> OPENMRS_DB_TYPE=mysql OPENMRS_DOCKER_ENV='true'
Invoke Bahmni Lite
Bring up Bahmni through Docker compose
docker-compose up -d --build
2. Wait for openmrs to load with all the required indexes
3. Enter “http://localhost/openmrs” in browser and verify openMRS is up
4. Navigate to “http://localhost/” and start using Bahmni (this should now run with the new DB)