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 -10
View File
@@ -16,14 +16,17 @@ const stateVersion = 1
// Snapshot is the journal record of one source snapshot and its transfer
// to the target.
type Snapshot struct {
Name string `json:"name"`
CreatedAt string `json:"source_created_at"`
TargetCreatedAt string `json:"target_created_at,omitempty"`
Owned bool `json:"owned"`
Final bool `json:"final,omitempty"`
Done bool `json:"done"`
Metadata map[string]string `json:"metadata,omitempty"`
Stats *TransferStats `json:"transfer,omitempty"`
Name string `json:"name"`
CreatedAt string `json:"source_created_at"`
TargetCreatedAt string `json:"target_created_at,omitempty"`
Owned bool `json:"owned"`
Final bool `json:"final,omitempty"`
Done bool `json:"done"`
// Removed marks an owned snapshot that is deleted, or is about to be
// deleted, at source and target.
Removed bool `json:"removed,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
Stats *TransferStats `json:"transfer,omitempty"`
}
// State is the persistent migration journal. It is written atomically
@@ -73,7 +76,8 @@ func LoadState(path string) (*State, error) {
names := map[string]bool{}
for _, snap := range s.Snapshots {
if !validName(snap.Name) || names[snap.Name] || (snap.Done && (snap.CreatedAt == "" || snap.TargetCreatedAt == "")) {
if !validName(snap.Name) || names[snap.Name] || (snap.Done && (snap.CreatedAt == "" || snap.TargetCreatedAt == "")) ||
(snap.Removed && (!snap.Owned || !snap.Done)) {
return nil, errors.New("invalid snapshot state")
}
@@ -83,7 +87,7 @@ func LoadState(path string) (*State, error) {
if s.LiveSnapshot != "" {
confirmed := false
for _, snap := range s.Snapshots {
if snap.Name == s.LiveSnapshot && snap.Done {
if snap.Name == s.LiveSnapshot && snap.Done && !snap.Removed {
confirmed = true
break
}