#!/bin/bash
#***************************************************************#
# ScriptName: ctr_export_all_images.sh
# Author: xhy
# Create Date: 2025-02-26 15:59
# Modify Author: xhy
# Modify Date: 2025-08-27 13:40
# Version: v1
#***************************************************************#

# 创建目标目录
IMAGEDIR=/root/images
mkdir -p ${IMAGEDIR}

# 遍历所有镜像并导出
images=$(ctr -n=k8s.io image ls -q|egrep -v 'sha256')
for image in ${images}; do

  echo -e "\n\033[33m[INFO] 正在导出镜像: ${image} 至 ${IMAGEDIR} ...\033[0m"

  ctr -n=k8s.io image export "${IMAGEDIR}/$(echo ${image} | tr '/' '_' | tr ':' '_').tar" ${image}
done

  echo -e "\n\033[32m[SUCC] 所有镜像已导出至 ${IMAGEDIR} 目录...\033[0m"
