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
__EOF__