Do not prune when a backup misses an earlier mount point (closes #395)
check / check (push) Canceled after 0s
check / check (push) Canceled after 0s
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 holds an entry and is on a different device from its parent directory, looked up once the walk has listed it, as listing mounts an automounted volume. Under --prune, when an earlier snapshot of that name recorded such a directory and this run does not, the run skips the prune, keeps every older snapshot and exits non-zero, naming the directory. For a volume retired on purpose, snapshot purge removes the older snapshots. Model: opus-5-5
This commit is contained in:
@@ -7,12 +7,14 @@ import (
|
||||
"database/sql"
|
||||
"io"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/afero"
|
||||
"sneak.berlin/go/vaultik/internal/config"
|
||||
"sneak.berlin/go/vaultik/internal/database"
|
||||
"sneak.berlin/go/vaultik/internal/log"
|
||||
"sneak.berlin/go/vaultik/internal/types"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -387,6 +389,77 @@ func TestCleanSnapshotDBNonExistentSnapshot(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// The exported metadata database keeps only the mount points that the
|
||||
// exported snapshot recorded. See
|
||||
// https://git.eeqj.de/sneak/vaultik/issues/395.
|
||||
func TestCleanSnapshotDBKeepsOnlyTheSnapshotsMountPoints(t *testing.T) {
|
||||
log.Initialize(log.Config{})
|
||||
t.Parallel()
|
||||
|
||||
ctx := context.Background()
|
||||
dbPath := filepath.Join(t.TempDir(), "export.db")
|
||||
|
||||
db, err := database.New(ctx, dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create database: %v", err)
|
||||
}
|
||||
|
||||
repos := database.NewRepositories(db)
|
||||
|
||||
for _, id := range []types.SnapshotID{"exported", "other"} {
|
||||
err = repos.Snapshots.Create(ctx, nil, &database.Snapshot{ID: id})
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create snapshot: %v", err)
|
||||
}
|
||||
|
||||
err = repos.Snapshots.AddMountPoint(ctx, nil, id.String(), "/data/"+id.String())
|
||||
if err != nil {
|
||||
t.Fatalf("failed to add mount point: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
err = db.Close()
|
||||
if err != nil {
|
||||
t.Fatalf("failed to close database: %v", err)
|
||||
}
|
||||
|
||||
sm := &SnapshotManager{
|
||||
config: &config.Config{
|
||||
CompressionLevel: 3,
|
||||
AgeRecipients: []string{testAgeRecipient},
|
||||
},
|
||||
fs: afero.NewOsFs(),
|
||||
}
|
||||
|
||||
_, err = sm.cleanSnapshotDB(ctx, dbPath, "exported")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to clean snapshot database: %v", err)
|
||||
}
|
||||
|
||||
cleaned, err := database.New(ctx, dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open cleaned database: %v", err)
|
||||
}
|
||||
|
||||
defer func() { _ = cleaned.Close() }()
|
||||
|
||||
cleanedRepos := database.NewRepositories(cleaned)
|
||||
|
||||
for id, want := range map[string][]string{
|
||||
"exported": {"/data/exported"},
|
||||
"other": nil,
|
||||
} {
|
||||
got, err := cleanedRepos.Snapshots.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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Two creates of one snapshot name back to back start within one second,
|
||||
// the resolution of the timestamp in a snapshot ID. See
|
||||
// https://git.eeqj.de/sneak/vaultik/issues/270.
|
||||
|
||||
Reference in New Issue
Block a user