欢迎阅读!

潇湘夜雨

当前位置: 主页 > 系统 > 云计算与云原生 >

jfrog仓库迁移到nexus

时间:2026-01-30 13:24来源:未知 作者:华嵩阳 点击:
一、npm仓库迁移步骤 1、查询pkg的仓库地址 curl -s https://jfrog.test.com/artifactory/api/repositories|jq .[]|select(.packageType == Npm)|select(.type == LOCAL)|select(.key | test(test|imd)) { key: test-npm-local-hz, type: LOC

一、npm仓库迁移步骤

1、查询pkg的仓库地址

curl -s https://jfrog.test.com/artifactory/api/repositories|jq '.[]|select(.packageType == "Npm")|select(.type == "LOCAL")|select(.key | test("test|imd"))'
{
  "key": "test-npm-local-hz",
  "type": "LOCAL",
  "url": "https://jfrog.test.com/artifactory/test-npm-local-hz",
  "packageType": "Npm"
}

2、下载npm包到本地

准备工作:安装jf客户端工具

配置pkg的仓库:jf c add source-artifactory --url=https://jfrog.test.com

下载npm仓库:jf rt dl "test-npm-local-hz" ./sync_temp/ --server-id=source-artifactory

3、上传npm包的nexus仓库

上传脚本:

#!/bin/bash
source_dir="sync_npm"
for in $(find $sync_npm -type f -name "*.tgz")
do
        echo $i
        #sleep 1
        curl -X POST -u "用户名:密码"  -H "Content-Type: multipart/form-data" -F "file=@$i"  'https://nexus.test.com/service/rest/v1/components?repository=dag-npm-local-hz'
done
二、maven仓库迁移步骤

1、查看maven仓库信息

curl -s https://jfrog.test.com/artifactory/api/repositories|jq '.[]|select(.packageType == "Maven")|select(.type == "LOCAL")|select(.key | test("test|imd"))'
{
  "key": "test-maven-release-hz",
  "type": "LOCAL",
  "url": "https://jfrog.test.com/artifactory/test-maven-release-hz",
  "packageType": "Maven"
}

2、下载pkg的maven仓库到本地目录

jf rt dl "test-maven-release-hz" ./sync_maven/ --server-id=source-artifactory

3、上传下载的仓库文件到nexus仓库

bash  mavenimport.sh -u 用户名-p 密码 -r https://nexus.test.com/repository/dag-maven-release-hz -d 本地仓库目录

上传脚本:

 

#!/bin/bash
 
# copy and run this script to the root of the repository directory containing files
# this script attempts to exclude uploading itself explicitly so the script name is important
# Get command line params
#repo_dir="/home/lzh/Downloads/sync_maven/"
while getopts ":r:u:p:d:" opt; do
        case $opt in
                r) REPO_URL="$OPTARG"
                ;;
                u) USERNAME="$OPTARG"
                ;;
                p) PASSWORD="$OPTARG"
                ;;
                d) REPO_DIR="$OPTARG"
                ;;
        esac
done
cd $REPO_DIR
for in $(find . -type f -not -path './mavenimport\.sh*' -not -path '*/\.*' -not -path '*/\^archetype\-catalog\.xml*' -not -path '*/\maven\-metadata\.xml' -not -path '*/\^maven\-metadata\-deployment*\.xml' sed "s|^\./||")
do
    echo $i
    curl -u "$USERNAME:$PASSWORD" -X PUT -H "Content-Type: multipart/form-data"  -T $i ${REPO_URL}/$i
done

三、raw仓库上传
1、下载仓库文件到本地

jf rt dl "XX-generic-public-hz" ./public-hz/ --server-id=source-artifactory

2、上传文件到nexus仓库

bash  -x rawimport.sh -u 用户名 -p 密码 -r https://devoXX.XXX.com/repository/raw-hosted -d 本地仓库文件目录

上传脚本(依赖jq命令工具):

#!/bin/bash
 
# copy and run this script to the root of the repository directory containing files
# this script attempts to exclude uploading itself explicitly so the script name is important
# Get command line params
while getopts ":r:u:p:d:" opt; do
        case $opt in
                r) REPO_URL="$OPTARG"
                ;;
                u) USERNAME="$OPTARG"
                ;;
                p) PASSWORD="$OPTARG"
                ;;
                d) REPO_DIR="$OPTARG"
                ;;
        esac
done
IFS=$'\n'
cd $REPO_DIR
for in $(cat file.txt)
do
    echo "file:$i"
    url_path=$(echo -n "$i" | jq -sR @uri|sed 's/"//g')
    curl -u "$USERNAME:$PASSWORD" -X PUT -H "Content-Type: multipart/form-data"  -T "$i" "${REPO_URL}/$url_path"
done
Sonatype 社区提供了一个官方的导入工具,适合喜欢使用标准化工具的用户。
git clone https://github.com/sonatype-nexus-community/nexus-repository-import-scripts.git
有3种仓库的迁移脚本:

mavenimport.sh  npmimport.sh  nugetimport.sh  README.md
 
(责任编辑:liangzh)
织梦二维码生成器
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------