From a520b2a33dfb2b8ee0e435261d38a14b218859d4 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 16 Sep 2025 03:04:43 +0000 Subject: [PATCH] =?UTF-8?q?[#1]=20=E5=A2=9E=E5=8A=A0=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E9=95=9C=E5=83=8F=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/log/.gitignore | 2 + src/log/scripts/save_images.sh | 140 +++++++++++++++++++++++++++++++++ 2 files changed, 142 insertions(+) create mode 100755 src/log/scripts/save_images.sh diff --git a/src/log/.gitignore b/src/log/.gitignore index 7546a9c..81709f4 100644 --- a/src/log/.gitignore +++ b/src/log/.gitignore @@ -1,3 +1,5 @@ private/ + +images/ diff --git a/src/log/scripts/save_images.sh b/src/log/scripts/save_images.sh new file mode 100755 index 0000000..5a9b268 --- /dev/null +++ b/src/log/scripts/save_images.sh @@ -0,0 +1,140 @@ +#!/usr/bin/env bash +set -euo pipefail + +echo "=======================================" +echo "ARGUS Log System - Image Export Tool" +echo "=======================================" +echo "" + +# 获取脚本所在目录和输出目录 +script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +output_dir="$script_dir/../images" + +# 确保输出目录存在 +mkdir -p "$output_dir" + +# 定义镜像名称和版本 +ES_IMAGE="argus-elasticsearch:latest" +KIBANA_IMAGE="argus-kibana:latest" + +# 定义输出文件名 +ES_TAR="argus-elasticsearch-latest.tar" +KIBANA_TAR="argus-kibana-latest.tar" + +# 函数:检查镜像是否存在 +check_image() { + local image_name="$1" + if docker images --format "table {{.Repository}}:{{.Tag}}" | grep -q "^$image_name$"; then + echo "✅ Image found: $image_name" + return 0 + else + echo "❌ Image not found: $image_name" + return 1 + fi +} + +# 函数:保存镜像 +save_image() { + local image_name="$1" + local output_file="$2" + local output_path="$output_dir/$output_file" + + echo "🔄 Saving $image_name to $output_file..." + + # 删除旧的镜像文件(如果存在) + if [[ -f "$output_path" ]]; then + echo " Removing existing file: $output_file" + rm "$output_path" + fi + + # 保存镜像 + docker save "$image_name" -o "$output_path" + + # 检查文件大小 + local file_size=$(du -h "$output_path" | cut -f1) + echo "✅ Saved successfully: $output_file ($file_size)" +} + +# 函数:显示镜像信息 +show_image_info() { + local image_name="$1" + echo "📋 Image info for $image_name:" + docker images "$image_name" --format " Size: {{.Size}}, Created: {{.CreatedSince}}, ID: {{.ID}}" +} + +echo "🔍 Checking for ARGUS custom images..." +echo "" + +# 检查镜像是否存在 +es_exists=false +kibana_exists=false + +if check_image "$ES_IMAGE"; then + show_image_info "$ES_IMAGE" + es_exists=true +else + echo "⚠️ Elasticsearch image not found. Please build it first with:" + echo " cd ../elasticsearch/build && docker build -t $ES_IMAGE ." +fi + +echo "" + +if check_image "$KIBANA_IMAGE"; then + show_image_info "$KIBANA_IMAGE" + kibana_exists=true +else + echo "⚠️ Kibana image not found. Please build it first with:" + echo " cd ../kibana/build && docker build -t $KIBANA_IMAGE ." +fi + +echo "" + +# 如果没有镜像存在,退出 +if [[ "$es_exists" == false && "$kibana_exists" == false ]]; then + echo "❌ No ARGUS images found to export. Please build the images first." + exit 1 +fi + +echo "💾 Starting image export process..." +echo "" + +# 保存 Elasticsearch 镜像 +if [[ "$es_exists" == true ]]; then + save_image "$ES_IMAGE" "$ES_TAR" +fi + +echo "" + +# 保存 Kibana 镜像 +if [[ "$kibana_exists" == true ]]; then + save_image "$KIBANA_IMAGE" "$KIBANA_TAR" +fi + +echo "" +echo "=======================================" +echo "📦 Export Summary" +echo "=======================================" + +# 显示导出的文件 +echo "📁 Exported files in $output_dir:" +for file in "$ES_TAR" "$KIBANA_TAR"; do + full_path="$output_dir/$file" + if [[ -f "$full_path" ]]; then + size=$(du -h "$full_path" | cut -f1) + echo " ✅ $file ($size)" + fi +done + +echo "" +echo "🚀 Usage instructions:" +echo " To load these images on another system:" +if [[ -f "$script_dir/$ES_TAR" ]]; then + echo " docker load -i $ES_TAR" +fi +if [[ -f "$script_dir/$KIBANA_TAR" ]]; then + echo " docker load -i $KIBANA_TAR" +fi + +echo "" +echo "✅ Image export completed successfully!" +echo "" \ No newline at end of file