How to backup all Nexus 3 artifacts?

痴心易碎 提交于 2019-12-04 15:07:49

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

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

docker-compose.yml

version: '3.7'
services:
  n3dr:
    image: utrecht/n3dr:3.0.0
    volumes:
      - ~/.n3dr.yaml:/home/n3dr/.n3dr.yaml
      - ~/2019-05-20-nexus-fqdn:/download
    environment:
      - HTTPS_PROXY=some-proxy
    command: repositories -n some-nexus -u admin -d

If one runs docker-compose up, the artifacts from all Nexus3 repositories will be downloaded.

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

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!