The native libcephfs backend is the only transfer path. The rsync transport, the mounted-filesystem access and its helpers (mount check, path resolution below a mount, mount claim, quota and hardlink repair through the mount) are removed, together with the rsync lab test and the client image that only added rsync. The claim and release tests now exercise the native claim through a local test file system with real flock locks. BREAKING CHANGE: "backend": "rsync" and the endpoint field "mount" are rejected. "backend" is optional and only accepts "native"; jobs created with "native" resume without it. Journals of rsync jobs cannot be resumed. Builds without the build tag ceph only support doctor and status. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
179 lines
4.3 KiB
Go
179 lines
4.3 KiB
Go
// Command cephmig migrates a CephFS subvolume, including its snapshots,
|
|
// between two Ceph clusters while the application keeps running.
|
|
//
|
|
// Usage:
|
|
//
|
|
// 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
|
|
//
|
|
// 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. 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 (
|
|
"context"
|
|
"encoding/json"
|
|
"errors"
|
|
"flag"
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
"os/exec"
|
|
"os/signal"
|
|
"syscall"
|
|
"time"
|
|
|
|
"git.zb-server.de/Sebi/CephfsMig/internal/migration"
|
|
)
|
|
|
|
func main() {
|
|
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
|
defer stop()
|
|
if err := run(ctx, os.Args[1:], os.Stdout, os.Stderr); err != nil {
|
|
fmt.Fprintln(os.Stderr, "cephmig:", err)
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
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 {
|
|
return errors.New(usage)
|
|
}
|
|
|
|
if args[0] == "help" || args[0] == "--help" || args[0] == "-h" {
|
|
fmt.Fprintln(out, usage)
|
|
return nil
|
|
}
|
|
|
|
if args[0] == "doctor" {
|
|
if len(args) != 1 {
|
|
return errors.New(usage)
|
|
}
|
|
|
|
return doctor(ctx, out, log)
|
|
}
|
|
|
|
switch args[0] {
|
|
case "inspect", "sync", "finalize", "cleanup", "status":
|
|
default:
|
|
return errors.New(usage)
|
|
}
|
|
|
|
flags := flag.NewFlagSet(args[0], flag.ContinueOnError)
|
|
flags.SetOutput(log)
|
|
configPath := flags.String("config", "", "JSON migration configuration")
|
|
statePath := flags.String("state", "", "persistent state file on local disk")
|
|
stopped := flags.Bool("writers-stopped", false, "confirm ALL source writers are stopped; keep them stopped until cutover completes")
|
|
if err := flags.Parse(args[1:]); err != nil {
|
|
if errors.Is(err, flag.ErrHelp) {
|
|
return nil
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
if flags.NArg() != 0 {
|
|
return errors.New("unexpected positional arguments")
|
|
}
|
|
|
|
if args[0] == "status" {
|
|
if *statePath == "" {
|
|
return errors.New("--state is required")
|
|
}
|
|
|
|
s, err := migration.LoadState(*statePath)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return json.NewEncoder(out).Encode(s)
|
|
}
|
|
|
|
if *configPath == "" {
|
|
return errors.New("--config is required")
|
|
}
|
|
|
|
c, err := migration.ReadConfig(*configPath)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
process := migration.Process{Stderr: log}
|
|
if args[0] != "inspect" && *statePath == "" {
|
|
return errors.New("--state is required")
|
|
}
|
|
|
|
if args[0] == "finalize" && !*stopped {
|
|
return errors.New("finalize requires --writers-stopped; stop and flush all application writers first")
|
|
}
|
|
|
|
if args[0] != "finalize" && *stopped {
|
|
return errors.New("--writers-stopped is only valid with finalize")
|
|
}
|
|
|
|
engine, closeEngine, err := migration.NewEngine(ctx, c, process, log)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
defer closeEngine.Close()
|
|
if args[0] == "inspect" {
|
|
info, err := engine.Inspect(ctx, c)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return json.NewEncoder(out).Encode(info)
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
s, err := migration.LoadState(*statePath)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return json.NewEncoder(out).Encode(s)
|
|
}
|
|
|
|
func doctor(ctx context.Context, out, log io.Writer) error {
|
|
checks := []struct {
|
|
name string
|
|
args []string
|
|
}{
|
|
{"go", []string{"version"}},
|
|
{"docker", []string{"compose", "version"}},
|
|
{"docker", []string{"info", "--format", "Docker server: {{.ServerVersion}}"}},
|
|
}
|
|
|
|
for _, check := range checks {
|
|
checkCtx, cancel := context.WithTimeout(ctx, 15*time.Second)
|
|
cmd := exec.CommandContext(checkCtx, check.name, check.args...)
|
|
cmd.Stdout, cmd.Stderr = out, log
|
|
err := cmd.Run()
|
|
cancel()
|
|
if err != nil {
|
|
return fmt.Errorf("check %s: %w", check.name, err)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|