
# 迁移Nexus中hosted类型仓库的数据至CodeArts Artifact
使用CodeArts Artifact的迁移工具可将Nexus中hosted类型仓库迁移至CodeArts Artifact本地仓库。该迁移工具的原理为：通过将Nexus上的包读取到输入流中，然后调用CodeArts Artifact的接口完成上传，完成对Nexus中hosted类型仓库的迁移。
#### 前提条件
- 已完成[迁移前准备](https://support.huaweicloud.com/bestpractice-cloudartifact/cloudartifact_14_0011.html#cloudartifact_14_0011)。
- 运行环境需要为JDK17，可执行java -version命令查看运行环境。如需安装JDK17可参考[安装JRE](https://bbs.huaweicloud.com/blogs/263166)。
- 迁移工具所在机器必须与Nexus、CodeArts Artifact服务网络连通，即迁移工具所在机器可以正常访问Nexus、CodeArts Artifact服务的网络地址。可通过如下两种方法验证：
  - 打开浏览器可直接访问***Nexus域名或IP:端口*** 和CodeArts Artifact服务的***仓库地址*** （仓库地址的获取方法请参考[步骤三：获取创建的私有依赖库（本地仓库）的地址与配置]的**[1]**）。
  
  - 执行如下命令： telnet *Nexus域名或IP:端口*
    telnet *CodeArts Artifact服务的仓库地址* （仓库地址的获取方法请参考[步骤三：获取创建的私有依赖库（本地仓库）的地址与配置]的**[1]**）
    
   
 
#### 步骤一：确定需要迁移的原仓库
[确认迁移的仓库类型和仓库语言类型](https://support.huaweicloud.com/bestpractice-cloudartifact/cloudartifact_14_0011.html#cloudartifact_14_0011__zh-cn_topic_0000002377562233_zh-cn_topic_0000001981543610_section761317424416)，针对hosted类型仓库，使用本章节操作步骤进行迁移。
 #### 步骤二：在CodeArts Artifact创建私有依赖库（本地仓库）
根据[确认迁移的仓库类型和仓库语言类型](https://support.huaweicloud.com/bestpractice-cloudartifact/cloudartifact_14_0011.html#cloudartifact_14_0011__zh-cn_topic_0000002377562233_zh-cn_topic_0000001981543610_section761317424416)所确认的仓库类型，创建目标仓库，此处以创建Maven类型私有依赖库（本地仓库）为例。
1. 使用华为云账号[访问CodeArts Artifact的私有依赖库](https://support.huaweicloud.com/usermanual-cloudartifact/cloudartifact_01_0007.html#section0)。
2. 在私有依赖库页面，单击右上方"新建制品仓库"。
3. 在"新建制品仓库"页面，仓库类型选择"本地仓库"，制品类型选择"Maven"，"归属项目"可选择已规划好的项目，单击"确定"。新建成功的Maven私有依赖库将显示在仓库视图中。
4. 创建完成后应为下图所示页面，如需新建其他仓库，可以单击右上角的"新建制品仓库"。 
   ![](https://support.huaweicloud.com/bestpractice-cloudartifact/zh-cn_image_0000002376275222.png "点击放大")
   
   
   
 
 #### 步骤三：获取创建的私有依赖库（本地仓库）的地址与配置
1. 获取私有依赖库地址。
   
   1. 进入[步骤二：在CodeArts Artifact创建私有依赖库（本地仓库）]创建的私有依赖库，选择"仓库视图"。
   
   2. 单击仓库名称，右侧页面中仓库的"概览"页签中详细信息显示"仓库地址"。单击![](https://support.huaweicloud.com/bestpractice-cloudartifact/zh-cn_image_0000002377402525.png)即可复制仓库地址。
      ![](https://support.huaweicloud.com/bestpractice-cloudartifact/zh-cn_image_0000002476074257.png "点击放大")
      
      
   
   
   
   
2. 获取私有依赖库配置。 
   1. 单击页面右上方"操作指导"。
   
   2. 在"操作指导"对话框中单击"下载配置文件"，下载配置文件**settings.xml** 至本地。
      ![](https://support.huaweicloud.com/bestpractice-cloudartifact/zh-cn_image_0000002377402537.png "点击放大")
      
      
   
   3. 在本地打开配置文件**settings.xml** 文件，在其中搜索\<username\>和\<password\>所在行并如下图提取用户名与密码。
      ![](https://support.huaweicloud.com/bestpractice-cloudartifact/zh-cn_image_0000002343524636.png "点击放大")
      
   
   
   
   
 
#### 步骤四：配置私有依赖库（本地仓库）的迁移工具
1. 使用华为云账号[访问CodeArts Artifact的私有依赖库](https://support.huaweicloud.com/usermanual-cloudartifact/cloudartifact_01_0007.html#section0)。
2. 在左侧边栏中单击目标Maven私有依赖库的仓库名称。
3. 在仓库页面右上方![](https://support.huaweicloud.com/bestpractice-cloudartifact/zh-cn_image_0000002343524640.png)，单击"下载迁移工具"将迁移工具压缩包（迁移工具名称relocation-jfrog-XXX.jar、配置文件application-nexus.yaml）下载到本地。
4. 配置application-nexus.yaml文件中样例（如下表所示），该样例仅包含必须配置的参数，可直接在文件中搜索此参数名称，这些参数统一在relocation下。 
   表1application.yaml 关键配置说明 
   | 参数名称             | 样例                                                                                                                                                | 配置说明                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
   |:---|:---|:---|
   | name             | nexus-to-artifact                                                                                                                                 | 迁移任务的名称，仅作为展示。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
   | package_type     | maven                                                                                                                                             | 迁移仓库的语言类型maven、npm、pypi、go。 须知： maven的私有依赖库分为release和snapshot两种包格式，如果原仓库混合在一起，需要对原仓库进行两次迁移，分别迁移release和snapshot到不同格式的maven仓库中。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
   | migrate_type     | nexus3                                                                                                                                            | 迁移类型，nexus3或nexus2，根据不同的Nexus版本填写。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
   | save_temp_dir    | D:/tmp/xxx/                                                                                                                                       | 迁移缓存路径， 迁移maven时必填，以"/"结尾, 此路径用于缓存maven的快照版本名称并最终上传。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
   | domain           | http://{ip}:{port}                                                                                                                                | 原仓库的域名，最后的路径需没有'/'。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
   | repo             | test_maven                                                                                                                                        | 原仓库名称，Nexus上的仓库名，通过Nexus页面确认要迁移的仓库的NAME字段获取。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
   | user_name        | username                                                                                                                                          | 原仓库的用户名。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
   | password         | password                                                                                                                                          | 原仓库的密码。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
   | target_domain    | https://{domain}/artgalaxy https://{domain}/artgalaxy/api/npm                | 目标仓库的域名。 通过私有库页面上仓库地址获取[步骤三：获取创建的私有依赖库（本地仓库）的地址与配置]。 - 例如仓库地址为： https://{domain}/artgalaxy/*xx* -north-*xxx* _*xxxxxxxx*_maven_1_388/ 则此处填写：https://{domain}/artgalaxy   - 例如仓库地址为： https://{domain}/artgalaxy/api/npm/*xx* -north-*xx* _*xxxxxxx*_npm_6944/ 则此处填写：https://{domain}/artgalaxy/api/npm             |
   | target_repo      | *xx* -north-*xxx* _*xxxxxxxx*_maven_1_388 *xx* -north-*xx* _*xxxxxxx*_npm_6944 | 目标仓库名称。 通过仓库地址获取，[步骤三：获取创建的私有依赖库（本地仓库）的地址与配置]。 - 例如仓库地址为： https://{domain}/artgalaxy/xx-north-*xxx* _x*xxxxxxx*_maven_1_388/ 则此处填写：*xx* -north-*xxx* _*xxxxxxxx*_maven_1_388   - 例如仓库地址为： https://{domain}/artgalaxy/api/npm/*xx* -north-*xx* _*xxxxxxx*_npm_6944/ 则此处填写：*xx* -north-*xx* _*xxxxxxx*_npm_6944    |
   | target_user_name | username                                                                                                                                          | 目标仓库用户名，可以通过[步骤三：获取创建的私有依赖库（本地仓库）的地址与配置]获取。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
   | target_password  | password                                                                                                                                          | 目标仓库密码，可以通过[步骤三：获取创建的私有依赖库（本地仓库）的地址与配置]获取。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
      
   最简易application-nexus.yaml
   ```
   spring:
     main:
       web-application-type: none
   relocation:
     # 迁移任务的名称，仅作为展示
     name: nexus-to-artifact
     # 迁移仓库的语言类型maven npm pypi go等
     package_type: maven
     # 迁移类型，支持governance jfrog nexus3/nexus2
     migrate_type: "nexus3"
     # 迁移缓存路径， 迁移maven时必填, "/"结尾, 此路径用于缓存maven的快照版本名称并最终上传
     save_temp_dir: "D:/tmp/xxx/" 
     # 原仓库参数， 仅jfrog nexus场景需要配置
     # 原仓库的地址，最后的路径需没有'/'
     domain: 'http://{domain}/artifactory'
     # 原仓库的仓库名称
     repo: 'test-maven'
     # 原仓库的用户名
     user_name: "username"
     # 原仓库的密码
     password: "password"
     # 目标仓库参数
     # 目标仓库地址，最后的路径需没有'/',从页面上获取
     target_domain: 'https://{domain}/artgalaxy/xxxx/xxxx'
     # 目标仓库的名称
     target_repo: xxxxx
     # 目标仓库用户名
     target_user_name: 'username'
     # 目标仓库密码
     target_password: 'password'
   ```
   
   
5. 全量配置参数application.yaml 参数参考。 
   ```
   spring:
     main:
       web-application-type: none
   relocation:
     # 迁移程序通用配置
     # 迁移程序核心线程数量
     corePoolSize: 20
     # 迁移程序最大线程池数量
     maxPoolSize: 40
     # 迁移程序线程池队列大小
     queueCapacity: 99999999
     # 迁移程序的最大迁移速度 单位 MB/s，默认值为20
     speed_limit: 20
     # jfrog 迁移场景参数，此参数表示迁移包修改时间从modifiedFrom 到 modifiedTo 时间之间的包（时间戳）
     modifiedFrom:
     modifiedTo:
     # 迁移任务的名称，仅作为展示
     name: jfrog-to-artifact
     # 迁移仓库的语言类型
     package_type: maven
     # 迁移类型，支持governance jfrog nexus
     migrate_type: "nexus"
     # 迁移缓存路径， 迁移maven时必填,"/"结尾
     save_temp_dir: "/xxxx/"
     # 原仓库参数， 仅jfrog nexus场景需要配置
     # 原仓库的地址，最后的路径需没有'/'
     domain: 'http://{domain}/artifactory'
     # 原仓库的仓库名称
     repo: 'test-maven-source'
     # 原仓库的类型，默认为artifactory
     repo_type: artifactory
     # 原仓库的用户名
     user_name: "username"
     # 原仓库的密码
     password: "password"
     # 如果是jfrog场景，此处可填写原仓库的子路径，支持子路径迁移
     source_sub_path:
     # 目标仓库参数
     # 目标仓库地址，最后的路径需没有'/',从页面上获取
     target_domain: 'https://{domain}/artgalaxy/xxxx/xxxx'
     # 目标仓库的名称
     target_repo: xxxxx
     # 目标仓库的类型，默认为artifactory
     target_repo_type: artifactory
     # 目标仓库用户名
     target_user_name: 'username'
     # 目标仓库密码
     target_password: 'password'
     # governance迁移参数 迁移python无需关注
     # governance迁移场景的domain_id
     domain_id: test009
     # governance场景下是否需要调用governance服务，如果是true将不调用governance
     call_governance_use_local: true
     # governance 迁移仓库的语言仓类型
     governance_type: maven
     # governance实体包的存放路径
     migrate_local_path: ""
     # governance元数据文件，表示需要迁移的元数据文件
     migrate_metadata_path: ""
     # 回调governance的路径，此路径需要单独设置一个空路径
     governance_save_path: ""
     # 回调governance的url
     governance_url: ""
     # 用户的ak，用于回调governance接口
     access_key_id: ""
     # 用户的sk，用于回调governance接口
     secret_access_key: ""
     # 是否仅通过governance_save_path中的缓存信息回调governance
     only_update_governance: false
     # 迁移governance最大的文件数量，此数量为migrate_metadata_path中的元数据数目
     migrate_max_num: -1
   ```
   
   
 
#### 步骤五：执行迁移
1. 执行如下迁移脚本。 
   ```
   java -jar relocation-jfrog-20251016.1.jar --spring.config.location=application-nexus.yaml > /log/relocation-jfrog.log 2>&1 &
   ```
   
   
2. 进入对应的私有依赖库（本地仓库），查看hosted类型仓库的组件包是否上传成功。
 
#### 步骤六：使用迁移后的CodeArts Artifact私有依赖库进行构建
当完成对应语言仓的迁移后，进入迁移后的语言仓，单击对应仓库右上角的"操作指导"，获取对应的配置文件，上传到需要构建的代码仓中，在相应编译时选择此文件即可完成编译。
![](https://support.huaweicloud.com/bestpractice-cloudartifact/zh-cn_image_0000002625425283.png "点击放大")
