6

I was wondering how to download all (not one or two specified ones) artifacts from a Nexus 3 repo to local disk. In Nexus 2 it was easy since everything was stored on disk and I would just rsync all the artifacts to my local disk.

But in Nexus 3 all artifacts are stored in the OrientDB and I will have to take an other route. I was thinking about downloading them per http after getting a complete list somehow.

Does anybody has an idea on how to perform such an export?

030
  • 10,842
  • 12
  • 78
  • 123
jcrosel
  • 349
  • 2
  • 5
  • 13
  • 1
    Why do you need that? – khmarbaise Sep 28 '17 at 13:36
  • There are some available options, see here: https://groups.google.com/a/glists.sonatype.com/forum/#!topic/nexus-users/xdsKXeveUL0 – Oleksandr Gubchenko Sep 29 '17 at 03:50
  • @khmarbaise I want to migrate to another Artifact Repository Manager – jcrosel Oct 02 '17 at 07:14
  • "But in Nexus 3 all artifacts are stored in the OrientDB and I will have to take an other route. I was thinking about downloading them per http after getting a complete list somehow." I was thinking about that all along, but how would I do that? – jcrosel Oct 02 '17 at 11:58
  • There is no rest api to get a list of all paths or artifacts. Where would i get this list from? I saw the maven indexer referenced somewhere, but no documentation for it. – jcrosel Oct 02 '17 at 14:00
  • After searching a little bit: https://github.com/nongfenqi/nexus3-rundeck-plugin – khmarbaise Oct 02 '17 at 15:30
  • @khmarbaise [n3dr](https://github.com/030/n3dr) is able to download all artifacts – 030 May 20 '19 at 22:02

5 Answers5

5

One could download all artifacts from a Nexus3 repository by using n3dr.

030
  • 10,842
  • 12
  • 78
  • 123
  • I used it, it works very well to download and upload. – noNihongo Apr 13 '21 at 19:48
  • I used the below command. "n3dr backup -u admin -p xxxxxx -n https://nexus-url.cloud -r app-releases --directory-prefix /home/nexus/revamp_bkp -d" I am getting this error. FATA[0000]/home/runner/work/n3dr/n3dr/cmd/n3dr/backup.go:42 main.glob..func1() HTTPS://nexus-url.cloud:443/repository/app-releases/com/abc/def/xyz/0.0.2/app-api-definition-0.0.2.jar is not an URL Can some one help to resolve the issue. – Vineeth NG Aug 26 '21 at 07:49
  • Could you create an issue in https://github.com/030/n3dr? – 030 Aug 27 '21 at 10:12
  • @VineethNG We use a regex to check the URL. Did you either specify http:// or https:// as well? – 030 Aug 27 '21 at 12:23
1

I modified following groovy scirpt, which can be uploaded using the API: https://gist.github.com/kellyrob99/2d1483828c5de0e41732327ded3ab224

To upload and execute the script I took a look at the examples: https://github.com/sonatype/nexus-book-examples/tree/nexus-3.x

jcrosel
  • 349
  • 2
  • 5
  • 13
0

If you see the version upgrade on the Dockerfile they have modified the location for the base app. You need to point your storage to

/opt/sonatype/sonatype-work

Source: https://github.com/sonatype/docker-nexus3/blob/master/Dockerfile

Alberto Soto
  • 111
  • 3
-1

I had to do move all artifacts from one Nexus 3 repository to another one. Once this was accidental, I developed the procedure (Windows):

  • from Nexus' web interface / Browse / Assets took the JSON with the list of assets
  • extracted the assets' URLs by collecting the values of their "name" attribute
  • delete all assets that are .md5, .sha1, maven-metadata.xml
  • delete all assets that are pom.xml for another atrifact
  • split the artifact URLS into

    path in the repository - it is in the format /<groupId path>/<artifactId>/<versionId>/<file name>
    groupId- parse the path, replacing / with .
    artifactId - parse the path,
    version - parse the path, 
    file name - parse the path
    packaging - the file name extension
    
  • for each such parsed URL call the script (named publish.bat):

    @echo off
    rem %1 = from repository URL
    rem %2 = to repository URL
    rem %3 = path
    rem %4 = groupId
    rem %5 = artifactId
    rem %6 = version
    rem %7 = file name
    rem %8 = packaging
    echo.
    echo %1%3/%5/%6/%7
    echo.
    
    curl --remote-name --create-dirs --output %7 %1%3/%5/%6/%7
    
    call mvn deploy:deploy-file -DgroupId=%4 -DartifactId=%5 -Dversion=%6 -DgeneratePom=true -Dpackaging=%8 -DrepositoryId=admin -Durl=%2 -Dfile=%7
    
    del %7
    

NOTE: -DrepositoryId=admin is a reference to a server definition in the Maven's settings.xml defining the user and password to publish in the target repository.

Example:

set FROM=source repository URL
set TO=target repository URL

call publish.bat %FROM% %TO% net/xyz/webtools net.xyz.webtools buildServer 03.06.00.01 buildServer-03.06.00.01.war war
Rusi Popov
  • 377
  • 1
  • 6
-2

You can retrieve all DownloadURLs using the REST-API, then download them all. I did this with a simple Python Script.

Jakob
  • 214
  • 1
  • 2
  • 15
  • 2
    Could you share this script? – 030 Dec 24 '18 at 13:41
  • 1
    This is the most useless answer I've ever seen. If you want to help then explain in details , otherwise spare us the useless characters. – JAN Jan 01 '23 at 08:27