curl - 从 Nexus 3.37.1 下载整个存储库

标签 curl nexus nexus3

我想知道如何从 Nexus 3.37 下载整个文件夹或存储库。我尝试了以下命令

curl -X GET -u 用户 ID:密码“https://nexus.com/abc/def/ghi/”-O

我能够使用上述命令下载目录中的单个文件,有人知道如何下载整个文件夹吗?

谢谢!

最佳答案

上面的脚本确实帮助我解决了这个问题。我稍微修改了一下并发布在下面。该脚本并不完美,您可能需要对其进行编辑。我知道一个问题是该脚本启动的第一次下载被放置在错误的目录中。

sourceServer=
sourceRepo=
sourceUser=
sourcePassword=
logfile=$sourceRepo-backup.log
outputFile=$sourceRepo-artifacts.txt

# ======== GET DOWNLOAD URLs =========
url=$sourceServer"/service/rest/v1/assets?repository="$sourceRepo
contToken="initial"
while [ ! -z "$contToken" ]; do
    if [ "$contToken" != "initial" ]; then
        url=$sourceServer"/service/rest/v1/assets?continuationToken="$contToken"&repository="$sourceRepo
    fi
    echo Processing repository token: $contToken | tee -a $logfile
    response=`curl -ksSL -u "$sourceUser:$sourcePassword" -X GET --header 'Accept: application/json' "$url"`
    readarray -t artifacts < <( jq  '[.items[].downloadUrl]' <<< "$response" )
    printf "%s\n" "${artifacts[@]}" > artifacts.temp
    sed 's/\"//g' artifacts.temp > artifacts1.temp
    sed 's/,//g' artifacts1.temp > artifacts.temp
    sed 's/[][]//g' artifacts.temp > artifacts1.temp
    cat artifacts1.temp >> $outputFile
#for filter in "${filters[@]}"; do
     #   cat artifacts.temp | grep "$filter" >> $outputFile
    #done
    #cat maven-public-artifacts.txt
    contToken=( $(echo $response | sed -n 's|.*"continuationToken" : "\([^"]*\)".*|\1|p') )
done


# ======== DOWNLOAD EVERYTHING =========
    echo Downloading artifacts...
    urls=($(cat $outputFile)) > /dev/null 2>&1
    for url in "${urls[@]}"; do
        path=${url#http://*:*/*/*/}
        dir=$sourceRepo"/"${path%/*}
        mkdir -p  $dir
        cd $dir
        pwd
        curl -vks -u "$sourceUser:$sourcePassword" -D response.header -X GET "$url" -O  >> /dev/null 2>&1
        responseCode=`cat response.header | sed -n '1p' | cut -d' ' -f2`
        if [ "$responseCode" == "200" ]; then
            echo Successfully downloaded artifact: $url
        else
            echo ERROR: Failed to download artifact: $url  with error code: $responseCode
        fi
        rm response.header > /dev/null 2>&1
        cd $curFolder
    done

关于curl - 从 Nexus 3.37.1 下载整个存储库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70610642/

相关文章:

bash - curl 到 tar 以用管道压缩

docker - X509 : certfificate signed by unknown authority when using docker login from a remote machine

maven - 非官方迁移 Nexus 2 -> 3 可能用于 Maven Artifact 吗?

ssl - 使用 curl 命令在 unix/linux 中禁用证书吊销检查

linux - 通过linux命令向端口发送数据

kubernetes - 在 Kubernetes 集群中使用 Docker 运行 Nexus 3

maven - Nexus 在互联网服务器上?

docker - Nexus 3 作为 Traefik v.2 背后的 Docker Registry - 推送失败

powershell - 如何在 Powershell 中使用 Invoke-WebRequest 重新创建工作的 CURL 命令

Gradle 将多个私有(private) jar 发布到 nexus