diff --git a/README.md b/README.md index 129a850..15bfd5d 100644 --- a/README.md +++ b/README.md @@ -1,136 +1,141 @@ # migration -[English guide](docs/USAGE.md) | [简体中文](README_ZH.md) | [Deutsch](README_DE.md) | [Español](README_ES.md) | [Français](README_FR.md) | [日本語](README_JA.md) | [한국어](README_KO.md) | [Português](README_PT.md) | [Русский](README_RU.md) +**English** | [简体中文](README_ZH.md) | [Deutsch](README_DE.md) | [Español](README_ES.md) | [Français](README_FR.md) | [日本語](README_JA.md) | [한국어](README_KO.md) | [Português](README_PT.md) | [Русский](README_RU.md) -在两个 S3 兼容集群之间执行可恢复的单向对象迁移。源端必须在迁移和验收期间冻结写入与删除;目标端必须支持 `PutObject` 和 `CompleteMultipartUpload` 的原子 `If-None-Match: *` 条件写。 +`migration` copies current objects from one S3-compatible cluster to another. In the configuration, `old` is the source and `new` is the destination. The tool tracks progress in local SQLite files and retries at the object level. -迁移不调用 DeleteObject 或 CopyObject。已有目标只在两端内容 SHA-256 一致时记为完成,否则报告冲突;不会主动覆盖冲突对象。此保证依赖目标端正确实现 S3 条件写语义,部署前必须验证对应服务版本。**不支持未经协调的在线双端删除**。迁移清单对象在目标端的业务删除也必须暂停或通过删除墓碑协调;仅禁止旧集群删除不能阻止历史对象被重新写入目标。客户端无法在两个独立集群之间建立原子删除事务。 +**Freeze source writes and deletes externally before scanning and keep them frozen through final verification and cutover.** This includes lifecycle deletion. Pause business deletion of inventory keys on the target as well, or coordinate it through reliable tombstones. The tool cannot provide an atomic delete transaction across clusters. `--source-frozen` is an operator assertion; it does not freeze S3. -中文手册:[docs/使用手册.md](docs/使用手册.md) · English guide: [docs/USAGE.md](docs/USAGE.md) · Design: [docs/DESIGN.md](docs/DESIGN.md) +The destination must honor atomic `If-None-Match: *` on both `PutObject` and `CompleteMultipartUpload`. Verify that the actual server version supports these conditions. The tool does not call DeleteObject or CopyObject. Existing target objects are marked done only when their full content SHA-256 and preserved metadata match; otherwise they remain conflicts. This safety guarantee depends on the destination implementing conditional writes correctly. -## 构建 +## Documentation -```sh -go build -o bin/migration . -# 或 make build -``` +[Command reference](docs/USAGE.md) · [Operator handbook (Chinese)](docs/使用手册.md) · [Design](docs/DESIGN.md) · [Historical audit](docs/AUDIT-2026-10-29.md) · [Fix validation](docs/FIXES-2026-10-29.md) -需要 Go 1.26 或更高版本;go.mod 指定已修补的 `go1.26.10` 工具链。SQLite 为纯 Go 实现,不需要 CGO。 +The translated READMEs are historical and may contain outdated details; follow this README and the command reference for the current safety contract. -## 安全使用 +## Quick start -1. 在应用、权限策略或存储快照层冻结源桶的写入和删除,包括生命周期删除,保持到最终验收完成。 -2. 为每次迁移使用独立状态目录;确认目标实现原子条件写,配置两端地址、区域和最小必要权限。 -3. 执行 `run --source-frozen`;该参数只是确认外部已冻结源端,**不会自动冻结 S3**。 -4. 检查失败、冲突和跳过记录,执行 `diff` 完整读回校验,再按业务切换方案处理流量。 +Build with Go 1.26 or later; `go.mod` selects the patched `go1.26.10` toolchain. SQLite uses a pure Go implementation and does not require CGO. ```sh +git clone https://github.com/rustfs/migration.git +cd migration +CGO_ENABLED=0 go build -o bin/migration . +# or: make build cp config.example.yaml config.yaml -# 编辑 endpoint/凭证/独立 db_path,并在应用或存储端冻结源写入及删除 -./bin/migration list -c config.yaml -./bin/migration run -c config.yaml --source-frozen --workers 16 --rate-limit 20M +``` + +Edit the endpoints, credentials and independent state directory in `config.yaml`. Freeze source writes and deletes externally and coordinate target deletes before proceeding. + +```sh +./bin/migration list -c config.yaml +./bin/migration run -c config.yaml --source-frozen --workers 16 --rate-limit 20M ./bin/migration status -c config.yaml -./bin/migration diff -c config.yaml +./bin/migration diff -c config.yaml ``` -最小配置: +Review failures, conflicts and skipped objects, run `diff` while both sides are stable, and follow your application's cutover plan. A successful `run` alone does not certify that every object was migrated. + +Leave `bucket` empty to select every source bucket; set it or use `--bucket photos` to select one. Explicit `--bucket ""` selects all buckets even when YAML or `BUCKET` specifies one. + +## Install + +Choose the archive for your platform under **Artifacts** in a successful [Build packages run](https://github.com/rustfs/migration/actions/workflows/packages.yml). Verify the archive against its included SHA-256 digest before extracting it. Linux packages use `.tar.gz` (amd64 or arm64); Windows uses `.zip` (amd64) and the executable is `migration.exe`. + +Protect configuration credentials and state files. The process logs endpoints and object keys; endpoint URLs cannot contain credentials, query strings or fragments. Use HTTPS across untrusted networks. + +## Configuration ```yaml -old: +old: # source, read-only endpoint: https://old.example.com access_key: OLD_AK secret_key: OLD_SK region: us-east-1 -new: +new: # target, read and write endpoint: https://new.example.com access_key: NEW_AK secret_key: NEW_SK region: us-east-1 -bucket: photos # 空表示所有源桶;未知 YAML 字段会报错 -source_frozen: false # 已在外部冻结源写入/删除后才可设 true -# 每个迁移任务使用独立目录 +bucket: photos # empty selects every source bucket +source_frozen: false # set true only after freezing externally +# Use an independent directory per migration job. db_path: ./state/job-1/migration.db conflict_log: ./state/job-1/conflict.log spool_dir: ./state/job-1/spool -spool_max_bytes: 1073741824 +spool_max_bytes: 1073741824 # 1 GiB per migration task workers: 16 -multipart_threshold: 52428800 -multipart_part_size: 16777216 +multipart_threshold: 52428800 # 50 MiB +multipart_part_size: 16777216 # 16 MiB multipart_concurrency: 4 -rate_limit: 0 +rate_limit: 0 # unlimited source reads ``` -YAML、环境变量、命令行优先级:CLI > 环境变量 > YAML > 默认值。`source_frozen` 可由 `SOURCE_FROZEN=true` 或 `--source-frozen` 覆盖。两端支持 `session_token`,环境变量为 `OLD_SESSION_TOKEN` / `NEW_SESSION_TOKEN`。 +Unknown YAML fields are rejected. Configuration precedence is CLI > environment > YAML > defaults. `source_frozen` can also be set with `SOURCE_FROZEN=true` or `--source-frozen`. Both endpoints support `session_token` for temporary credentials, with `OLD_SESSION_TOKEN` and `NEW_SESSION_TOKEN` environment overrides. -其他环境变量:`OLD_ENDPOINT` `OLD_AK` `OLD_SK` `OLD_REGION`,`NEW_ENDPOINT` `NEW_AK` `NEW_SK` `NEW_REGION`,`REGION`,`BUCKET` `DB_PATH` `CONFLICT_LOG` `SPOOL_DIR` `WORKERS` `MULTIPART_CONCURRENCY` `RATE_LIMIT`。 +Other environment overrides are `OLD_ENDPOINT`, `OLD_AK`, `OLD_SK`, `OLD_REGION`, `NEW_ENDPOINT`, `NEW_AK`, `NEW_SK`, `NEW_REGION`, `REGION`, `BUCKET`, `DB_PATH`, `CONFLICT_LOG`, `SPOOL_DIR`, `WORKERS`, `MULTIPART_CONCURRENCY` and `RATE_LIMIT`. The destination account needs `s3:CreateBucket` if the tool must create a bucket. `list` and `scan` require the source endpoint; `run`, `migrate` and `diff` require both endpoints. -## 命令和退出状态 +## Commands and exit status -| 命令 | 行为 | 目标写入 | +| Command | Behavior | Writes to target | | --- | --- | --- | -| list | 列出源桶 | 无 | -| scan | 完整扫描源清单到 SQLite | 无 | -| run | 扫描完成后迁移 | 条件创建对象和必要的桶 | -| migrate | 使用已有完整清单重试 pending/failed | 条件创建对象和必要的桶 | -| status | 只读本地状态,不创建缺失 DB | 无 | -| diff | 检查两端桶,并完整读取等尺寸对象计算 SHA-256 | 无 | -| diff --extra | 另外报告仅目标存在的 key | 无 | +| `list` | List source buckets | No | +| `scan` | Scan the complete source inventory into SQLite | No | +| `run` | Scan, then migrate | Conditionally creates objects and required buckets | +| `migrate` | Retry pending/failed objects from a completed scan | Conditionally creates objects and required buckets | +| `status` | Read local state without creating a missing database | No | +| `diff` | Verify buckets, size, preserved metadata and full-body SHA-256 | No | +| `diff --extra` | Also report target-only keys | No | -`run` / `migrate` 未确认 source_frozen 时拒绝执行。对象传输失败、取消、持久化失败、未完成扫描和状态读取错误都返回非零退出码。`diff` 对缺失、大小差异、SHA-256 差异或无法验证返回失败;`--extra` 报告的目标独有对象允许存在,不单独令命令失败。 +`run` and `migrate` reject execution without the source-freeze assertion. Transfer failures, cancellation, persistence failures, incomplete scans and state-read errors return nonzero. `diff` returns nonzero for missing, mismatched or unverifiable objects. With `--extra`, target-only keys are reported but do not independently cause failure. -conflict 表示保留目标现有数据,skipped 表示源返回明确 NoSuchKey;它们需要操作员审核,不能仅凭 `run` 退出 0 判定全部数据已迁移。未做完整扫描的 `migrate` 不再当作空任务成功。 +A conflict preserves an existing target object; skipped means the source returned a definite `NoSuchKey`. Both require review, even when `run` exits 0. For an automated gate, `run --strict` and `migrate --strict` return nonzero if the state contains pending, failed, conflict or skipped objects, including results from prior runs. `diff --strict` also reports and fails on target-only keys. Strict mode does not replace a freeze window and final content verification. -自动化验收可使用 `run --strict` 或 `migrate --strict`:只要状态库中仍有 pending、failed、conflict 或 skipped,命令就返回非零,包括前次运行遗留的状态。`diff --strict` 同时检查目标独有对象,并在发现时返回非零。严格模式仍不能代替冻结窗口和最终内容验收。 +`diff --issues-jsonl /path/to/new-file.jsonl` streams every issue as JSON Lines with `bucket`, `key`, `kind` and `detail`. Existing files are not overwritten. Add `--extra` or `--strict` to include target-only keys. On interruption or error the file may be incomplete; check the command result before using it for acceptance. -`diff --issues-jsonl /path/to/new-file.jsonl` 将全部差异逐条写入新文件,字段为 bucket、key、kind 和 detail;文件已存在时拒绝覆盖。目标独有 key 需要同时使用 `--extra` 或 `--strict` 才会记录。任务出错或中断时文件可能只包含部分结果,必须结合命令退出状态判断是否完整。 +## Integrity and recovery -## 完整性与恢复 +- The inventory records source size, ETag and modification time. Reads use If-Match and an available VersionId to pin the representation. ETags are conditional-read tokens, not assumed to be MD5 checksums. +- Small objects spool to disk; large objects use bounded range reads with Content-Range, ETag and exact-length checks. Each part also spools to disk. +- New objects are read back from the target and checked against SHA-256. Existing same-size objects are fully read on both sides; equal size or a multipart ETag alone does not establish equality. Preserved headers and user metadata are also compared. +- A normal single-object copy reads the source once and the target once. Multipart copies read the source approximately twice and the target once to verify the assembled object. Source digest reads are included in the rate limit. +- SQLite state binds the source and target endpoints and bucket. Do not reuse a database with different endpoints or repoint an endpoint to a different cluster or account. A scan generation records completion; an interrupted rescan invalidates that certificate. +- Legacy unbound state with processed rows is rejected. Use a new state directory and rescan after upgrading; existing target objects will be fully verified without deleting them. +- A single-writer lock prevents simultaneous processes using the same state database; read-only `status` can run concurrently. Keep the `.db`, `-wal`, `-shm` and `.lock` files intact during a job. In all-bucket mode `job-a.db` derives names such as `job-a-photos.db`. +- A changed source identity re-enters validation; the tool does not overwrite an existing target and is not a continuous synchronization system. -- 清单记录源大小、ETag 和时间;迁移重新检查源身份,并用 If-Match 和可用的 VersionId 固定读取。ETag 是并发条件,不被当作通用 MD5。 -- 小对象先落临时文件;大对象按范围读取并校验 Content-Range、ETag 和精确长度,每片也落临时文件,避免将整个分片保留在内存。 -- 新对象提交后从目标读回并比较 SHA-256。已有同尺寸目标也完整读取两端校验,不再把 multipart ETag 或缺失 ETag 降级为“大小一致即完成”。 -- 分片对象额外顺序读取一遍源以计算完整摘要。单对象正常复制约读取源一遍、目标一遍;分片复制约读取源两遍、目标一遍。源摘要读取也受 rate-limit 限制。 -- SQLite 绑定源/目标 endpoint 和 bucket;不允许更换 endpoint 复用清单。扫描记录 generation,中断扫描使完成凭证失效。 -- 有已处理记录而无身份的旧库拒绝自动接管。升级时使用新状态目录重新扫描;已有目标将重新完整验证,无须删除目标对象。 -- 单写者锁拒绝多进程同时使用同一个状态库;只读 status 可以并行运行。保留 `.db`、`-wal`、`-shm` 及 `.lock` 文件,不要在任务运行时手工删除锁文件。 -- 全桶模式保留任务文件名:`job-a.db` 派生 `job-a-photos.db`,不会和 `job-b.db` 的桶清单混用。 -- 源同 key 的身份变化会重新进入待验证状态;已有目标仍不被覆盖。这不是持续同步工具。 +Recovery retries whole objects, not individual parts. A forced termination can leave unfinished multipart uploads on the server; configure a lifecycle rule to clean them up. Do not treat an old verification as valid after allowing data to change. -恢复是对象级重试。kill -9 后未完成分片可能留在服务端,应配置清理未完成分片的生命周期;工具不持久化分片 uploadId。不能在最后一次校验后允许数据任意变化、再把旧校验当成切换依据。 +## Concurrency, rate and disk limits -## 并发与限速 +`workers` defaults to 16 and controls concurrent objects; `multipart_concurrency` defaults to 4 and controls concurrent parts per object. Their limits are 1024 and 64 respectively, with a product limit of 4096. Do not use these maxima as production defaults. Scan is single-threaded. -`workers` 默认 16,控制同时处理的对象;`multipart_concurrency` 默认 4,控制单个大对象分片数。workers 上限 1024,分片并发上限 64,乘积上限 4096。不要用最大值作为生产默认。 +`rate_limit` caps aggregate source-body reads for `run` and `migrate`, including the multipart digest pass. It does not limit target uploads or readback, or `diff`. `20M` / `20MB` means 20,000,000 B/s; `20MiB` means 20 × 1024 × 1024 B/s; `0` means unlimited. `diff` reads both full bodies for equal-sized objects, so plan for the bandwidth and read load. -`rate_limit` 是 run/migrate 的所有源正文读取共享速率,不限制目标上传/读回,也不限制 diff。`20M` / `20MB` 为 20,000,000 B/s;`20MiB` 为 20×1024×1024 B/s;`0` 为不限速。**diff 会完整读取两端数据**,需要安排网络和读负载窗口。 +Parts range from 5 MiB to 5 GiB. The tool may increase part size to stay within 10,000 parts and rejects objects that exceed the multipart limits. `spool_max_bytes` defaults to 1 GiB and limits concurrent temporary-file reservations within one migration, including one extra byte per file for length checks. A single object or part larger than the budget fails: increase the budget or reduce the part size or threshold. -分片大小为 5MiB 到 5GiB;工具可为超过 10,000 片的对象增大片大小,并拒绝超出分片限制的对象。`spool_max_bytes` 默认 1 GiB,限制当前迁移任务并发临时文件预留总量(含每个文件用于检测超长正文的 1 字节);超过预算的单个对象或分片会失败,需提高预算或降低分片大小/分片阈值。该限制不包含异常退出遗留文件、其他进程和目录内容,也不保证磁盘剩余空间。独立目录中断后确认没有运行中的任务,再人工清理残留文件;监控磁盘并使用目标端分片生命周期清理。 +The budget does not include files left by crashes, other processes or other directory contents, and does not guarantee free disk space. Use a dedicated spool directory and monitor disk capacity. After confirming no job is active, manually remove stale temporary files. The client uses HTTP/1 with a 30-second response-header timeout and a 90-second timeout for an individual blocked body read or connection write; rate-limit waits between reads do not trigger that timeout. -客户端使用 HTTP/1,响应头等待上限 30 秒,单次阻塞正文读取和连接写入上限 90 秒;限速造成的两次读取之间等待不会触发该超时。网络失败按失败对象保留以便重试。 +## Scope -## 能力边界 +The tool migrates current object contents, common content headers and user metadata. It does not copy version history, delete markers, bucket policies, lifecycle rules, object tags, ACLs, storage class, Object Lock, retention/legal hold or source SSE configuration. The target's default encryption policy still applies. Workloads that depend on these features need a separate migration plan. -迁移当前对象内容、常见内容头和用户 metadata。不会复制版本历史、删除标记、桶策略、生命周期、对象 tags、ACL、Object Lock/retention/legal hold、存储等级或源 SSE 配置。目标自身默认加密策略仍生效。使用这些功能的业务需要独立迁移方案,不应直接以本工具完成桶级功能迁移。 +A destination that does not support conditional writes, cannot provide stable object identities or cannot serve readback is not suitable for reliable migration with this tool. Do not bypass verification with size-only comparison. -目标端不支持条件写、无法返回稳定对象身份、或不能读回内容时不得作为可靠迁移目标。不要通过取消 checksum 校验或改成只比较大小绕过问题。 - -## 测试 +## Testing ```sh go test ./... go test -race ./... go vet ./... -# 可选:显式选择 RustFS 1.0.4 二进制,启动两个临时回环实例 +# Optional: start two temporary loopback instances with the specified RustFS binary. python3 scripts/audit-local-rustfs.py \ --rustfs-binary /absolute/path/rustfs --expect-version 1.0.4 ``` -将 `/absolute/path/rustfs` 替换为待测二进制的绝对路径。启动器先执行该文件的 `--version`,版本必须与 `1.0.4` 精确一致,否则在启动实例前退出;不会从 PATH 自动选择另一个 RustFS。它记录二进制路径、版本输出和 SHA-256,使用同一文件启动两个临时回环实例,结束后清理进程与临时数据。默认证据目录为 `audit-results/rustfs-1.0.4/`,其中 `rustfs-binary.json` 标识实际受测二进制;可用 `--output-dir` 指定其他目录。 - -审计发现的确定性场景现已纳入默认回归测试,不再需要 audit build tag。`real_s3` 测试保持独立,必须实际执行后才能得出对应服务版本的结论。旧 RustFS `1.0.0-alpha.61` 的分片 ETag 失败仅保留为历史记录,不能当作 `1.0.4` 的通过或失败结果;上线前应对拟部署版本运行真实服务测试。 - -历史审计:[2026-10-29 审计](docs/AUDIT-2026-10-29.md)。修复验证结果见 [修复记录](docs/FIXES-2026-10-29.md)。 +The launcher checks that the specified executable reports the expected version, records its path, version and SHA-256, and stops the temporary instances and removes their data afterward. It does not choose another executable from PATH. The default evidence directory is `audit-results/rustfs-1.0.4/`; `--output-dir` selects another location. Real-service results apply only to the version actually tested; validate the server versions intended for deployment. -## English summary +## License -This is a resumable one-way migration tool for a **frozen source**. Freeze source writes and deletes externally, then acknowledge with `--source-frozen`. The destination must implement atomic `If-None-Match: *` for both PutObject and CompleteMultipartUpload. Existing objects are read and compared with full SHA-256; mismatches remain conflicts. Copy failures and cancellation return errors. `diff` reads full bodies on both clusters and requires GetObject permissions and bandwidth. See the [English guide](docs/USAGE.md) for migration and upgrade steps. +Licensed under the [Apache License 2.0](LICENSE).