nexus-public: Nexus migration for OrientDB to H2 for 3.70.1-02 fails as nexus-db-migrator is version 3.70.1-03

hi,

We have Nexus OSS deployed using docker using the latest 3.70 tag;

services:
  nexus:
    container_name: nexus
    restart: unless-stopped
    image: sonatype/nexus3:3.70.1
    user: nexus
    environment:
      - TZ=Pacific/Auckland
    volumes:
      - /home/ubuntu/nexus-data:/nexus-data
    ports:
      - 8081:8081

when Nexus starts up it shows as version OSS 3.70.1-02

We create a backup job for the OrientDB Nexus>create task>type: Admin - Export databases for backup taskname: backup backup location: /nexus-data/backup run task

so now we connect to the container and attempt to migrate the database to h2;

# docker exec -it nexus /bin/bash
$ cd /opt/sonatype/nexus
$ ./bin/nexus stop
$ cd /nexus-data/db
$ cp /nexus-data/backup/* .
$ curl -s -L -O https://download.sonatype.com/nexus/nxrm3-migrator/nexus-db-migrator-3.70.1-03.jar
$ java -Xmx2G -Xms2G -XX:+UseG1GC -XX:MaxDirectMemorySize=28672M -jar nexus-db-migrator-3.70.1-03.jar --migration_type=h2 --healthcheck --debug
08:40:47 [main] WARN  c.s.n.d.migrator.MigratorApplication - Please ensure any Nexus Repository instance has been gracefully shut down before proceeding.
08:40:47 [main] INFO  c.s.n.d.migrator.MigratorApplication - Do you want to continue [y/n]?
y
The migration files in /nexus-data/db do not match the expected requirements: The backup versions are inconsistent.

As seen above the migration fails presumable as the migration tool is expecting the Nexus version to be 3.70.1-03 and not 3.70.1-02 but there is no docker tag for version 3.70.1-03. What is the solution here? We want to track the latest OSS release, but can only do that when we are using the H2 DB by the looks of things.

thanks.

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 2
  • Comments: 42 (3 by maintainers)

Most upvoted comments

thanks @MrEAlderson, it was exactly as you suggested. When I ran the migrator from the /nexus-data/backup directory then it worked as expected so nice work! I moved the nexus.mv.db to the /nexus-data/db afterwards then reconfigured the nexus.properties file to have the; nexus.datastore.enabled=true and Nexus came up as expected, and I was then able to migrate it to the latest nexus release. for anyone else struggling with this, my build notes are below;

  1. Start off with the latest relese that supports OrientDB (3.70.1);
# vi /home/ubuntu/docker-compose.yml
services:
  nexus:
    container_name: nexus
    restart: unless-stopped
    image: sonatype/nexus3:3.70.1
    user: nexus
    environment:
      - TZ=Pacific/Auckland
    volumes:
      - /home/ubuntu/nexus-data:/nexus-data
    ports:
      - 8081:8081
  1. Bring container up;
# cd /home/ubuntu
# docker-compose up -d
  1. Create backup task for OrientDB and run it Nexus>create task>type: Admin - Export databases for backup taskname: backup backup location: /nexus-data/backup
  2. Pop inside the container, check the backup files are located as expected and run the migrator and copy the migrated file to the /nexus-data/db folder and exit the container.
# docker exec -it nexus /bin/bash
$ /opt/sonatype/nexus/bin/nexus stop
$ cd /nexus-data/backup
$ ls -l
-rw-r--r-- 1 nexus nexus 14862329 Aug 19 00:26 analytics-2024-08-19-12-26-21-3.70.1-02.bak
-rw-r--r-- 1 nexus nexus 56446663 Aug 19 00:26 component-2024-08-19-12-26-21-3.70.1-02.bak
-rw-r--r-- 1 nexus nexus   201734 Aug 19 00:26 config-2024-08-19-12-26-21-3.70.1-02.bak
-rw-r--r-- 1 nexus nexus   127789 Aug 19 00:26 security-2024-08-19-12-26-21-3.70.1-02.bak
$ curl -s -L -O https://download.sonatype.com/nexus/nxrm3-migrator/nexus-db-migrator-3.70.1-03.jar
$ java -Xmx2G -Xms2G -XX:+UseG1GC -XX:MaxDirectMemorySize=28672M -jar nexus-db-migrator-3.70.1-03.jar --migration_type=h2
12:29:47 [main] WARN  c.s.n.d.migrator.MigratorApplication - Please ensure any Nexus Repository instance has been gracefully shut down before proceeding.
12:29:47 [main] INFO  c.s.n.d.migrator.MigratorApplication - Do you want to continue [y/n]?
y
12:30:35 [main] INFO  c.s.n.d.m.l.ProvidingJobInfoListener - Migration job finished at Mon Aug 19 12:30:35 NZST 2024
12:30:35 [main] INFO  c.s.n.d.m.l.ProvidingJobInfoListener - Migration job took 23 seconds to execute
12:30:35 [main] INFO  c.s.n.d.m.l.ProvidingJobInfoListener - 86289 records were processed
12:30:35 [main] INFO  c.s.n.d.m.l.ProvidingJobInfoListener - 7 records were filtered
12:30:35 [main] INFO  c.s.n.d.m.l.ProvidingJobInfoListener - 0 records were skipped
12:30:35 [main] INFO  c.s.n.d.m.l.ProvidingJobInfoListener - 86282 records were migrated
12:30:35 [main] INFO  c.s.n.d.m.l.ProvidingJobInfoListener - Created 'Rebuild repository browse' and 'Rebuild repository search' tasks. They will automatically one-time run after starting your Nexus Repository instance.
12:30:35 [main] INFO  c.s.n.d.m.l.ProvidingJobInfoListener - Migrated the following formats: [APT, COCOAPODS, CONAN, CONDA, DOCKER, GITLFS, GO, HELM, MAVEN2, NPM, NUGET, P2, PYPI, R, RAW, RUBYGEMS, YUM]
$ /opt/sonatype/nexus/bin/nexus stop
$ ls -l nexus.mv.db
-rw-r--r-- 1 nexus nexus 117149696 Aug 19 00:30 nexus.mv.db
$ cp nexus.mv.db /nexus-data/db
$ exit
  1. Bring down container and modify Nexus to use H2 database
# docker-compose down
# vi /home/ubuntu/nexus-data/etc/nexus.properties
nexus.datastore.enabled=true
# docker-compose up -d
  1. Confirm Nexus still up and running on the 3.70.1 release except using H2 database.
# docker logs nexus|grep H2
2024-08-19 12:36:59,436+1200 INFO  [FelixStartLevel] *SYSTEM org.sonatype.nexus.datastore.DataStoreConfigurationDefaultSource - Loaded 'nexus' data store configuration defaults (Embedded H2)
2024-08-19 12:37:00,109+1200 INFO  [FelixStartLevel] *SYSTEM org.sonatype.nexus.datastore.mybatis.MyBatisDataStore - nexus - MyBatis databaseId: H2
  1. Modify docker-compose.yml file to track the 3.71.0 tag
# vi /home/ubuntu/docker-compose.yml
services:
  nexus:
    container_name: nexus
    restart: unless-stopped
    image: sonatype/nexus3:3.71.0
    user: nexus
    environment:
      - TZ=Pacific/Auckland
    volumes:
      - /home/ubuntu/nexus-data:/nexus-data
    ports:
      - 8081:8081
  1. Bring container up to match docker-compose file
# docker-compose up -d
  1. Have a calming cup of tea and wonder why Sonatype didn’t just include automatic db migration from OrientDB to H2 for those people using the OSS edition. Guess you get what you pay for!

I’m also using Nexus 3.70.1 and nexus-db-migrator-3.70.1-03.jar, but the migration fails:

13:34:42 [main] ERROR o.s.batch.core.step.AbstractStep - Encountered an error executing step checkModelVersionsStep in job migrationFromOrientNoExportJSONJob
com.sonatype.nexus.db.migrator.exception.WrongSchemaVersionException: Occurring schema versions that are not supported:
Upgrade ModelVersions{config='1.10', security='1.4', component='1.16', healthCheck='1.1', userToken='1.4', tags='1.1'}
Supported schema versions:
Upgrade ModelVersions{config='1.10', security='1.4', component='1.16', healthCheck='1.1', userToken='1.5', tags='1.1'}
Your OrientDB schemas are not supported by the current migrator version. Please update your Nexus Repository to the 3.70.1 version and use latest migrator version.

The documentation is somewhat inconsistent: While the upgrade pages [1] and [2] indicate that the migration should be performed on the backup files, the legacy database migration guide suggests that the migration should be done from the db directory:

grafik grafik

The note regarding “Migrating a Docker Image to H2” is also misleading: You can’t stop Nexus within a container running the official Docker image, as Nexus is the init process. /opt/sonatype/nexus/bin/nexus stop doesn’t work. You have to stop the container and perform the migration on the host or within another container (e.g. using image eclipse-temurin:8-jre).

We got the same problem with unsupported userToken=‘1.4’. I have discovered, this component are only supported by Pro version. We used Pro to evaluate its features and disabled it by enabling oss version feature with nexus.loadAsOSS=true To mitigate this issue, we have disabled OSS feature and started Pro version - it upgraded userToken to 1.5. Than enabled OSS version again and successfully migrated from OrientDB to H2

A short report from me.

The migration to h2 worked in itself.

here my steps:

remove old backups -> backup-task docker-compose stop

here you have to configure your docker-network and docker-volume docker run -it -u nexus --network nexus_running_default -v /srv/nexus/nexus_running/data:/nexus-data/ sonatype/nexus3:3.70.2 bash

as specialy 30.70.2-1 of the migrator

our system with 4gb ram was enough

cd /nexus-data/backup
#download the migrator
curl -s -L -O https://download.sonatype.com/nexus/nxrm3-migrator/nexus-db-migrator-3.70.2-01.jar

#execute the migrator with with a lot of few resources
java -Xmx2G -Xms2G -XX:+UseG1GC -XX:MaxDirectMemorySize=28672M -jar nexus-db-migrator-3.70.2-01.jar --migration_type=h2

#mv the new database to the database path
cp nexus.mv.db ../db/

after that, configure nexus.datastore.enabled=true in the “/nexus-data/etc/nexus.properties”

change the nexus version to 3.72.0

Apparently, however, this rebuild-browser/rebuild-search task was not executed at the end, I had to create it manually. Now everything is working as desired.

Successfully upgraded docker-based Nexus 3.70.0-02 to 3.71.0-06 with OpenJDK11.0.24 To fix auto-increment values I have download H2 installer from http://www.h2database.com/html/download.html and start aforementioned script

#!/bin/bash

h2sql() { echo "> $@" >&2 java -cp /data/nexus-data/backup/h2/bin/h2-2.3.232.jar org.h2.tools.Shell -url jdbc:h2:/data/nexus-data/db/nexus -sql "$@" }

schema=$(h2sql "SCRIPT NODATA") echo "$schema" | while read line; do if [[ $line =~ ^CREATE\ CACHED\ TABLE\ \"PUBLIC\"\.\"([^\"]+)\" ]]; then tbl="${BASH_REMATCH[1]}" elif [[ $line =~ ^\"([^\"]+)\"\ .*\ GENERATED\ BY\ DEFAULT ]]; then col="${BASH_REMATCH[1]}" h2sql "ALTER TABLE $tbl ALTER COLUMN $col RESTART WITH SELECT max($col) + 1 FROM $tbl" fi done

Than enabled option nexus.datastore.enabled=true in nexus.properties and successfully started app

@ashleyw-gh thank you, you saved my day: everything works for us with your detailed procedure.

Try to run this java command:

java --add-exports=java.base/sun.nio.ch=ALL-UNNAMED -Xmx16G -Xms16G -XX:+UseG1GC -XX:MaxDirectMemorySize=28672M -jar nexus-db-migrator-3.70.1-03.jar

This command at least lets me run the healthcheck with Java 17 (might also work with Java 11).

If anyone is interested in a detailed guide on updating Nexus to the latest version and migrating the database to PostgreSQL or H2, I’ve written one.

Thank you a lot, @ashleyw-gh and @MrEAlderson! That saved also my day! I was also getting the “The backup versions are inconsistent” error and in my case, that was because there were multiple .bak files per type (analytics, components, …) in the directory (as they are kept for a while after being created). They might have been created by different Nexus versions or the migrator might have had difficulties dealing with this.

So, just to add it for anyone dealing with the same problem: You should also make sure, that only the latest backup files are present in the backup directory.

Ok, it works with H2… Am I right in assuming that only H2 works in OSS and not Postgres?

How disappointing

java -version

openjdk version “11.0.24” 2024-07-16 OpenJDK Runtime Environment Temurin-11.0.24+8 (build 11.0.24+8) OpenJDK 64-Bit Server VM Temurin-11.0.24+8 (build 11.0.24+8, mixed mode)

这个版本完美运行

Uh, yes, I’ve evaluated the pro version at some point in the past, too! Thanks for the hint!

Hello,

Just an update. It turned out my whole problem was because I was using the Oracle JDK. When I switched to OpenJDK, the migrator worked fine.

Regards!

Hey all, apologies for the friction. We’re getting this onto a team’s plate to investigate, we’ll report back here when we have some more information.

@ashleyw-gh I followed your instructions and ended up with a different result:

13:01:46 [main] ERROR o.s.boot.SpringApplication - Application run failed
java.lang.IllegalStateException: Failed to execute ApplicationRunner                                                                                                                                                    
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:776)                                                                                                                             
at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:763)                                                                                                                            
at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)                                                                                                                                    
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1317)                                                                                                                                   
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306)                                                                                                                                   
at com.sonatype.nexus.db.migrator.MigratorApplication.main(MigratorApplication.java:117)

Caused by: com.sonatype.nexus.db.migrator.exception.InvalidMigrationFilesException: 
The migration files in /nexus-data/db do not match the expected requirements: 
Existing database files found.

What files should be in /nexus-data/db before running the migration tool?

bash-4.4$ pwd
/nexus-data/db
bash-4.4$ ls -l
total 63924
drwxr-xr-x 2 nexus nexus     4096 Apr 16 10:02 OSystem
drwxr-xr-x 2 nexus nexus     4096 Aug 16 12:58 analytics
-rw-r--r-- 1 nexus nexus  7936132 Aug 16 13:00 analytics-2024-08-16-12-57-25-3.70.1-02.bak
drwxr-xr-x 2 nexus nexus    12288 Aug 16 12:58 component
-rw-r--r-- 1 nexus nexus   502559 Aug 16 13:00 component-2024-08-16-12-57-25-3.70.1-02.bak
drwxr-xr-x 2 nexus nexus    12288 Aug 16 12:58 config
-rw-r--r-- 1 nexus nexus   232393 Aug 16 13:00 config-2024-08-16-12-57-25-3.70.1-02.bak
-rw-r--r-- 1 nexus nexus        2 Aug 16 12:57 frozen.marker
drwxr-xr-x 2 nexus nexus     4096 Aug 16 13:01 logs
-rw-r--r-- 1 nexus nexus       93 Jun  6 15:08 model.properties
-rw-r--r-- 1 nexus nexus 56574550 Aug 16 13:01 nexus-db-migrator-3.70.1-03.jar
-rw-r--r-- 1 nexus nexus    16384 Aug 16 13:01 nexus.mv.db
drwxr-xr-x 2 nexus nexus     4096 Aug 16 12:57 security
-rw-r--r-- 1 nexus nexus   136473 Aug 16 13:00 security-2024-08-16-12-57-25-3.70.1-02.bak
bash-4.4$

I faced the same issue and had to decompile the jar to determine what they meant. You are not supposed to have your backups within your db folder. Move them (all files with .bak extension) out into their own folder and it should work. The migrator might trash this same folder on its own, so you might have to clean it manually after you run it.

Oh, and if anyone else randomly sees this message and wonders what the hell they mean with the migration step 6. Perform a full backup using normal backup procedures:

  1. Downgrade to 3.69.0
  2. Create a manual backup task whose location shall show at an empty folder in your volume (/opt/sonatype/sonatype-work/nexus3/penis). Run it, and if it succeeds, remove the task again.
  3. Upgrade back to latest
  4. Configure Postgres accordingly, otherwise it is stuck in a boot loop and you won’t be able to properly use the console (as yo get kicked out)
  5. Follow the remaining steps, the commands from OP helped me with that

If you get lucky as I am, this is the step where you get greeted with Migration to an external database requires Nexus Repository Manager Pro🙃 Fortunately migration to H2 worked just fine at this stage.