harbor批量导出镜像
工作中遇到一个问题,要把某个项目的harbor镜像库全部迁移到其他环境的harbor上,由于网络不通,只能导出来,传给同事,让同事导入到他们的harbor上;
记录下我的操作方法。
1.批量导出harbor某个项目的镜像库
## 查到harbor的项目编号
curl -X GET --header 'Accept: application/json' 'http://192.168.10.16/api/search?q=paas-k8s'
#!/bin/bash
URL="http://192.168.10.16"
IP="192.168.10.16"
USER="admin"
PASS="fana"
REPOS=$(curl -s -X GET --header 'Accept: application/json' "${URL}/api/repositories?project_id=3"|grep "name"|awk -F '"' '{print $4}')
for rp in ${REPOS}
do
TAGS=$(curl -s -X GET --header 'Accept: application/json' "${URL}/api/repositories/${rp}/tags"|grep \"name\"|awk -F '"' '{print $4}'|sort -r)
a=$(echo ${rp}|awk -F "/" '{print $2}')
for t in ${TAGS}
do
docker pull ${IP}"/"${rp}":"${t}
echo ${IP}"/"${rp}":"${t} >> /opt/docker.tag
docker save ${IP}"/"${rp}":"${t} > /opt/docker/${IP}-${a}-${t}.tar.gz
done
echo "===================="
done
2.批量导入到images
for i in `ll /opt/docker|awk '{print $9}'`;do docker load < $i;done
3.批量push到harbor
for i in `docker images|awk '{print $1}'|grep -v REPOSITORY`;do docker push $i; done
#或
for i in `cat /opt/docker.tag`;do docker push $i;done