Skip to content

Instantly share code, notes, and snippets.

@DerekV
DerekV / ArchivingRemoteMavenRepo.md
Last active February 13, 2021 16:50
Cloning and archiving a remote maven repo

I had a need to grab a backup of a remove Maven repo, and then saving this to AWS s3 for backup / archival purposes. In my case, it was an Artifactory Online instance that hosted jars and other artifacts that we own, but we did not have ssh access.

This is published with the intent of providing some inspiration for your own solution, as well as notes for myself. If you have something to add that might be useful for others, please open a PR.

Authentication

This was tested against artifactory, which documents several ways to authenticate.
In my case I used a header with an API token, which is Artifactory specific. However for this Gist I will replace that with basic auth, which will work with (I think) a broader range of maven implementations such as Sonatype Nexus, and works with Artifactory as well.

Pulling all the images from a docker registry

Normally, this would be a bad idea. My use case was this, we had a private registry with all our images going back a while, badly needing to get cleaned up and purged, and I wanted to grab a archive first. We couldn't just ssh to the machine hosting the registry to back it up that way.

To pull an image we need to know the registry, repository, and tag.

Luckily getting a list of repositories in the registry is easy with curl and jq.

curl --user "$REG_USER:$REG_PASS" -H "Accept: application/json"   "https://$REGISTRY/v2/_catalog"  | jq -r '.repositories[]'