feat: remove cephmig snapshots during sync and add cleanup command

Users of a subvolume should not see traces of the migration. Each sync
round now deletes the older cephmig-* round snapshots at source and
target and keeps only the newest one as base for the next round. The new
command `cephmig cleanup` deletes the remaining one after the cutover.
Application snapshots are never touched.

The journal marks a snapshot as removed before deleting it, so an
interrupted run finishes the deletion instead of reporting a vanished
snapshot.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-12-03 19:52:13 +01:00
1 parent cc2dff46a0
commit 907d400765
9 files changed
+322 -19

No files matched your search

+14 -6
View File
@@ -7,12 +7,15 @@
// 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
//
// inspect checks both clusters without changing them. sync copies the
// current state and may be repeated. finalize performs the last round after
// all writers are stopped and marks the job ready for cutover. status prints
// the migration journal. All results are written to standard output as JSON.
// all writers are stopped and marks the job ready for cutover. cleanup
// deletes the snapshots cephmig created, at source and target, once the
// cutover is done. status prints the migration journal. All results are
// written to standard output as JSON.
package main
import (
@@ -40,7 +43,7 @@ func main() {
}
}
const usage = "usage: cephmig doctor | inspect --config FILE | sync --config FILE --state FILE | finalize --config FILE --state FILE --writers-stopped | status --state FILE"
const usage = "usage: cephmig doctor | inspect --config FILE | sync --config FILE --state FILE | finalize --config FILE --state FILE --writers-stopped | cleanup --config FILE --state FILE | status --state FILE"
func run(ctx context.Context, args []string, out, log io.Writer) error {
if len(args) == 0 {
@@ -61,7 +64,7 @@ func run(ctx context.Context, args []string, out, log io.Writer) error {
}
switch args[0] {
case "inspect", "sync", "finalize", "status":
case "inspect", "sync", "finalize", "cleanup", "status":
default:
return errors.New(usage)
}
@@ -118,7 +121,7 @@ func run(ctx context.Context, args []string, out, log io.Writer) error {
return errors.New("--writers-stopped is only valid with finalize")
}
if c.Backend != "native" && args[0] != "inspect" {
if c.Backend != "native" && args[0] != "inspect" && args[0] != "cleanup" {
if _, err = exec.LookPath("rsync"); err != nil {
return fmt.Errorf("rsync is required: %w", err)
}
@@ -139,7 +142,12 @@ func run(ctx context.Context, args []string, out, log io.Writer) error {
return json.NewEncoder(out).Encode(info)
}
if err = engine.Sync(ctx, c, *statePath, args[0] == "finalize"); err != nil {
if args[0] == "cleanup" {
err = engine.Cleanup(ctx, c, *statePath)
} else {
err = engine.Sync(ctx, c, *statePath, args[0] == "finalize")
}
if err != nil {
return err
}
+1 -1
View File
@@ -25,7 +25,7 @@ func TestCLIUsage(t *testing.T) {
t.Fatal("help missing")
}
for _, args := range [][]string{nil, {"unknown"}, {"sync"}, {"status"}, {"sync", "--config", "x", "extra"}} {
for _, args := range [][]string{nil, {"unknown"}, {"sync"}, {"status"}, {"cleanup"}, {"cleanup", "--config", "../../dev/migration.example.json"}, {"sync", "--config", "x", "extra"}} {
if err := run(context.Background(), args, &out, &log); err == nil {
t.Fatalf("accepted %v", args)
}