Do not prune when a backup misses an earlier mount point (closes #395)
check / check (push) Waiting to run
check / check (push) Waiting to run
snapshot create --prune purged the older snapshots holding a volume's files when the volume, mounted below a configured path, was not mounted: its empty mount point read as deleted files. The scan now records in the local index each directory at or below a configured path that is on a different device from its parent directory. Under --prune, when an earlier snapshot of that name recorded such a directory and this run does not find it on a different device, the run skips the prune, keeps every older snapshot, names the directory and exits non-zero, as for an empty configured path. For a volume retired, or a directory no longer backed up, on purpose, the older snapshots are removed with snapshot purge. Model: opus-5-5
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
"slices"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -422,3 +423,52 @@ func TestSnapshotRepositoryDuplicate(t *testing.T) {
|
||||
t.Error("expected error for duplicate snapshot")
|
||||
}
|
||||
}
|
||||
|
||||
// Deleting a snapshot from the local index deletes the mount points its
|
||||
// backup recorded, and no other snapshot's. See
|
||||
// https://git.eeqj.de/sneak/vaultik/issues/395.
|
||||
func TestSnapshotRepositoryDeleteRemovesMountPoints(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
db, cleanup := setupTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
ctx := context.Background()
|
||||
repo := database.NewSnapshotRepository(db)
|
||||
|
||||
for _, id := range []types.SnapshotID{"kept", "deleted"} {
|
||||
err := repo.Create(ctx, nil, &database.Snapshot{
|
||||
ID: id,
|
||||
Hostname: testHostname,
|
||||
VaultikVersion: testVersion,
|
||||
StartedAt: time.Now().Truncate(time.Second),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create snapshot: %v", err)
|
||||
}
|
||||
|
||||
err = repo.AddMountPoint(ctx, nil, id.String(), "/data/nas")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to add mount point: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
err := repo.Delete(ctx, "deleted")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to delete snapshot: %v", err)
|
||||
}
|
||||
|
||||
for id, want := range map[string][]string{
|
||||
"kept": {"/data/nas"},
|
||||
"deleted": nil,
|
||||
} {
|
||||
got, err := repo.GetMountPoints(ctx, id)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to read mount points: %v", err)
|
||||
}
|
||||
|
||||
if !slices.Equal(got, want) {
|
||||
t.Errorf("mount points of %s: got %v, want %v", id, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user