前言

Harbor原生的复制策略无法在复制任务执行前,对比源仓库和目标仓库镜像及其tag的差异,发现差异并报告,Harbor复制任务的日志无法直观的查看复制镜像的详情,选择regsync进行镜像复制

regsync的配置清晰、易于管理、版本控制友好、可以定义复杂的同步规则。

一、regsync是什么

regsync是1个开源的命令行工具 (CLI),它的核心功能是在不同的容器镜像仓库之间自动、高效地同步容器镜像及其标签。

简单来说:你可以把 RegSync 想象成一个专门负责镜像仓库之间“搬运”镜像的智能快递员。

二、使用regsync

下载regsync安装包支持Windows/Mac/Linux平台;

1.生成复制清单

通过1个YAML配置文件 (regsync.yaml) 来定义所有同步任务

version: 1
creds:
  - registry: harborA.devops.com
    user: admin
    pass: xxxx
    tls: disabled
  - registry: harborB.devops.con
    user: admin
    pass: xxx
    tls: disabled

defaults:
  type: docker
  tls: disabled
sync:
  - source: harborA.devops.com/devops/busybox
    target: harborB.devops.com/devops/busybox
    type: repository
    recurse: true
    copyAllTags: true
    tags:
      allow: [".*"]
  - source: harborA.devops.com/devops/drawio
    target: harborB.devops.com/devops/drawio
    type: repository
    recurse: true
    copyAllTags: true

2.执行复制任务

2.1.check

对比源仓库和目标仓库,待复制镜像及其tag并生成报告

root@master-01:/# regsync -c reync.yaml check
time=2025-06-28T02:26:32.298Z level=WARN msg="Changing TLS settings for registry" orig=enabled new=disabled host=newharbor.devops.test
time=2025-06-28T02:26:32.298Z level=WARN msg="Changing TLS settings for registry" orig=enabled new=disabled host=artifactory.devops.test
time=2025-06-28T02:26:56.348Z level=INFO msg="Image sync needed" source=newharbor.devops.test/devops/busybox:v100 target=artifactory.devops.test/devops/busybox:v100
time=2025-06-28T02:26:57.448Z level=INFO msg="Image sync needed" source=newharbor.devops.test/devops/drawio:v1 target=artifactory.devops.test/devops/drawio:v1
time=2025-06-28T02:26:57.711Z level=INFO msg="Image sync needed" source=newharbor.devops.test/devops/drawio:v100 target=artifactory.devops.test/devops/drawio:v100

2.2.执行复制任务

#Linux
regsync -c reync.yaml once --missing
#windows
D:\regsync>regsync.exe -c ./config/regsync.yaml once --missing

 

参考

posted on 2025-06-28 10:17  Martin8866  阅读(51)  评论(0)    收藏  举报