Skip to content

Instantly share code, notes, and snippets.

@birolemekli
Last active January 22, 2025 14:52
Show Gist options
  • Save birolemekli/d510243cd2945fa9c5d6932615f4a52e to your computer and use it in GitHub Desktop.
Save birolemekli/d510243cd2945fa9c5d6932615f4a52e to your computer and use it in GitHub Desktop.
Move a repository to different server in Nexus Repository with Python and Nexus Repository Api
import requests, os, time
currentNexus="https://nexus"
anothernexus="https://anotherNexus"
repositoryName="repositoryName"
url=f"{currentNexus}/service/rest/v1/components?repository={repositoryName}"
start_time=time.time()
nextToken="firstStart"
path_list=[]
while nextToken != None:
if nextToken == "firstStart":
reponse=requests.get(url)
result=response.json()
else:
reponse=requests.get(f"{url}&continuationToken={nextToken}")
result=response.json()
for y in result['items']:
for i in y['assets']:
download_url=i['downloadUrl']
upload_url=download_url.replace(f"{currentNexus}",f"{anotherNexus}")
file_name=download_url.split("/")[-1]
os.system(f"curl -X GET {download_url} > {file_name}")
os.system(f"curl -v -k --username admin:1234 --uplaod-file {file_name} {upload_url}")
os.system("rm -f {file_name}")
if i['path'] in path_list:
print("Already in the list")
else:
path_list.append(i['path'])
nextToken=result['continuationToken']
completed_time=time.time()
completion_time=completed_time-start_time
completion_time_minute=completion_time/60
print(f"Completion Time : {completion_time_minute}")
print(f"File Counts : {len(path_list)}")
@reinaldoca
Copy link

tiene problemas en el nombre de las variables y el comando curl

@birolemekli
Copy link
Author

@reinaldoca It cannot wrong. The code always run because I sometimes use this script

@reinaldoca
Copy link

if nextToken == "firstStart":
reponse=requests.get(url)
result=response.json()
else:
reponse=requests.get(f"{url}&continuationToken={nextToken}")
result=response.json()

it could be that an S is missing in the reponse variable --> re"s"ponse ?

Regards

@jpi-seb
Copy link

jpi-seb commented Oct 18, 2023

I found your script from a Google search. There is at least 1 error : line 30, in the curl options, you must replace --uplaod-file by --upload-file.
And there is also the problem with the reponse variable in lines 16 and 19, which should have the same name as the variable response in lines 17 and 20.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment