页次: 1
---For harbor API V1.x---
#!/bin/bash
URL="https://reg.xxx.cn"
IP="reg.xxx.cn"
REPOS=$(curl -s -k -u "admin:a$6^tWduvy\!8" -X GET --header 'Accept: application/json' "${URL}/api/repositories?project_id=4"|grep "name"|awk -F '"' '{print $4}')
for rp in ${REPOS}
do
TAG=$( curl -s -k -u "admin:a$6^tWduvy\!8" -X GET --header 'Accept: application/json' "${URL}/api/repositories/${rp}/tags" |grep \"name\"|awk -F '"' '{print $4}'|sort -r|head -n1 )
IMAGE=$IP/$rp:$TAG
echo docker pull $IMAGE
docker save reg.xxx.com/$rp:$TAG -o $rp-$TAG.tar
done
---For harbor API V2.x---
Harbor_Address=https://harbor.xxx.cn #Harbor主机地址
Harbor_Pulltag=harbor.xxx.cn
Harbor_User=admin #登录Harbor的用户
Harbor_Passwd=Syxxx@I23 #登录Harbor的用户密码
Tar_File=/home/bjt/bjt-7niu/harbor #镜像tar包存放路径
mkdir -p $Tar_File
cd $Tar_File
# 获取Harbor中所有的项目(Projects)
Project_List=$(curl -s -u 'admin:Syswin@I23' --limit-rate 1M -H 'Content-Type: application/json' -X GET ${Harbor_Address}/api/v2.0/projects/bjtoon/repositories?page_size=100 -k | python -m json.tool | grep name | awk '/"name": /' | awk -F '"' '{print $4}' )
for Project in $Project_List;do
# 循环获取项目下所有的镜像
mkdir -p ${Tar_File}/${Project}
Image_Tags=$(curl -s -u $Harbor_User:$Harbor_Passwd -H "Content-Type: application/json" -X GET $Harbor_Address/v2/$Project/tags/list?page_size=100 -k | awk -F '"' '{print $8,$10,$12}'|sort |awk '{print $NF}')
Image_p_name="${Harbor_Pulltag}/${Project}:${Image_Tags}"
docker pull "${Image_p_name}"
docker save "${Image_p_name}" -o "${Project}".tar
gzip -9 $Project.tar
done
最近编辑记录 小天天 (2023-12-29 14:31:53)
离线
页次: 1