升级harbor步骤记录

harbor从1.6.X 升级到2.X.X

如果要升级到1.10.X版本的话,操作一致,就最后的 url需要修改一下 把 v2.0给删了

升级 2.3.x的harbor的时候,docker必须是1.20以上版本

获取所有的镜像脚本 get_all_image.sh

PS 该脚本是网上扒下来的,应该是51CTO的文章,稍微修改了一下

#!/bin/bash

HARBOR=127.0.0.1
USER=admin
PASSWD=Harbor12345

curl -u "$USER:$PASSWD" $HARBOR/api/projects?
if [ $? -ne 0 ];then
   echo "Please enter the correct user name and password"
   exit 100
fi


IMAGE_RANG=$(curl -u "$USER:$PASSWD"  $HARBOR/api/search | grep "repository_name" |awk -F "\"" '{print $4}')


workdir=$(cd $(dirname $0); pwd)

# Get the latest tag and ID for all images
for i in ${IMAGE_RANG};do

    NEW_TAG_TIME=$(curl -u "$USER:$PASSWD" $HARBOR/api/repositories/$i/tags|awk '/"created"/'|sort -k 2| tail -n 1|awk -F '"' '{print $4}')

    NEW_TAG=$(curl -u "$USER:$PASSWD" $HARBOR/api/repositories/$i/tags |grep -B 7 "${NEW_TAG_TIME}" |awk '/"name": /' | awk -F '"' '{print $4}')

    for h in ${NEW_TAG};do

        IMAGE=$(echo $i:$h)

        IMAGE_ID=$(curl -u "$USER:$PASSWD" $HARBOR/api/repositories/$i/tags/$h/manifest | grep -A 7 manifest | grep digest | awk -F : '{print $3}')

        IMAGE_ID_NEW=$(echo ${IMAGE_ID:0:12})

        ID_IMAGE=$(echo $IMAGE)

        echo ${ID_IMAGE} >>a.tst
     done
done


IMAGE_FILE=`date +%Y%m%d%H%M%S.harbor_image.txt`
#awk '{printf "%-60s %70s\n",$1,$2}' $workdir/a.tst >${IMAGE_FILE}
awk '{printf "%-60s %70s\n",$1,$2}' $workdir/a.tst > harbor_image.txt
if [ $? -eq 0 ];then
    rm -rf  $workdir/a.tst
fi

echo "Please check the ${IMAGE_FILE} file."

升级步骤,不是脚本,一步步执行

harbor_url=example.com
cd /opt
tar zcvf harbor20210922.tar.gz harbor
cd /data/
tar zcvf harborData20210922.tar.gz database/ registry/ secretkey
# 执行脚本获取
cd ~
mkdir allImage
cd allImage
bash get_all_image.sh
for i in `cat harbor_image.txt`; do docker pull $harbor_url/$i; done

# 删除旧数据
cd /opt/harbor
docker-compose down
cd /data
# 除了 registry 其他全部都删了
rm -rf ca_download  config  database  job_logs  psc  redis  secretkey
# 部署harbor
cd /opt
mv harbor harbor_old
wget https://github.com/goharbor/harbor/releases/download/v2.3.2/harbor-offline-installer-v2.3.2.tgz
tar xf harbor-offline-installer-v2.3.2.tgz
cd harbor
mv harbor.yml.tmpl harbor.yml
sed -i "s#reg.mydomain.com#$harbor_url#g" harbor.yml
sed -i 's@^https:@#https:@g' harbor.yml
sed -i 's@^  port: 443@#  port: 443@g' harbor.yml
sed -i 's@^  certificate:@#  certificate:@g' harbor.yml
sed -i 's@^  private_key:@#  private_key:@g' harbor.yml
./install.sh
# 创建仓库
cd ~/allImage/
for pro in `cat harbor_image.txt |awk -F "/" '{print $1}' |sort -k2n |uniq`
do
curl -u "admin:Harbor12345" -XPOST -H "Content-Type: application/json" "http://$harbor_url/api/v2.0/projects" --data '{"project_name": "'${pro}'", "metadata":{"public":"true"}}'
done
# 推送镜像
for i in `cat harbor_image.txt`; do docker push $harbor_url/$i; done

posted @ 2021-09-22 17:04  汉克书  阅读(509)  评论(0编辑  收藏  举报