DHIS2 Database Migration/Restoration Process
DHIS2
Database Migration/Restoration Process
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.
Actions at Origin Server [Linux]
Create
a sql dump of the current/origin database:
user@origin_server$ sudo su - postgres
postgres@origin_server$ pg_dump dhis2 -U dhis -f dhis2_origin_db.sql
Copy
the sql dump to the destination server. You can use ssh client such as
PUTTY/WinSCP or simply use the command below:
user@origin_server$ scp dhis2_origin_db.sql dhis@ destination_server:/home/dhis/
Actions at Origin Server [Windows]
Open Command Line Window
Navigate to Postgres bin folder i.e
cd C:\Program
Files\PostgreSQL\9.6\bin
Dump the database using the command below
pg_dump.exe -U postgres -d dhis2 -f
D:\Backup\<backup-file-name>.sql
Type password for your postgres user
You may copy the dump file over to the
destination server using ssh client PUTTY or on windows command prompt /WinSCP.
Actions at Destination Server
While
in destination server, create a new database by invoking:
dhis@Mydhis2$ sudo -u postgres createdb –O dhis
dhis2_destination
Create
the PostGIS extension for the newly created database
dhis@Mydhis2$ 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)
dhis@Mydhis2$ sudo -u dhis /home/dhis/tomcat-dhis/bin/shutdown.sh
Update
the DHIS2 configuration file to reflect the newly created database.
dhis @Mydhis2$ 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:
dhis@Mydhis2$ sudo su - postgres
Initiate
the restoration of the copied database by invoking:
postgres@Mydhis2$ 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:
dhis@Mydhis2$ 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:
dhis@Mydhis2$ tail -f
/home/dhis/tomcat-dhis/logs/catalina.out
Comments
Post a Comment