あるフリーランスエンジニアの色んなメモ!! ITスキル・ライフハックとか

Docker版のNexusを3.71.0以降へupgradeする

Dockerイメージで動作させているNexus 3.70系を3.71.0以降のversionへupgradeするには、
upgradeする前にOrientDBをH2へ移行する必要がある。


前提条件

  • Nexusのversionが、3.70系の最新versionであること
  • OrientDBからH2への移行時に、16GB以上のメモリが確保されていること

使用したNexusの状態

upgradeするNexusは、docker composeで運用している

services:
  nexus:
    image: sonatype/nexus3:3.70.4
    ports:
      - 8081:8081
    volumes:
      - nexus-data:/nexus-data

volumes:
  nexus-data: null

OrientDBからH2への移行手順

DBのbackup保存先ディレクトリを作成する

mkdir /var/lib/docker/volumes/nexus_nexus-data/_data/_backup
chown 200:200 /var/lib/docker/volumes/nexus_nexus-data/_data/_backup

Nexusへブラウザでアクセスし、full backupを取得する

  • adminでログイン
  • 上部の歯車アイコンをクリック
  • System > Tasks
  • Create task
  • Admin - Export Database for backup
    • Task name: 任意
    • Backup location: /nexus-data/_backup
    • ⁠Task frequency: Manual
  • 作成したTaskを選択し、Runをクリック
  • Taskが完了したことを確認する

Nexusを停止する

docker compose down

Database Migrator Utilityを取得する

移行作業に使用するjarファイルを取得し、backup保存先へ格納する

wget https://download.sonatype.com/nexus/nxrm3-migrator/nexus-db-migrator-3.70.4-02.jar -P /var/lib/docker/volumes/nexus_nexus-data/_data/_backup/

DBの移行を実施する

OpenJDKのコンテナイメージを起動し、先ほど取得したjarファイルを使用してDBの移行を実施する

docker run --rm -it -v /var/lib/docker/volumes/nexus_nexus-data/_data:/work -w /work/_backup openjdk:11-ea-jdk bash
  • OpenJDKのコンテナ内で、Database Migrator Utilityを実行する
java -Xmx16G -Xms16G -XX:+UseG1GC -XX:MaxDirectMemorySize=28672M -jar nexus-db-migrator-*.jar --migration_type=h2
17:55:40 [main] WARN  c.s.n.d.migrator.MigratorApplication - Please ensure any Nexus Repository instance has been gracefully shut down before proceeding.
17:55:40 [main] INFO  c.s.n.d.migrator.MigratorApplication - Do you want to continue [y/n]?
y
17:55:42 [main] INFO  c.s.n.d.migrator.MigratorApplication - --content_migration parameter is absent. Setting it to true.
17:55:42 [main] INFO  c.s.n.d.migrator.MigratorApplication - Force parameter wasn't found. Setting it to false by default.
17:55:42 [main] INFO  c.s.n.d.migrator.MigratorApplication - ------------------------------------------------------------
17:55:42 [main] INFO  c.s.n.d.migrator.MigratorApplication - Java version: Oracle Corporation 11
17:55:42 [main] INFO  c.s.n.d.migrator.MigratorApplication - JVM arguments: -Xmx16G -Xms16G -XX:+UseG1GC -XX:MaxDirectMemorySize=28672M
17:55:42 [main] INFO  c.s.n.d.migrator.MigratorApplication - Migrator arguments: --migration_type=h2 --content_migration=true --export_json=false --force=false
17:55:42 [main] INFO  c.s.n.d.migrator.MigratorApplication - ------------------------------------------------------------
17:55:43 [main] INFO  c.s.n.d.migrator.MigratorApplication - Starting MigratorApplication v3.70.4-02 using Java 11 on cf71fc0d4217 with PID 14 (/work/_backup/nexus-db-migrator-3.70.4-02.jar started by root in /work/_backup)

~省略~

17:55:51 [main] INFO  c.s.n.d.m.l.ProvidingJobInfoListener - Migration job finished at Wed Mar 26 17:55:51 UTC 2025
17:55:51 [main] INFO  c.s.n.d.m.l.ProvidingJobInfoListener - Migration job took 5 seconds to execute
17:55:51 [main] INFO  c.s.n.d.m.l.ProvidingJobInfoListener - 2023 records were processed
17:55:51 [main] INFO  c.s.n.d.m.l.ProvidingJobInfoListener - 3 records were filtered
17:55:51 [main] INFO  c.s.n.d.m.l.ProvidingJobInfoListener - 0 records were skipped
17:55:51 [main] INFO  c.s.n.d.m.l.ProvidingJobInfoListener - 2020 records were migrated
17:55:51 [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.
17:55:51 [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]
  • 作成されたファイルを所定の場所へ移動する
cp nexus.mv.db ../db/
chown 200:200 ../db/nexus.mv.db
  • Nexusの設定ファイルを編集する

H2を使用するために必要な設定を実施する

echo "nexus.datastore.enabled=true" >> /work/etc/nexus.properties
  • OpenJDKコンテナを終了する
exit

Nexusを起動する

docker compose up -d

Nexusのmigration taskが完了するのを待つ

H2が使用されていることを確認する

Nexusへブラウザでアクセスし

  • adminでログイン
  • 上部の歯車アイコンをクリック
  • System > Tasks
  • filterでbackupで絞り込む
    • Admin - Backup H2 Database
      のtaskのみ存在することを確認する

Nexusをupgradeする

docker composeの設定変更

使用するNexusのversionを変更する

services:
  nexus:
    image: sonatype/nexus3:3.78.2
    ports:
      - 8081:8081
    volumes:
      - nexus-data:/nexus-data

volumes:
  nexus-data: null

Nexusを起動する

docker compose up -d

Nexusのmigration taskが完了するのを待つ


参考

Migration Environment Prerequisite Requirements
https://help.sonatype.com/en/upgrading-to-nexus-repository-3-71-0-and-beyond.html#migration-environment-prerequisite-requirements-252162

Migrating From OrientDB to H2
https://help.sonatype.com/en/upgrading-to-nexus-repository-3-71-0-and-beyond.html#migrating-from-orientdb-to-h2-252162

comments powered by Disqus