为方便打包源成分,我们提供了一个打包脚本示例。脚本会将Docker源成分(配置文件)按照其原目录结构打包为DockerConf.tar.gz。
该脚本只是一个打包示例,不存在危险操作、源码泄露。
- 请在源虚拟机的任意位置创建一个.sh脚本文件(例如pack_docker_sources.sh),脚本内容详见pack_docker_sources.sh链接。
- 执行该脚本以完成打包过程,打包完成后,您可以根据提示信息获取打包文件。
bash /path/to/pack_docker_sources.sh
显示信息如下所示,加粗内容则为打包文件路径:
Checking the configuration files...
Starting to compress the configuration files...
/root/.docker/config.json
/etc/docker/daemon.json
/etc/systemd/system/docker.service.d/http-proxy.conf
DockerConf/
DockerConf/config.json.tar.gz
DockerConf/daemon.json.tar.gz
DockerConf/http-proxy.conf.tar.gz
Compression completed. The package is saved as /root/DockerConf.tar.gz.
若在Windows系统创建脚本,由于Windows和Linux的换行符表示方式不同,则在Linux系统执行脚本可能会出现以下报错,请按照如下步骤进行操作。
| -bash: ./autoBuild.sh: /bin/bash^M: bad interpreter: No such file or directory
|
- 安装dos2unix。
- 安装成功后执行以下命令。
| dos2unix pack_docker_sources.sh
|
- 执行完成后请重新启动脚本。
若您无可用Yum源安装失败,请执行以下命令,执行完成后请重新启动脚本。
| sed -i 's/\r//g' pack_docker_sources.sh
|
- 可通过以下两种方式获取源成分。
- 若使用“源成分包上传”方式,返回“添加成分信息”页签,单击“源成分包上传”后“上传”按钮,上传打包的源成分包。
- 若使用“节点服务器获取”方式,请执行如下命令解压源成分压缩包。
- 使用SSH远程登录工具,将压缩包上传至“所属节点”的自定义路径。
- 指定压缩包所在路径为“源成分所在路径”,例如:/home/DockerConf.tar.gz。
pack_docker_sources.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 | #!/bin/bash
# 设置脚本错误处理
set -e
# 定义要检查的文件路径数组
files=(
"${HOME}/.docker/config.json"
"/etc/docker/daemon.json"
"/etc/systemd/system/docker.service.d/http-proxy.conf"
)
# 检查相关配置文件是否存在
echo "Checking the configuration files..."
existing_files=()
for file in "${files[@]}"; do
if [ -f "$file" ]; then
existing_files+=("$file")
fi
done
# 如果有文件存在,开始压缩
if [ ${#existing_files[@]} -gt 0 ]; then
echo "Starting to compress the configuration files..."
# 创建临时配置文件保存目录
temp_dir="${HOME}/DockerConf"
mkdir -p "$temp_dir"
# 压缩存在的配置文件
for file in "${existing_files[@]}"; do
file_name=$(basename "$file")
tar -Pczvf "$temp_dir/${file_name}.tar.gz" "$file"
done
# 压缩 Docker 相关配置文件
cd "$HOME" && tar -czvf DockerConf.tar.gz DockerConf && rm -rf "$temp_dir"
echo "Compression completed. The package is saved as ${HOME}/DockerConf.tar.gz"
else
echo "No configuration files are found for any of the source components. Select No source component available to migrate the middleware."
fi
|