Migration of database to new server setup

Hi DHIS2 Community, does anyone have or has done a database migration from one instance of DHIS2 to a new instance? Please share your thoughts on how to go about this. Thanks.


Figured out.Thanks!

1 Like

This process assumes that the OS is Linux and that you have both the current DHIS2 setup (Will call it “Origin”) and a new/empty DHIS2 instance (Will call it “Destination”) where you intend to migrate data.

Make a dump of the current/origin database:

postgres@origin_server$ pg_dump dhis2 -U dhis -f dhis2_origin_db.sql

Copy the sql dump to the destination server. You can use an ssh client such as PUTTY/WinSCP or simply use the command below:

user@Origin$ scp dhis2_origin_db.sql user@destination_server:/home/dhis/

While in destination server, create a new database by invoking:

sudo -u postgres createdb –O dhis dhis2_destination

Create the PostGIS extension for the newly created database

sudo -u postgres psql -c "create extension postgis;" dhis2_destination

Shutdown the newly created dhis2 setup by invoking the command below (this path may vary depending on your setup)

sudo -u dhis /home/dhis/tomcat-dhis/bin/shutdown.sh

Update the DHIS2 configuration file to reflect the newly created database.

sudo -u dhis nano /home/dhis/config/dhis.conf

In the dhis.conf file locate the following line:

# JDBC driver connection URL

connection.url = jdbc:postgresql:dhis2

Change this to the newly created database, save and exit the file edit mode.

# JDBC driver connection URL

connection.url = jdbc:postgresql:dhis2_destination

At this point, we are ready to migrate/restore data from the origin database to the new setup.

Invoke the following command:

sudo su - postgres

Initiate the restoration of the copied database by invoking:

postgres@destination_server$ psql -d dhis2_destination -U dhis -f dhis2_origin_db.sql

dhis2_migration: this is the newly created and/or empty database in which we intend to restore data into.

dhis: refers to the database user.

Restart the dhis2 instance by invoking:

sudo -u dhis /home/dhis/tomcat-dhis/bin/startup.sh

You can monitor the Tomcat by viewing the log information, simply invoke the command below:

tail -f /home/dhis/tomcat-dhis/logs/catalina.out