Skip to content

[Compatibility]: mo-dump -csv 导出记录绝对路径,备份文件无法跨机器/跨目录恢复 #30481

Closed
matrixorigin/mo_dump
#58

Description

@daviszhen

环境:MatrixOne 8.0.30-MatrixOne-v4.2.5(arm64/linux)。

现象:mo-dump -csv 的产物无法跨机器/跨目录恢复

-csv 模式下,mo-dump 把数据写入本地 CSV 文件,并在 SQL 脚本里用 导出时的绝对路径 引用它:

LOAD DATA LOCAL INFILE '/tmp/csvout/spt_s.csv' INTO TABLE `s`
  FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n' PARALLEL 'FALSE';

因此恢复能否成功,取决于原机器上那个绝对路径是否仍然存在:

场景 结果
在原路径所在机器恢复,CSV 仍在 /tmp/csvout/ ✅ 成功(3 行、2MB 大值完整)
从另一个目录执行该 dump(CSV 仍在原绝对路径) ✅ 成功(绝对路径仍命中)
CSV 已移动/删除后恢复 ❌ ERROR 2 (HY000) at line 15: File '/tmp/csvout/spt_s.csv' not found (OS errno 2 - No such file or directory)
换一台机器恢复(CSV 一并拷过去,但路径不同) ❌ 同上(脚本里写的是旧机器的绝对路径,需先人工改写)
客户端未开 --local-infile ❌ ERROR 2068 (HY000) at line 15: LOAD DATA LOCAL INFILE file request rejected due to restrictions on access.

影响

  1. 逻辑备份不可搬迁:备份的目的是"出事了能在别处恢复"。-csv 的 dump 只有在恢复机上的绝对路径与导出机完全一致时才可用 —— 跨机器、跨目录、容器化恢复都需要先对脚本做路径改写,属于容易在演练时才暴露的坑。
  2. 两个文件必须成对保管:.sql 脚本 + 同名 CSV 文件;只保留 .sql 会得到一个"看起来完整但无法恢复"的备份(与恢复时才报 ERROR 2)。
  3. 默认(非 -csv)模式没有这个问题 —— 数据以 INSERT 语句写在 dump 内,无外部文件依赖,实测向量列 / BLOB / 2MB 大值 / 特殊字符全部逐行一致。

复现

docker run -d --name mo -p 6001:6001 matrixorigin/matrixone:latest
mysql -h127.0.0.1 -P6001 -uroot -p111 -e "create database t1; create table t1.s(id int primary key, t text); insert into t1.s values (1,'a');"
mo-dump -u root -p 111 -h 127.0.0.1 -P 6001 -db t1 -csv > d.sql     # 生成 t1_s.csv(当前目录)
grep 'LOAD DATA' d.sql                                              # 里面是绝对路径
mysql --local-infile=1 -h127.0.0.1 -P6001 -uroot -p111 < d.sql      # 同机同路径 → 成功
mv t1_s.csv /tmp/; mysql --local-infile=1 -h127.0.0.1 -P6001 -uroot -p111 < d.sql   # → ERROR 2

建议

  1. 导出时写相对路径(相对 dump 文件所在目录),或提供一个参数让用户指定输出路径的写法(如 -csv-dir / 相对模式);这样"把 .sql 与 .csv 放在同一目录"即可恢复,符合备份的直觉;
  2. 若短期保持绝对路径,建议:
    • 在文档中显著说明 -csv 的 dump 依赖绝对路径、需连同 CSV 一起搬迁并改写路径;
    • 在 dump 文件头部加注释说明这一依赖;
  3. 客户端侧要求(必须 --local-infile=1)建议一并在文档写明,否则首次恢复会直接撞 ERROR 2068;
  4. 文档中可明确推荐:需要可搬迁的逻辑备份时使用默认模式(INSERT,无外部文件依赖),-csv 仅用于需要 CSV 数据文件本身的场景。

关联

Activity

  1. added
    priority/p2
    kind/compatibility
    on Oct 17, 2026
  2. slyunnn commented on Oct 27, 2026

    @slyunnn

    Regression and extended verification for #30481 (2026-10-27)

    Verification Environment

    • MatrixOne latest main: 802376360c574f44aea23db5eef3cfcebf0527fd — perf: adapt bulk user AUTO_INCREMENT prefetch to observed demand (#31410); freshly built runtime git_version() = 8023763.
    • mo_dump latest main: 9f0cc1173a9dc2def2656de3cb5c4b988c879442 — Merge pull request #69 from ck89119/issue-30917-main; the tested mo-dump binary was built from this checkout.
    • Local topology: 2 CN / 1 TN / 1 LogService / Proxy. Proxy 26833, CN1 27151, and CN2 27152 were reachable. Export and restore used Proxy; restored rows were read through all three endpoints.
    • Client: mo-dump and MySQL CLI over TCP using the MySQL wire protocol; CSV restore used --local-infile=1.

    What Was Covered

    • OK The original -csv export generated LOAD DATA LOCAL INFILE with a relative CSV filename, not the export-time absolute path.
    • OK Moved the SQL/CSV pair to a different directory, verified the original directory no longer existed, dropped the disposable source database, and restored from the new working directory. All 3 rows matched the original lengths and MD5 digests, including a 2,097,152-byte LONGTEXT value and comma-containing text.
    • OK Read back the restored rows through Proxy, CN1, and CN2; lengths and digests matched on each endpoint.
    • OK With client LOCAL INFILE disabled, the load failed with ERROR 2068. Running from a directory without the relative CSV file failed with ERROR 2.
    • OK -local-infile=false still emitted an absolute server-side LOAD DATA INFILE path. The default non-CSV SQL export had no CSV dependency and restored the same rows with LOCAL INFILE disabled.
    • Not covered A physical second machine or a server-side non-LOCAL restore; the cross-directory move exercises the reported local-client path boundary. Full BVT was not rerun.

    Findings

    The portable LOCAL CSV path was implemented in merged mo_dump PR #58, merge commit d9d6375512620f12ff371b8602cc1d10d6f6caa0. Relative filenames are resolved from the importing client's current working directory, so run the restore from the directory containing the CSV files or otherwise arrange the path accordingly.

    MOTR / BVT Coverage

    No MOTR case was added: this scenario requires the external mo-dump client, filesystem relocation and MySQL LOCAL INFILE, and was exercised end-to-end here. The full BVT suite was not rerun.

    Final Conclusion

    Fixed for the reported cross-directory LOCAL INFILE restore on the pinned mo_dump and MatrixOne main commits. A large-value regression is warranted because the original report included a large field and the client must transfer it; this run covered one 2 MiB value. High row counts are not needed for this path-resolution issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/compatibilitykind/compatibilitypriority/p2

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions