Retore backup Error : relation "audit" already exists

Hello

I have a dhis2 backup that I cannot restore, I have the following error when starting the instance after restoration:

Message    : ERROR: relation "audit" already exists
May 30 20:27:37 dhis tomcat9[304]: Location   : org/hisp/dhis/db/migration/2.34/V2_34_8__Create_Audit_Table.sql (/var/lib/tomcat9/file:/var/lib/tomcat9/webapps/dhis/WEB-INF/lib/dhis-support-db-migration-2.34.3.jar!/org/hisp/dhis/db/migration/2.34/V2_34_8__Create_Audit_Table.sql)
Caused by: org.flywaydb.core.api.FlywayException: Validate failed:
May 30 20:11:03 dhis tomcat9[300]: Detected failed migration to version 2.34.8 (Create Audit Table). Please remove any half-completed changes then run repair to fix the schema history.

I don’t know exactly with which version of dhis 2 the backup was made. As mentioned in the error message, I tried all versions of 2.34.* and also 2.36, but I still have the same error.

To guess the version, you probably need to restore it in fresh db : Don’t start any dhis2 against the db
Then look at the content of flyway_schema_history

select * from flyway_schema_history;

+------------------+-----------+-----------------------------------------------------------------------------------------------------------------------------------------------+----------+------------------------------------------------------------------>
| installed_rank   | version   | description                                                                                                                                   | type     | script                                                           >
|------------------+-----------+-----------------------------------------------------------------------------------------------------------------------------------------------+----------+------------------------------------------------------------------>
| 1                | 1         | << Flyway Baseline >>                                                                                                                         | BASELINE | << Flyway Baseline >>                                            >
| 2                | 2.30.0    | Populate dhis2 schema if empty database                                                                                                       | JDBC     | org.hisp.dhis.db.migration.base.V2_30_0__Populate_dhis2_schema_if>
| 3                | 2.31.1    | Migrations for release v31                                                                                                                    | SQL      | 2.31/V2_31_1__Migrations_for_release_v31.sql                     >
| 4                | 2.31.2    | Job configuration param to jsonb                                                                                                              | JDBC     | org.hisp.dhis.db.migration.v31.V2_31_2__Job_configuration_param_t>
| 5                | 2.31.3    | Program notification template to templateid                                                                                                   | JDBC     | org.hisp.dhis.db.migration.v31.V2_31_3__Program_notification_temp>
| 6                | 2.31.4    | Add defaults for validationstrategy                                                                                                           | JDBC     | org.hisp.dhis.db.migration.v31.V2_31_4__Add_defaults_for_validati>
| 7                | 2.31.5    | Add new user role for new capture app                                                                                                         | JDBC     | org.hisp.dhis.db.migration.v31.V2_31_5__Add_new_user_role_for_new>

by inspecting the version you might be able to guess the correction version to start the dhis2.
if you don’t have the flyway_schema_history table then either the backup is incomplete or it’s a much older version.

select version from flyway_schema_history order by installed_rank desc; is perhaps easier to find latest migration version.

1 Like

see Identify the DHIS2 version from database backup

Hello @Stephan_Mestach Thank you for your help.

It’s seems to be 2.33.x version

I deployed version 2.33.9 and the FlywayException no longer appears.

Now I have the following error (Do I have to open new topic ?):

The second error was a problem with jdk and tomcat version, I installed jdk8 and tomcat 8 and it finally worked.

1 Like

Thanks for sharing @didate!

1 Like