kopia/kopia · warning

snapshot source has less than two snapshots

Error message

snapshot source has less than two snapshots

What it means

GetTwoLatestSnapshotsForASource requires at least two snapshots for a source to return the last and second-last manifests. If fewer than two exist, it returns this error since no pair can be returned.

Solutions

  1. Run another backup to create a second snapshot
  2. Guard the call by counting snapshots via snapshot.ListSnapshots first
  3. Treat the error as 'nothing to compare' and skip the diff
  4. Manually specify two known snapshot IDs using a diff API that takes explicit IDs

Example fix

// before
prev, last, err := diff.GetTwoLatestSnapshotsForASource(ctx, rep, source)
// after
snaps, _ := snapshot.ListSnapshots(ctx, rep, source)
if len(snaps) < 2 {
    return nil // only %d snapshot(s) exist
}
prev, last, err := diff.GetTwoLatestSnapshotsForASource(ctx, rep, source)
Defensive patterns

Strategy: validation

Validate before calling

snaps, err := snapshot.ListSnapshots(ctx, rep, source)
if err != nil || len(snaps) < 2 {
    return nil // fewer than two snapshots
}

Try / catch

prev, last, err := diff.GetTwoLatestSnapshotsForASource(ctx, rep, source)
if err != nil && strings.Contains(err.Error(), "less than two") {
    return nil // nothing to diff yet
}

Prevention

When it happens

Trigger: Calling GetTwoLatestSnapshotsForASource for a source with 0 or 1 snapshots.

Common situations: First run of a diff/reporting tool on a newly configured source; a source that has only had one backup ever taken.

Understand the failure class

Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.

Related errors


AI-assisted analysis of kopia/kopia@82495e54b5 (2026-09-07). Data as JSON: /api/errors/bf12b75a59f603c2. Report an issue: GitHub.

Appendix: source

Thrown at internal/diff/diff.go:459

			return snapshotList[i-1], nil
		}
	}

	return nil, errors.New("couldn't find immediately preceding snapshot")
}

// GetTwoLatestSnapshotsForASource fetches two latest snapshot manifests for a given source if they exist.
func GetTwoLatestSnapshotsForASource(ctx context.Context, rep repo.Repository, source snapshot.SourceInfo) (secondLast, last *snapshot.Manifest, err error) {
	snapshots, err := snapshot.ListSnapshots(ctx, rep, source)
	if err != nil {
		return nil, nil, errors.Wrap(err, "failed to list all snapshots")
	}

	const minimumReqSnapshots = 2

	sizeSnapshots := len(snapshots)
	if sizeSnapshots < minimumReqSnapshots {
		return nil, nil, errors.New("snapshot source has less than two snapshots")
	}

	sort.Slice(snapshots, func(i, j int) bool {
		return snapshots[i].StartTime.Before(snapshots[j].StartTime)
	})

	return snapshots[sizeSnapshots-2], snapshots[sizeSnapshots-1], nil
}

View on GitHub (pinned to 82495e54b5)