Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7cf82cc1d2 |
No files matched your search
@@ -554,6 +554,12 @@ count and blob size unknown, `null` in `--json`. A file under `blobs/` whose
|
|||||||
name is not a blob hash is not counted as a blob, since `prune` never deletes
|
name is not a blob hash is not counted as a blob, since `prune` never deletes
|
||||||
it.
|
it.
|
||||||
|
|
||||||
|
A blob that a manifest lists but the destination does not hold is reported as
|
||||||
|
missing, with a count and size. The report names each snapshot that lists a
|
||||||
|
missing blob, since that snapshot cannot be restored. The command then exits
|
||||||
|
non-zero. `--json` gives these in `missing_blob_count`, `missing_blob_size` and
|
||||||
|
`snapshots_missing_blobs`.
|
||||||
|
|
||||||
- `--json`: Output as JSON
|
- `--json`: Output as JSON
|
||||||
|
|
||||||
**`remote nuke`**: Delete every object under `metadata/` and `blobs/` on the
|
**`remote nuke`**: Delete every object under `metadata/` and `blobs/` on the
|
||||||
|
|||||||
@@ -75,7 +75,9 @@ func newRemoteInfoCommand() *cobra.Command {
|
|||||||
- Size of all snapshot metadata (per snapshot and total)
|
- Size of all snapshot metadata (per snapshot and total)
|
||||||
- Count and total size of all blobs
|
- Count and total size of all blobs
|
||||||
- Count and size of referenced blobs (from all manifests)
|
- Count and size of referenced blobs (from all manifests)
|
||||||
- Count and size of orphaned blobs (not referenced by any manifest)`,
|
- Count and size of orphaned blobs (not referenced by any manifest)
|
||||||
|
- Count and size of referenced blobs missing from remote storage, and the
|
||||||
|
snapshots that list them; the command exits non-zero when any are missing`,
|
||||||
Args: cobra.NoArgs,
|
Args: cobra.NoArgs,
|
||||||
RunE: func(cmd *cobra.Command, _ []string) error {
|
RunE: func(cmd *cobra.Command, _ []string) error {
|
||||||
// Use unified config resolution
|
// Use unified config resolution
|
||||||
|
|||||||
@@ -67,12 +67,10 @@ func NewRcloneStorer(ctx context.Context, remote, path string) (*RcloneStorer, e
|
|||||||
// Check for remote not found error
|
// Check for remote not found error
|
||||||
if strings.Contains(err.Error(), "didn't find section in config file") ||
|
if strings.Contains(err.Error(), "didn't find section in config file") ||
|
||||||
strings.Contains(err.Error(), "failed to find remote") {
|
strings.Contains(err.Error(), "failed to find remote") {
|
||||||
return nil, fmt.Errorf("%w: %q (%s)",
|
return nil, fmt.Errorf("%w: %s", ErrRemoteNotFound, remote)
|
||||||
ErrRemoteNotFound, remote, describeRcloneConfigFile())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, fmt.Errorf("opening rclone remote %q (%s): %w",
|
return nil, fmt.Errorf("creating rclone filesystem: %w", err)
|
||||||
remote, describeRcloneConfigFile(), err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return &RcloneStorer{
|
return &RcloneStorer{
|
||||||
@@ -326,22 +324,6 @@ func (r *RcloneStorer) upload(ctx context.Context, key string, data io.Reader) e
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// describeRcloneConfigFile names the rclone config file for an error
|
|
||||||
// message, and says so when that file does not exist.
|
|
||||||
func describeRcloneConfigFile() string {
|
|
||||||
path := config.GetConfigPath()
|
|
||||||
if path == "" {
|
|
||||||
return "no config file"
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err := os.Stat(path)
|
|
||||||
if errors.Is(err, os.ErrNotExist) {
|
|
||||||
return fmt.Sprintf("config file %q, which does not exist", path)
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Sprintf("config file %q", path)
|
|
||||||
}
|
|
||||||
|
|
||||||
// progressReader wraps an io.Reader to track read progress.
|
// progressReader wraps an io.Reader to track read progress.
|
||||||
type progressReader struct {
|
type progressReader struct {
|
||||||
reader io.Reader
|
reader io.Reader
|
||||||
|
|||||||
@@ -398,100 +398,24 @@ func TestNewRcloneStorerUnknownRemote(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// setRcloneConfigEnv points RCLONE_CONFIG at path for the rest of the test.
|
// TestNewRcloneStorerReadsRcloneConfigEnv checks that a remote defined only
|
||||||
func setRcloneConfigEnv(t *testing.T, path string) {
|
// in the file RCLONE_CONFIG names is found and written to, as rclone itself
|
||||||
t.Helper()
|
// would.
|
||||||
|
func TestNewRcloneStorerReadsRcloneConfigEnv(t *testing.T) {
|
||||||
// rclone keeps the config file path in a process-global variable, which
|
// rclone keeps the config file path in a process-global variable, which
|
||||||
// NewRcloneStorer leaves pointing at path.
|
// NewRcloneStorer leaves pointing at this test's file.
|
||||||
previous := config.GetConfigPath()
|
previous := config.GetConfigPath()
|
||||||
|
|
||||||
t.Cleanup(func() { _ = config.SetConfigPath(previous) })
|
t.Cleanup(func() { _ = config.SetConfigPath(previous) })
|
||||||
|
|
||||||
t.Setenv("RCLONE_CONFIG", path)
|
|
||||||
}
|
|
||||||
|
|
||||||
// writeRcloneConfigFile writes contents to a new rclone config file and
|
|
||||||
// returns its path.
|
|
||||||
func writeRcloneConfigFile(t *testing.T, contents string) string {
|
|
||||||
t.Helper()
|
|
||||||
|
|
||||||
confFile := filepath.Join(t.TempDir(), "rclone.conf")
|
confFile := filepath.Join(t.TempDir(), "rclone.conf")
|
||||||
|
|
||||||
err := os.WriteFile(confFile, []byte(contents), 0o600)
|
err := os.WriteFile(confFile, []byte("[loc]\ntype = local\n"), 0o600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("writing rclone config: %v", err)
|
t.Fatalf("writing rclone config: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return confFile
|
t.Setenv("RCLONE_CONFIG", confFile)
|
||||||
}
|
|
||||||
|
|
||||||
// TestNewRcloneStorerErrorsNameRemoteAndConfigFile checks that each error
|
|
||||||
// from opening a remote names the remote and the rclone config file, and
|
|
||||||
// says when that file does not exist.
|
|
||||||
//
|
|
||||||
//nolint:paralleltest // sets RCLONE_CONFIG and the process-global rclone config
|
|
||||||
func TestNewRcloneStorerErrorsNameRemoteAndConfigFile(t *testing.T) {
|
|
||||||
const doesNotExist = "which does not exist"
|
|
||||||
|
|
||||||
missingFile := filepath.Join(t.TempDir(), "missing.conf")
|
|
||||||
emptyFile := writeRcloneConfigFile(t, "")
|
|
||||||
badRemoteFile := writeRcloneConfigFile(t,
|
|
||||||
"[bad]\ntype = vaultik-no-such-backend\n")
|
|
||||||
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
configFile string
|
|
||||||
remote string
|
|
||||||
wantNotFound bool
|
|
||||||
wantNoSuchFile bool
|
|
||||||
}{
|
|
||||||
{"config file missing", missingFile, "dav", true, true},
|
|
||||||
{"remote not in config file", emptyFile, "dav", true, false},
|
|
||||||
{"remote fails to open", badRemoteFile, "bad", false, false},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tt := range tests {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
|
||||||
setRcloneConfigEnv(t, tt.configFile)
|
|
||||||
|
|
||||||
_, err := storage.NewRcloneStorer(
|
|
||||||
context.Background(), tt.remote, "path")
|
|
||||||
if err == nil {
|
|
||||||
t.Fatal("NewRcloneStorer succeeded, want an error")
|
|
||||||
}
|
|
||||||
|
|
||||||
msg := err.Error()
|
|
||||||
|
|
||||||
if errors.Is(err, storage.ErrRemoteNotFound) != tt.wantNotFound {
|
|
||||||
t.Errorf("error = %v, want ErrRemoteNotFound: %v",
|
|
||||||
err, tt.wantNotFound)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !strings.Contains(msg, `"`+tt.remote+`"`) {
|
|
||||||
t.Errorf("error %q does not name remote %q", msg, tt.remote)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !strings.Contains(msg, tt.configFile) {
|
|
||||||
t.Errorf("error %q does not name config file %q",
|
|
||||||
msg, tt.configFile)
|
|
||||||
}
|
|
||||||
|
|
||||||
if strings.Contains(msg, doesNotExist) != tt.wantNoSuchFile {
|
|
||||||
t.Errorf("error %q, want it to say the file does not exist: %v",
|
|
||||||
msg, tt.wantNoSuchFile)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TestNewRcloneStorerReadsRcloneConfigEnv checks that a remote defined only
|
|
||||||
// in the file RCLONE_CONFIG names is found and written to, as rclone itself
|
|
||||||
// would.
|
|
||||||
//
|
|
||||||
//nolint:paralleltest // sets RCLONE_CONFIG and the process-global rclone config
|
|
||||||
func TestNewRcloneStorerReadsRcloneConfigEnv(t *testing.T) {
|
|
||||||
setRcloneConfigEnv(t, writeRcloneConfigFile(t, "[loc]\ntype = local\n"))
|
|
||||||
|
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
|
|
||||||
"github.com/dustin/go-humanize"
|
"github.com/dustin/go-humanize"
|
||||||
"sneak.berlin/go/vaultik/internal/log"
|
"sneak.berlin/go/vaultik/internal/log"
|
||||||
|
"sneak.berlin/go/vaultik/internal/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ShowInfo displays system and configuration information
|
// ShowInfo displays system and configuration information
|
||||||
@@ -187,6 +188,9 @@ type SnapshotMetadataInfo struct {
|
|||||||
// backup interrupted before its manifest upload leaves a directory
|
// backup interrupted before its manifest upload leaves a directory
|
||||||
// without one, which prune does not treat as a snapshot.
|
// without one, which prune does not treat as a snapshot.
|
||||||
hasManifest bool
|
hasManifest bool
|
||||||
|
|
||||||
|
// Hashes of the blobs the snapshot's manifest lists.
|
||||||
|
blobHashes []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoteInfoResult contains all remote storage information
|
// RemoteInfoResult contains all remote storage information
|
||||||
@@ -216,6 +220,13 @@ type RemoteInfoResult struct {
|
|||||||
OrphanedBlobCount *int `json:"orphaned_blob_count"`
|
OrphanedBlobCount *int `json:"orphaned_blob_count"`
|
||||||
OrphanedBlobSize *int64 `json:"orphaned_blob_size"`
|
OrphanedBlobSize *int64 `json:"orphaned_blob_size"`
|
||||||
|
|
||||||
|
// Blobs that a manifest lists but the destination does not hold,
|
||||||
|
// and the remote key of each snapshot whose manifest lists one.
|
||||||
|
// Those snapshots cannot be restored.
|
||||||
|
MissingBlobCount int `json:"missing_blob_count"`
|
||||||
|
MissingBlobSize int64 `json:"missing_blob_size"`
|
||||||
|
SnapshotsMissingBlobs []string `json:"snapshots_missing_blobs,omitempty"`
|
||||||
|
|
||||||
// Remote key of each snapshot whose manifest could not be read
|
// Remote key of each snapshot whose manifest could not be read
|
||||||
UnreadableManifests []string `json:"unreadable_manifests,omitempty"`
|
UnreadableManifests []string `json:"unreadable_manifests,omitempty"`
|
||||||
|
|
||||||
@@ -283,19 +294,30 @@ func (v *Vaultik) RemoteInfo(jsonOutput bool) error {
|
|||||||
"snapshots", result.TotalMetadataCount,
|
"snapshots", result.TotalMetadataCount,
|
||||||
"total_blobs", result.TotalBlobCount,
|
"total_blobs", result.TotalBlobCount,
|
||||||
"referenced_blobs", result.ReferencedBlobCount,
|
"referenced_blobs", result.ReferencedBlobCount,
|
||||||
|
"missing_blobs", result.MissingBlobCount,
|
||||||
"unreadable_manifests", len(result.UnreadableManifests))
|
"unreadable_manifests", len(result.UnreadableManifests))
|
||||||
|
|
||||||
if jsonOutput {
|
if jsonOutput {
|
||||||
enc := json.NewEncoder(v.Stdout)
|
enc := json.NewEncoder(v.Stdout)
|
||||||
enc.SetIndent("", " ")
|
enc.SetIndent("", " ")
|
||||||
|
|
||||||
return enc.Encode(result)
|
err = enc.Encode(result)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("encoding JSON: %w", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if showText {
|
if showText {
|
||||||
v.printRemoteInfoTable(result)
|
v.printRemoteInfoTable(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The report is written first, so the exit status adds to it.
|
||||||
|
if result.MissingBlobCount > 0 {
|
||||||
|
return fmt.Errorf("%w: %d blob(s) that snapshots list are missing; "+
|
||||||
|
"%d snapshot(s) cannot be restored", errProblemsInStorage,
|
||||||
|
result.MissingBlobCount, len(result.SnapshotsMissingBlobs))
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -405,6 +427,7 @@ func (v *Vaultik) collectReferencedBlobsFromManifests(
|
|||||||
for _, blob := range manifest.Blobs {
|
for _, blob := range manifest.Blobs {
|
||||||
referencedBlobs[blob.Hash] = blob.CompressedSize
|
referencedBlobs[blob.Hash] = blob.CompressedSize
|
||||||
blobsSize += blob.CompressedSize
|
blobsSize += blob.CompressedSize
|
||||||
|
info.blobHashes = append(info.blobHashes, blob.Hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
info.BlobCount = &blobCount
|
info.BlobCount = &blobCount
|
||||||
@@ -462,6 +485,8 @@ func (v *Vaultik) scanRemoteBlobStorage(
|
|||||||
result.TotalBlobSize += blob.Size
|
result.TotalBlobSize += blob.Size
|
||||||
}
|
}
|
||||||
|
|
||||||
|
countMissingBlobs(result, referencedBlobs, allBlobs)
|
||||||
|
|
||||||
// A blob named only by a manifest that could not be read, or by one
|
// A blob named only by a manifest that could not be read, or by one
|
||||||
// under a skipped name, would be counted as orphaned, so the orphan
|
// under a skipped name, would be counted as orphaned, so the orphan
|
||||||
// figures stay unknown.
|
// figures stay unknown.
|
||||||
@@ -487,6 +512,33 @@ func (v *Vaultik) scanRemoteBlobStorage(
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// countMissingBlobs records in result the referenced blobs that
|
||||||
|
// allBlobs, the listing of the destination, does not hold, and the
|
||||||
|
// snapshots whose manifests list one of them. It reads the snapshots
|
||||||
|
// from result.Snapshots, so populateRemoteInfoResult must run first.
|
||||||
|
func countMissingBlobs(
|
||||||
|
result *RemoteInfoResult, referencedBlobs map[string]int64,
|
||||||
|
allBlobs map[string]storage.ObjectInfo,
|
||||||
|
) {
|
||||||
|
for hash, size := range referencedBlobs {
|
||||||
|
if _, present := allBlobs[hash]; !present {
|
||||||
|
result.MissingBlobCount++
|
||||||
|
result.MissingBlobSize += size
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, info := range result.Snapshots {
|
||||||
|
for _, hash := range info.blobHashes {
|
||||||
|
if _, present := allBlobs[hash]; !present {
|
||||||
|
result.SnapshotsMissingBlobs = append(
|
||||||
|
result.SnapshotsMissingBlobs, info.SnapshotID)
|
||||||
|
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// printRemoteInfoTable renders the human-readable remote info output
|
// printRemoteInfoTable renders the human-readable remote info output
|
||||||
func (v *Vaultik) printRemoteInfoTable(result *RemoteInfoResult) {
|
func (v *Vaultik) printRemoteInfoTable(result *RemoteInfoResult) {
|
||||||
const (
|
const (
|
||||||
@@ -539,6 +591,12 @@ func (v *Vaultik) printRemoteInfoTable(result *RemoteInfoResult) {
|
|||||||
"", "", ubytes(result.TotalMetadataSize))
|
"", "", ubytes(result.TotalMetadataSize))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
v.printBlobStorageSummary(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
// printBlobStorageSummary renders the blob storage section that ends
|
||||||
|
// the human-readable remote info output.
|
||||||
|
func (v *Vaultik) printBlobStorageSummary(result *RemoteInfoResult) {
|
||||||
v.stdoutf("\n=== Blob Storage ===\n")
|
v.stdoutf("\n=== Blob Storage ===\n")
|
||||||
v.stdoutf("Total blobs on remote: %s (%s)\n",
|
v.stdoutf("Total blobs on remote: %s (%s)\n",
|
||||||
humanize.Comma(int64(result.TotalBlobCount)),
|
humanize.Comma(int64(result.TotalBlobCount)),
|
||||||
@@ -546,22 +604,31 @@ func (v *Vaultik) printRemoteInfoTable(result *RemoteInfoResult) {
|
|||||||
v.stdoutf("Referenced by snapshots: %s (%s)\n",
|
v.stdoutf("Referenced by snapshots: %s (%s)\n",
|
||||||
humanize.Comma(int64(result.ReferencedBlobCount)),
|
humanize.Comma(int64(result.ReferencedBlobCount)),
|
||||||
ubytes(result.ReferencedBlobSize))
|
ubytes(result.ReferencedBlobSize))
|
||||||
|
v.stdoutf("Missing from remote: %s (%s)\n",
|
||||||
|
humanize.Comma(int64(result.MissingBlobCount)),
|
||||||
|
ubytes(result.MissingBlobSize))
|
||||||
|
|
||||||
if result.OrphanedBlobCount == nil {
|
if result.OrphanedBlobCount == nil {
|
||||||
v.stdoutf("Orphaned (unreferenced): unknown "+
|
v.stdoutf("Orphaned (unreferenced): unknown "+
|
||||||
"(%d manifest(s) could not be read, "+
|
"(%d manifest(s) could not be read, "+
|
||||||
"%d manifest(s) under a non-conforming name skipped)\n",
|
"%d manifest(s) under a non-conforming name skipped)\n",
|
||||||
len(result.UnreadableManifests), result.SkippedManifestCount)
|
len(result.UnreadableManifests), result.SkippedManifestCount)
|
||||||
|
} else {
|
||||||
|
v.stdoutf("Orphaned (unreferenced): %s (%s)\n",
|
||||||
|
humanize.Comma(int64(*result.OrphanedBlobCount)),
|
||||||
|
ubytes(*result.OrphanedBlobSize))
|
||||||
|
|
||||||
return
|
if *result.OrphanedBlobCount > 0 {
|
||||||
|
v.stdoutf("\nRun 'vaultik prune' to remove orphaned blobs.\n")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
v.stdoutf("Orphaned (unreferenced): %s (%s)\n",
|
if len(result.SnapshotsMissingBlobs) > 0 {
|
||||||
humanize.Comma(int64(*result.OrphanedBlobCount)),
|
v.stdoutf("\nSnapshots that cannot be restored (blobs missing):\n")
|
||||||
ubytes(*result.OrphanedBlobSize))
|
|
||||||
|
|
||||||
if *result.OrphanedBlobCount > 0 {
|
for _, id := range result.SnapshotsMissingBlobs {
|
||||||
v.stdoutf("\nRun 'vaultik prune' to remove orphaned blobs.\n")
|
v.stdoutf(" %s\n", id)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ func TestRemoteInfo_UnreadableManifestLeavesSnapshotBlobsUnknown(t *testing.T) {
|
|||||||
env := newListEnv(t)
|
env := newListEnv(t)
|
||||||
readableKey := env.addRemote(t, listRemoteID,
|
readableKey := env.addRemote(t, listRemoteID,
|
||||||
time.Date(2026, 3, 2, 0, 0, 0, 0, time.UTC))
|
time.Date(2026, 3, 2, 0, 0, 0, 0, time.UTC))
|
||||||
|
addBlob(t, env.store.testStorer, testBlobHashA)
|
||||||
|
|
||||||
unreadableKey := snapshot.RemoteSnapshotKey(listLocalID)
|
unreadableKey := snapshot.RemoteSnapshotKey(listLocalID)
|
||||||
require.NoError(t, env.store.Put(context.Background(),
|
require.NoError(t, env.store.Put(context.Background(),
|
||||||
@@ -270,6 +271,7 @@ func TestRemoteInfo_StatusLineUsesUIMarker(t *testing.T) {
|
|||||||
|
|
||||||
env := newListEnv(t)
|
env := newListEnv(t)
|
||||||
env.addRemote(t, listRemoteID, time.Date(2026, 3, 2, 0, 0, 0, 0, time.UTC))
|
env.addRemote(t, listRemoteID, time.Date(2026, 3, 2, 0, 0, 0, 0, time.UTC))
|
||||||
|
addBlob(t, env.store.testStorer, testBlobHashA)
|
||||||
|
|
||||||
const statusLine = ui.Marker + " Scanning snapshot metadata...\n"
|
const statusLine = ui.Marker + " Scanning snapshot metadata...\n"
|
||||||
|
|
||||||
@@ -281,3 +283,61 @@ func TestRemoteInfo_StatusLineUsesUIMarker(t *testing.T) {
|
|||||||
require.NoError(t, env.v.RemoteInfo(false))
|
require.NoError(t, env.v.RemoteInfo(false))
|
||||||
assert.NotContains(t, env.stdout.String(), "Scanning snapshot metadata")
|
assert.NotContains(t, env.stdout.String(), "Scanning snapshot metadata")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestRemoteInfo_ReportsBlobsMissingFromDestination checks that a blob a
|
||||||
|
// manifest lists but the destination does not hold is counted as
|
||||||
|
// missing, that the snapshot listing it is named, and that remote info
|
||||||
|
// then fails after writing its report.
|
||||||
|
func TestRemoteInfo_ReportsBlobsMissingFromDestination(t *testing.T) {
|
||||||
|
log.Initialize(log.Config{})
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
env := newListEnv(t)
|
||||||
|
|
||||||
|
// The first snapshot lists blob A, which is not stored. The second
|
||||||
|
// lists blob B, which is.
|
||||||
|
brokenKey := env.addRemote(t, listRemoteID,
|
||||||
|
time.Date(2026, 3, 2, 0, 0, 0, 0, time.UTC))
|
||||||
|
addManifest(t, env.store.testStorer, listLocalID, []string{testBlobHashB})
|
||||||
|
addBlob(t, env.store.testStorer, testBlobHashB)
|
||||||
|
|
||||||
|
const wantError = "1 blob(s) that snapshots list are missing; " +
|
||||||
|
"1 snapshot(s) cannot be restored"
|
||||||
|
|
||||||
|
err := env.v.RemoteInfo(false)
|
||||||
|
require.ErrorContains(t, err, wantError)
|
||||||
|
|
||||||
|
text := env.stdout.String()
|
||||||
|
assert.Contains(t, text, "Missing from remote: 1 (5.0 MB)")
|
||||||
|
assert.Contains(t, text, "Snapshots that cannot be restored (blobs missing):\n"+
|
||||||
|
" "+brokenKey+"\n")
|
||||||
|
assert.NotContains(t, text, snapshot.RemoteSnapshotKey(listLocalID)+"\n")
|
||||||
|
|
||||||
|
env.stdout.Reset()
|
||||||
|
require.ErrorContains(t, env.v.RemoteInfo(true), wantError)
|
||||||
|
|
||||||
|
var doc map[string]any
|
||||||
|
|
||||||
|
require.NoError(t, json.Unmarshal(env.stdout.Bytes(), &doc))
|
||||||
|
assert.InDelta(t, 1, doc["missing_blob_count"], 0)
|
||||||
|
assert.InDelta(t, fiveMegabytes, doc["missing_blob_size"], 0)
|
||||||
|
assert.Equal(t, []any{brokenKey}, doc["snapshots_missing_blobs"])
|
||||||
|
|
||||||
|
// --quiet drops the report, not the failure.
|
||||||
|
env.stdout.Reset()
|
||||||
|
env.v.UI.SetQuiet(true)
|
||||||
|
require.ErrorContains(t, env.v.RemoteInfo(false), wantError)
|
||||||
|
assert.Empty(t, env.stdout.String())
|
||||||
|
env.v.UI.SetQuiet(false)
|
||||||
|
|
||||||
|
// With blob A stored again nothing is missing.
|
||||||
|
addBlob(t, env.store.testStorer, testBlobHashA)
|
||||||
|
env.stdout.Reset()
|
||||||
|
require.NoError(t, env.v.RemoteInfo(true))
|
||||||
|
|
||||||
|
doc = nil
|
||||||
|
require.NoError(t, json.Unmarshal(env.stdout.Bytes(), &doc))
|
||||||
|
assert.InDelta(t, 0, doc["missing_blob_count"], 0)
|
||||||
|
assert.InDelta(t, 0, doc["missing_blob_size"], 0)
|
||||||
|
assert.NotContains(t, doc, "snapshots_missing_blobs")
|
||||||
|
}
|
||||||
@@ -349,6 +349,7 @@ func TestSnapshotListAndPurgePrintSizesLikeRemoteInfo(t *testing.T) {
|
|||||||
env.addRemote(t, listLocalID, start)
|
env.addRemote(t, listLocalID, start)
|
||||||
require.NoError(t, env.v.Repositories.Snapshots.UpdateCounts(
|
require.NoError(t, env.v.Repositories.Snapshots.UpdateCounts(
|
||||||
context.Background(), nil, listLocalID, 0, 0, 0, 0, fiveMegabytes))
|
context.Background(), nil, listLocalID, 0, 0, 0, 0, fiveMegabytes))
|
||||||
|
addBlob(t, env.store.testStorer, testBlobHashA)
|
||||||
|
|
||||||
require.NoError(t, env.v.RemoteInfo(false))
|
require.NoError(t, env.v.RemoteInfo(false))
|
||||||
assert.Contains(t, findTableRow(t, env.stdout.String(), remoteKey[:16]),
|
assert.Contains(t, findTableRow(t, env.stdout.String(), remoteKey[:16]),
|
||||||
|
|||||||
Reference in new issue
Block a user