Skip to content

从 docker 部署的 metersphere 中导出数据库数据

bash
docker exec -it metersphere /bin/bash

#数据目录 /opt/metersphere/data
#配置文件 /opt/metersphere/conf
#日志 /opt/metersphere/logs
$ cd /opt/metersphere/conf
$ cat metersphere.properties
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/test?autoReconnect=false
spring.datasource.username=root
spring.datasource.password=111111

# 备份mysql,-h必须要写,default-character-set必须设置
$ docker exec -i metersphere mysqldump --default-character-set=utf8mb4 --hex-blob -uroot -p111111 -h127.0.0.1 test > metersphere.sql
# 使用scp拷贝
$ scp ci@10.181.22.134:/home/ci/metersphere.sql /Users/jade/Downloads/metersphere.sql

迁移 mysql

sql
# mysqlrootpwd
CREATE USER metersphereadmin@'%' IDENTIFIED BY 'meterspherepwd';
CREATE DATABASE `meterspheredb` DEFAULT CHARACTER SET = `utf8mb4` DEFAULT COLLATE = `utf8mb4_general_ci`;
GRANT ALL PRIVILEGES ON `meterspheredb`.* TO metersphereadmin@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;

修改链接配置

url=10.181.22.134:3306
username=metersphereadmin
password=meterspherepwd

问题

导出中文乱码

  • 设置 --default-character-set=utf8mb4
  • longblob 导致乱码 在命令上加上参数 --hex-blob

导出时排除二进制数据

如果数据库中存在 BLOBBINARY 类型的数据,可以尝试排除这些列,以确保导出文件是纯文本格式:

bash
docker exec -i metersphere mysqldump --default-character-set=utf8mb4 --skip-extended-insert --skip-opt -uroot -p111111 -h127.0.0.1 test > metersphere.sql
  • --skip-extended-insert:避免合并多行插入,确保每行数据独立。
  • --skip-opt:禁用默认选项,确保导出更兼容的 SQL 文件。

S1. 让源码运行起来

maven 配置,替换 maven 下载地址

properties
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.3/apache-maven-3.8.3-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar
# 替换为
distributionUrl=https://mirrors.aliyun.com/apache/maven/maven-3/3.8.3/binaries/apache-maven-3.8.3-bin.zip
wrapperUrl=https://maven.aliyun.com/repository/public/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar

运行配置,数据库、kafka、redis、minio 等

properties

/Volumes/macdata/temp/conf/metersphere.properties

spring.datasource.url=jdbc:mysql://10.181.22.134:3306/meterspheredb?autoReconnect=false&useUnicode=true&characterEncoding=UTF-8&characterSetResults=UTF-8&zeroDateTimeBehavior=convertToNull&allowPublicKeyRetrieval=true&useSSL=false&sessionVariables=sql_mode=%27STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION%27
spring.datasource.username=metersphereadmin
spring.datasource.password=meterspherepwd
kafka.bootstrapServers=10.181.22.134:9092
minio.endpoint=http://10.177.11.188:9000
minio.accessKey=metersphere
minio.secretKey=Password123@minio

/Volumes/macdata/temp/conf/redisson.yml => /opt/metersphere/conf/redisson.yml

singleServerConfig:
  password: redisadmin
  address: "redis://10.177.11.188:6379"
  database: 0
threads: 4
nettyThreads: 8

二开步骤:

S1.使用 unocss 代替 tailwindcss

S2. 删除接口测试相关代码

vue
<template>
  <div>当前文件路径: 1</div>
</template>

<script setup lang="ts"></script>

<style lang="less" scoped></style>

报错

Error1: [plugin:vite:css] [postcss] /Users/jade/Documents/code/open/metersphere/frontend/src/assets/style/global.less:8:3: The inline-block, class does not exist. If inline-block, is a custom class, make sure it is defined within a @layer directive.

/Users/jade/Documents/code/open/metersphere/frontend/src/assets/style/global.less:8:2
6  |
7  |  @tailwind base;
8  |  @tailwind components;
   |    ^
9  |  @tailwind utilities;
10 |  * {

使用新项目迁移

https://v3.tailwindcss.com/docs/guides/vite#vue

bash
$ pnpm create vite@latest testcase-web --template vue-ts

$ pnpm add -D tailwindcss@3 postcss autoprefixer

增加 postcss、tail

pnpm add
[plugin:vite:css] Failed to load PostCSS config (searchPath: /Users/jade/Documents/code/company/testcase-web): [ReferenceError] module is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '/Users/jade/Documents/code/company/testcase-web/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
ReferenceError: module is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '/Users/jade/Documents/code/company/testcase-web/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
    at file:///Users/jade/Documents/code/company/testcase-web/postcss.config.js?t=1755073033566:1:1
    at ModuleJob.run (node:internal/modules/esm/module_job:234:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:473:24)
    at async req$3 (file:///Users/jade/Documents/code/company/testcase-web/node_modules/.pnpm/vite@7.1.2_jiti@1.21.7_yaml@2.8.1/node_modules/vite/dist/node/chunks/dep-CMEinpL-.js:8641:12)
    at async Object.search (file:///Users/jade/Documents/code/company/testcase-web/node_modules/.pnpm/vite@7.1.2_jiti@1.21.7_yaml@2.8.1/node_modules/vite/dist/node/chunks/dep-CMEinpL-.js:8451:24)