This post runs through a simple Ruby script that manipulates the offline/online status of hosted Nexus repositories. Such a script would be useful if you need to manipulate the storage of a repository while Nexus is running. Assume you have a script that needs to backup the storage directory of all of your hosted directories once a night. If you wanted to make sure that your repository isn’t altered in the middle of a backup, you would put each hosted repository out of service before the backup job ran. After the job completed, you would put all of your hosted servers back into service.
While you could do this via the Nexus UI, this wouldn’t help your automated nightly backup script. For this script to be easy to run, you’ll need to script Nexus via the REST interface. With the Nexus 1.6 release, we’ve released full documentation of the Nexus REST services available in every Nexus installation (REST doc). Continue reading for an example of how to interact with, authenticate, and manipulate a Nexus instance via the REST APIs. Continue reading