cleanup now deletes the claim file under .cephmig/claims as its last step, if it holds the job's own ID, and removes the claim directories when they are empty. A cleaned-up job is finished: cleanup and finalize do nothing and do not claim the target again, and sync is refused. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
237 lines
9.1 KiB
Markdown
237 lines
9.1 KiB
Markdown
# CephMig: migrate CephFS subvolumes between Ceph clusters
|
|
|
|
A Go tool that copies a CephFS subvolume, including its snapshots, POSIX ACLs,
|
|
xattrs, quotas and timestamps, from one Ceph cluster to another while the
|
|
application keeps running.
|
|
|
|
## Description
|
|
|
|
**Why?** A subvolume has to move to a new cluster with only a short write
|
|
stop. The target size is up to 200 TB and more than 200 million files. A
|
|
plain copy is not enough: snapshots, hardlinks and Ceph metadata must be
|
|
preserved, and an interrupted run must be resumable.
|
|
|
|
**How?** CephMig works in rounds. Each round transfers a consistent source
|
|
snapshot, verifies the target and creates a snapshot of the same name there.
|
|
A journal on local disk records every step. For the last round, all writers
|
|
are stopped briefly.
|
|
|
|
There are two backends:
|
|
|
|
- **native** (recommended): the copier talks to both clusters directly
|
|
through libcephfs. It needs neither rsync nor a kernel or FUSE mount.
|
|
After the initial transfer it uses snapdiff and, where possible, blockdiff.
|
|
- **rsync**: copies between two mounted CephFS file systems.
|
|
|
|
**Status:** prototype. The features are verified in the local lab. Load
|
|
tests at the target size and a production cutover are still missing.
|
|
|
|
> **Documented deviations:** native snapshot IDs and snapshot creation times
|
|
> are assigned anew at the target. The native backend takes mtime, atime,
|
|
> ctime and birth time (btime) of every file from the source; the ctime is
|
|
> never lower than the mtime. The original snapshot creation times are kept
|
|
> in the journal.
|
|
> Details: [docs/migration.md](docs/migration.md).
|
|
|
|
## Installation
|
|
|
|
Requirements:
|
|
|
|
- Linux, Go 1.25 or later and GNU Make
|
|
- for the native backend and the lab: Docker Engine with Docker Compose and
|
|
`/dev/fuse` on the Docker host
|
|
- for the lab: up to 12 GiB RAM for the containers and about 8 GiB of disk
|
|
space for the two OSDs, plus space for the images
|
|
|
|
Get the source and build it:
|
|
|
|
```sh
|
|
git clone ssh://git@git.zb-server.de:30022/Sebi/CephfsMig.git
|
|
cd CephfsMig
|
|
make doctor # checks Go, Docker and Docker Compose
|
|
make build # builds bin/cephmig (rsync backend only)
|
|
make check # go vet, Go tests and a syntax check of the test scripts
|
|
```
|
|
|
|
The native backend needs CGO and the libcephfs headers, so it is built in a
|
|
container. The build also runs the Go tests with the race detector:
|
|
|
|
```sh
|
|
make dev-native-build # builds the image cephmig-native:dev
|
|
```
|
|
|
|
## Usage
|
|
|
|
```text
|
|
cephmig doctor
|
|
cephmig inspect --config FILE
|
|
cephmig sync --config FILE --state FILE
|
|
cephmig finalize --config FILE --state FILE --writers-stopped
|
|
cephmig cleanup --config FILE --state FILE
|
|
cephmig status --state FILE
|
|
```
|
|
|
|
| Command | Effect |
|
|
|------------|----------------------------------------------------------------------|
|
|
| `inspect` | checks source and target without changing anything |
|
|
| `sync` | transfers the current state; can be repeated any number of times |
|
|
| `finalize` | last round after the write stop, then ready for cutover |
|
|
| `cleanup` | deletes the snapshots cephmig created and its claim on the target |
|
|
| `status` | prints the journal |
|
|
|
|
All results are written to standard output as JSON. The state file must be
|
|
outside the CephFS mounts.
|
|
|
|
Steps of a migration:
|
|
|
|
1. Check source, target, permissions and capacity with `inspect`.
|
|
2. Make the initial copy with `sync` while the application keeps running.
|
|
3. Repeat `sync` to catch up with changes.
|
|
4. Stop all writing applications, then run `finalize --writers-stopped`.
|
|
5. Switch the clients to the target and release the applications.
|
|
6. Once the cutover is checked, remove the migration snapshots with `cleanup`.
|
|
|
|
A file system snapshot does not make a database application-consistent. The
|
|
write stop must cover all clients.
|
|
|
|
```mermaid
|
|
sequenceDiagram
|
|
actor Op as Operator
|
|
participant M as cephmig
|
|
participant S as Source cluster
|
|
participant T as Target cluster
|
|
|
|
Op->>M: inspect
|
|
M->>S: check subvolume
|
|
M->>T: check subvolume
|
|
loop sync, repeated while the application runs
|
|
Op->>M: sync
|
|
M->>S: create round snapshot
|
|
M->>T: copy changes, verify
|
|
M->>T: create round snapshot
|
|
M->>S: remove previous round snapshot
|
|
M->>T: remove previous round snapshot
|
|
end
|
|
Note over Op,S: stop all writers
|
|
Op->>M: finalize --writers-stopped
|
|
M->>S: create final snapshot
|
|
M->>T: copy, full verification, create final snapshot
|
|
M-->>Op: ready-for-cutover
|
|
Note over Op,T: switch clients to the target
|
|
Op->>M: cleanup
|
|
M->>S: remove final snapshot
|
|
M->>T: remove final snapshot
|
|
```
|
|
|
|
The detailed sequence is in [docs/migration.md](docs/migration.md#workflow-in-detail).
|
|
|
|
Intermediate `sync` rounds skip subtrees whose recursive change time
|
|
(`ceph.dir.rctime`) did not change, so a round reads only the changed parts.
|
|
`finalize` always reads everything.
|
|
|
|
Each round creates a snapshot `cephmig-<job>-<round>` at source and target;
|
|
`sync` deletes the older ones as soon as a newer round is complete. Users of
|
|
the subvolume therefore see at most one such snapshot during the migration,
|
|
and none after `cleanup`. Application snapshots are never deleted.
|
|
|
|
The configuration is a JSON file, here
|
|
[dev/migration.example.json](dev/migration.example.json) from the lab:
|
|
|
|
```json
|
|
{
|
|
"backend": "native",
|
|
"source": {
|
|
"config": "/clusters/source/ceph.conf",
|
|
"keyring": "/clusters/source/ceph.client.admin.keyring",
|
|
"filesystem": "cephfs",
|
|
"group": "migration",
|
|
"subvolume": "demo",
|
|
"mount": "/mnt/source-fs"
|
|
},
|
|
"target": {
|
|
"config": "/clusters/target/ceph.conf",
|
|
"keyring": "/clusters/target/ceph.client.admin.keyring",
|
|
"filesystem": "cephfs",
|
|
"group": "migration",
|
|
"subvolume": "demo",
|
|
"mount": "/mnt/target-fs"
|
|
},
|
|
"bandwidth_kib": 0
|
|
}
|
|
```
|
|
|
|
Optional fields are `user` (Ceph client identity, e.g. `client.migration`),
|
|
`workers` (0 to 64; 0 selects the default) and `full_scan` (`true` makes
|
|
every round read all metadata instead of skipping unchanged subtrees). `mount` is only needed for
|
|
the rsync backend: the mount of the file system root.
|
|
|
|
## Examples
|
|
|
|
The lab starts two independent Ceph clusters (Ceph 21.2.0) in Docker and runs
|
|
the migration between them:
|
|
|
|
```sh
|
|
make dev-up # start the clusters
|
|
make dev-status # state of both clusters
|
|
make dev-smoke # smoke test: snapshot, ACLs, xattrs, hardlinks, quotas
|
|
make dev-native-test # native functional test
|
|
docker compose -f dev/compose.yaml exec native cephmig-native inspect \
|
|
--config /lab/migration.example.json
|
|
make dev-down # stop; the data is kept
|
|
```
|
|
|
|
More tests:
|
|
|
|
| Target | Content |
|
|
|----------------------------|-----------------------------------------------------------|
|
|
| `make dev-migration-test` | migration with the rsync backend |
|
|
| `make dev-smallfiles-test` | 10,000 small files (`FILES=2000` limits the number) |
|
|
| `make dev-million-start` | one million files with four snapshot states |
|
|
| `make dev-restart-check` | restart of the lab; FSIDs and data are preserved |
|
|
|
|
Results of documented runs: [docs/smallfiles-local.md](docs/smallfiles-local.md)
|
|
and [docs/million-local.md](docs/million-local.md).
|
|
|
|
## Project structure
|
|
|
|
```text
|
|
.
|
|
├── cmd/
|
|
│ ├── cephmig/ command-line program
|
|
│ └── nativeprobe/ diagnostic tool for the libcephfs binding
|
|
├── internal/
|
|
│ ├── migration/ migration workflow, journal, rsync and native transfer
|
|
│ ├── storage/ file system interface of the native copier
|
|
│ └── cephfsnative/ CGO binding to libcephfs (build tag ceph)
|
|
├── dev/ lab: Compose files, Dockerfiles, test scripts
|
|
├── docs/ detailed documentation and measurements
|
|
└── Makefile build, check and lab targets
|
|
```
|
|
|
|
## Documentation
|
|
|
|
- [docs/migration.md](docs/migration.md): commands, limits and evidence
|
|
- [docs/lab.md](docs/lab.md): the lab in detail, Ceph version, known warnings
|
|
- [docs/raw-transfer.md](docs/raw-transfer.md): direct RADOS import and limits of the native implementation
|
|
- [docs/verify-concept.md](docs/verify-concept.md): concept for a full content verification after the cutover
|
|
- API documentation of the Go packages: `go doc -all ./internal/migration`
|
|
|
|
## Contributing
|
|
|
|
- Go code follows [Effective Go](https://go.dev/doc/effective_go) and is
|
|
formatted with `gofmt`. Exported identifiers have doc comments.
|
|
- Run `make check` before every commit.
|
|
- Commit messages follow [Conventional Commits 1.0.0](https://www.conventionalcommits.org/en/v1.0.0/),
|
|
for example `feat(migration): add bandwidth limit` or
|
|
`fix(native): retry on EEXIST`. Breaking changes are marked with `!` and a
|
|
`BREAKING CHANGE:` footer.
|
|
|
|
## License
|
|
|
|
No license has been chosen yet. Without a license, all rights are reserved.
|
|
|
|
## Contact
|
|
|
|
Sebastian Unterschütz. Please report questions and bugs as issues in the
|
|
repository [Sebi/CephfsMig](https://git.zb-server.de/Sebi/CephfsMig).
|