Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
cb35bd1
design: propose the native mirror layout on one shared planner
mbertschler Sep 23, 2026
9d86c4e
design: record the native mirror decisions
mbertschler Sep 23, 2026
54243d2
sync: extract the push planner shared by the content layouts
mbertschler Sep 23, 2026
a1be793
sync: refuse a wiped root whose upload records remain
mbertschler Sep 23, 2026
e9888a3
store: add remote_paths, the native mirror's destination record
mbertschler Sep 23, 2026
f690057
sync: reserve .squirrel-staging for a native mirror's in-flight writes
mbertschler Sep 23, 2026
a7efc49
sync: add the transport, its name guard and the local implementation
mbertschler Sep 23, 2026
fe36baa
sync: push local mirrors natively through the transport
mbertschler Sep 23, 2026
de05fa1
docs: describe the native local mirror
mbertschler Sep 23, 2026
5d74066
sync: tighten the mirror's record type and comments
mbertschler Sep 23, 2026
b47961e
sync: keep mirror copies out of the content layouts' upload check
mbertschler Sep 23, 2026
0a5e785
config: reject rclone-only keys on native mirrors
mbertschler Sep 23, 2026
1fc1f6c
sync: add the sftp transport
mbertschler Sep 23, 2026
6491a0e
sync: push plain sftp mirrors natively
mbertschler Sep 23, 2026
3931e06
sync: ride the index snapshot along through the transport
mbertschler Sep 23, 2026
f5cf926
sync: discover and fetch a native mirror's snapshots through the tran…
mbertschler Sep 23, 2026
45be05e
sync: restore each file through a temporary file beside its path
mbertschler Sep 23, 2026
1d00c10
sync: restore native mirrors through the transport
mbertschler Sep 23, 2026
4d34f9f
sync: pin that both test servers' rename replaces its target
mbertschler Sep 23, 2026
33c3afe
sync: clear a partial ride-along snapshot, and tidy the shelves
mbertschler Sep 23, 2026
0068c2b
sync: let a hung sftp server release the transport
mbertschler Sep 24, 2026
2cc55a9
sync: land the marker and the ride-along snapshot whole or not at all
mbertschler Sep 24, 2026
2dbce81
sync: skip a broken receipt whole, and read restores in large blocks
mbertschler Sep 24, 2026
7329347
store: record a mirror copy's read-back fingerprint, and let the gate…
mbertschler Sep 24, 2026
1a2bb18
sync: read a local mirror's staged copy back before committing it
mbertschler Sep 24, 2026
7df2e2f
sync: verify native mirrors, and write again what they lost
mbertschler Sep 24, 2026
81ca000
offload: pin that a native local mirror gates, and an sftp mirror nev…
mbertschler Sep 24, 2026
9a9025c
docs, design, audit: a native local mirror can gate offload again
mbertschler Sep 24, 2026
4db8561
sync: let the name guard commit a content layout's artifacts
mbertschler Sep 24, 2026
4409d7c
sync: run the sftp server's hash command through the transport
mbertschler Sep 24, 2026
0084ca8
sync: pull the native root's plumbing out of the mirror handler
mbertschler Sep 24, 2026
f452829
sync: land the content layouts' artifacts through an artifact store
mbertschler Sep 24, 2026
3b43b1b
sync: tidy the server hash tests and wrap the probe's failure
mbertschler Sep 24, 2026
5a7fa92
sync: push content-addressed and packed destinations through the tran…
mbertschler Sep 24, 2026
6031419
sync: restore and recover native content destinations through the tra…
mbertschler Sep 24, 2026
80126f8
sync: verify native content destinations through the transport
mbertschler Sep 24, 2026
9164cca
sync, cmd: reach every native destination without rclone
mbertschler Sep 24, 2026
4119ada
docs: describe the content layouts squirrel writes itself
mbertschler Sep 24, 2026
8a5d41f
sync, store: stop a lost mirror copy from vouching, and never verify …
mbertschler Sep 24, 2026
e1d6770
sync: never mistake an unhashed artifact for a changed one
mbertschler Sep 24, 2026
5185997
sync, agent, docs: say what native destinations do now, and say it po…
mbertschler Sep 24, 2026
72a1b4e
sync: refuse names a folding mirror cannot tell apart, and follow cas…
mbertschler Sep 24, 2026
d42dfaf
sync: crash a native push at every transport call, on both transports
mbertschler Sep 24, 2026
58a64ed
sync: check a native mirror against a reference model over random his…
mbertschler Sep 24, 2026
444a215
sync: lose records a non-directory took away, and report staging of u…
mbertschler Sep 24, 2026
8009e45
sync: refuse a first push onto a tree squirrel did not record, and le…
mbertschler Sep 24, 2026
3b7f270
sync, config: tell an unplugged disk from a new one, and name the loc…
mbertschler Sep 24, 2026
3632164
docs, design: say which destinations squirrel writes itself, and what…
mbertschler Sep 24, 2026
e7f57a8
design: set native-mirror.md's status, map every required case to its…
mbertschler Sep 24, 2026
333d10e
design: log the native mirror walk's findings
mbertschler Sep 24, 2026
1bc4ff7
design: the corrupted copy passed two verify passes, not three
mbertschler Sep 24, 2026
c9a0db0
sync: fail the push when the fold plan cannot tell whether a path is …
mbertschler Sep 24, 2026
68e6b81
design: describe the testbed's exFAT disk and how the benchmark ran
mbertschler Sep 24, 2026
9dda926
docs: frame restore, verify, offload and staging as they work on nati…
mbertschler Sep 24, 2026
c0ae689
design: flush once per batch and write several paths at once (decisio…
mbertschler Sep 24, 2026
8bca689
config: concurrency sets how many files a push writes at once
mbertschler Sep 24, 2026
650288e
sync: flush once per batch and write several paths at once
mbertschler Sep 24, 2026
f2c3cfc
sync: land only what the final flush covers, and flush what reconcile…
mbertschler Sep 24, 2026
a16ca44
design: record the benchmark after decision 8
mbertschler Sep 24, 2026
d07821b
sync: count live records per directory so a push stays linear
mbertschler Sep 25, 2026
ced1380
design: correct the exFAT benchmark
mbertschler Sep 25, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Squirrel works the same at any size: one machine backing up to one destination,

## Under the hood

Squirrel indexes a local file tree by BLAKE3 content hash and syncs it to one or more remote destinations (NAS, S3, B2, GCS, SFTP, …) via rclone. Peer syncs are BLAKE3-verified end-to-end; every other destination is checked by the strongest comparison it supports, and the index records which one ran. Destinations are append-only: an overwrite at the destination moves the prior bytes into `.squirrel-history/run-<id>/`, never deletes them.
Squirrel indexes a local file tree by BLAKE3 content hash and syncs it to one or more destinations (a local disk, a NAS, SFTP, S3, B2, GCS, …): it writes local disks and plain SFTP servers itself, and reaches buckets and encrypted destinations through rclone. Peer syncs are BLAKE3-verified end-to-end; every other destination is checked by the strongest comparison it supports, and the index records which one ran. Destinations are append-only: an overwrite at the destination moves the prior bytes into `.squirrel-history/run-<id>/`, never deletes them.

## Principle

Expand Down Expand Up @@ -49,7 +49,7 @@ go install github.com/mbertschler/squirrel/cmd/squirrel@latest

A source build reports its version as `0.0.0-dev` — the version is only stamped into the released binaries at build time.

You will also need [rclone](https://rclone.org) ≥ 1.71 on `PATH` to sync or restore against a **bucket destination** (1.71 added the sftp `hashes` option that [`hash_algo`](#offsite-verification-squirrel-verify) sets). Syncing to a **peer node** does not use it — those bytes stream over the peer's own sync API — so a machine whose only targets are peers needs no rclone at all:
You will also need [rclone](https://rclone.org) ≥ 1.71 on `PATH` to sync or restore against a **bucket destination** (`s3`, `b2`, `gcs`) or an **encrypted** one (1.71 added the sftp `hashes` option that [`hash_algo`](#offsite-verification-squirrel-verify) sets there). A `local` disk and a plain `sftp` server need no rclone — squirrel writes them itself — and neither does a **peer node**, whose bytes stream over the peer's own sync API, so a machine whose only targets are those needs no rclone at all:

```
brew install rclone # macOS
Expand Down Expand Up @@ -88,11 +88,11 @@ bucket = "squirrel-backup"
root = "/squirrel"
```

Supported destination types: `local`, `sftp`, `s3`, `b2`, `gcs` (rclone-backed), and `kopia` (see [kopia destinations](#kopia-destinations)). Secrets accept either a literal string or an inline `{ env = "VAR_NAME" }` table that is resolved at load time. Unknown fields, missing required fields, and unset env vars are rejected immediately — squirrel will not invoke rclone with a misconfigured destination.
Supported destination types: `local`, `sftp`, `s3`, `b2`, `gcs`, and `kopia` (see [kopia destinations](#kopia-destinations)). squirrel writes `local` and `sftp` destinations itself, and rclone writes `s3`, `b2`, `gcs` and every encrypted destination. Secrets accept either a literal string or an inline `{ env = "VAR_NAME" }` table that is resolved at load time. Unknown fields, missing required fields, and unset env vars are rejected immediately — squirrel will not start a transfer to a misconfigured destination.

Some optional params are specific to one backend type and rejected on the others (as an unknown field):

- **`sftp` host-key validation** — `known_hosts_file` points rclone at a known_hosts file so it validates the server's host key before transferring; `host_key_algorithms` is rclone's space-separated list pinning the accepted host-key algorithms. Both map to the rclone sftp options of the same name. **Without `known_hosts_file`, rclone does not validate the server's host key** and will connect to whatever host answers — set it (recommended) so a redirected or impersonated server is rejected.
- **`sftp` host-key validation** — `known_hosts_file` names a known_hosts file holding the server's host key; `host_key_algorithms` is a space-separated list pinning the accepted host-key algorithms. squirrel checks the key of every sftp destination it writes — every one without `crypt` — against `known_hosts_file`, or `~/.ssh/known_hosts` when unset, and refuses a server the file does not hold. On an encrypted sftp destination both map to the rclone sftp options of the same name, and **without `known_hosts_file`, rclone does not validate the server's host key** and will connect to whatever host answers — set it so a redirected or impersonated server is rejected.

```toml
[destinations.nas]
Expand All @@ -114,7 +114,7 @@ Some optional params are specific to one backend type and rejected on the others
storage_class = "<provider archive tier>" # archive tiers cost less to store, more to read
```

Squirrel writes its own `rclone.conf` next to the config (`~/.squirrel/rclone.conf`, mode 0600) on every sync invocation. You do not run `rclone config` and you should not edit `rclone.conf` by hand.
For the destinations rclone writes, squirrel writes its own `rclone.conf` next to the config (`~/.squirrel/rclone.conf`, mode 0600) on every sync invocation. You do not run `rclone config` and you should not edit `rclone.conf` by hand.

### Encrypted destinations

Expand Down Expand Up @@ -158,7 +158,7 @@ Properties that differ from rclone destinations:

### Content-addressed destinations

By default a destination mirrors the volume's tree (see [Destination layout](#destination-layout)). Any rclone-remote destination — with or without a `crypt` block — can instead opt into an **append-only, content-addressed** layout, built for cold archive storage where objects should never be rewritten or moved:
By default a destination mirrors the volume's tree (see [Destination layout](#destination-layout)). Any destination but kopia — with or without a `crypt` block — can instead opt into an **append-only, content-addressed** layout, built for cold archive storage where objects should never be rewritten or moved. squirrel writes it itself on a `local` disk and on `sftp` without `crypt`: each object is staged, confirmed (read back through BLAKE3 locally, hashed by the server's `hash_algo` command on sftp) and only then renamed onto its name, never over a file already there. rclone writes the others:

```toml
[destinations.archive]
Expand All @@ -182,7 +182,7 @@ Properties that differ from mirrored destinations:

- **Verification is presence+size**, recorded as such: each object is re-hashed with BLAKE3 before upload and confirmed present at the expected size after it, but its stored bytes are not compared at transfer time (and `crypt` remotes expose no hashes at all), so the runs row is recorded shallow and the push never claims content verification. On top of that, each upload's provider-side ciphertext fingerprint is recorded in the index and re-checked by [`squirrel verify`](#offsite-verification-squirrel-verify).
- **Pick the layout when the destination is first used.** Switching an existing mirrored destination to `content-addressed` (or back) is not supported — point the new layout at a fresh destination or root. The push detects a mirrored history (a recorded successful sync without its manifest segment) and refuses.
- **`squirrel restore` restores the layout**: it resolves each present path to its content hash from the local index, fetches the per-hash object through the same rclone (`crypt`) read path the push uses, and re-hashes every fetched object before writing. When the *local index itself* is lost, the format is deliberately simple enough to recover without squirrel — see below.
- **`squirrel restore` restores the layout**: it resolves each present path to its content hash from the local index, fetches the per-hash object through the same read path the push uses (squirrel's own on a `local` disk and plain `sftp`, rclone and its `crypt` overlay otherwise), and re-hashes every fetched object before writing. When the *local index itself* is lost, the format is deliberately simple enough to recover without squirrel — see below.
- `--dry-run` is not supported yet on the push (it previews restore).

#### Offsite verification (`squirrel verify`)
Expand All @@ -192,7 +192,8 @@ Cold archive storage is exactly the copy you can't cheaply re-download and re-ha
What gets recorded depends on the backend type:

- **`s3`** — the object **ETag**, recorded as `etag-md5` for a single-part upload's whole-object MD5, or `etag-md5-composite` for a multipart object's `<hex>-<parts>` value, stored verbatim either way. The ETag is read straight from the S3 API with a paginated `ListObjectsV2` over the `objects/` prefix, *not* through rclone: rclone funnels every hash read through `Object.Hash(MD5)`, which returns an empty string for a composite ETag, so a multipart (or client-encrypted, always-streamed) object would otherwise never expose a fingerprint at all. Listing is archive-tier-safe (no per-object `HEAD`, no restore), and the composite ETag is fixed at upload time and unaffected by later storage-class transitions or server-side encryption, so the recorded value stays stable for the life of the object. This read is the counterpart to the (deferred) write-side use of S3 additional checksums; capturing the ETag needs no upload-side change. For S3-compatible providers whose endpoint the client addresses wrongly, set `force_path_style = true` (see below).
- **`sftp`** — the checksum computed server-side by the remote's hash command. Content-addressed sftp destinations default to **SHA-256** (`hash_algo = "sha256"`, rendered as rclone's sftp `hashes` option so the selection is explicit rather than rclone's md5/sha1 preference); set `hash_algo` if your server only offers another type.
- **`local`** — the BLAKE3 of the stored bytes, read back by squirrel itself as each object lands and again on every verify pass; it must equal the object's name.
- **`sftp`** — the checksum computed server-side by the remote's hash command. Content-addressed sftp destinations default to **SHA-256** (`hash_algo = "sha256"`); set `hash_algo` if your server only offers another type. Without `crypt` squirrel runs the command itself (`md5sum`, `sha1sum`, `sha256sum` or `b3sum`) and checks its answer against the bytes it sent; behind `crypt` rclone runs it, through its sftp `hashes` option.
- **other backends** — whatever hash `rclone lsjson --hash` exposes, recorded under its rclone hash name (e.g. `sha1` on b2). A backend exposing no checksum leaves the fingerprint pending, with a warning in the sync output.

Re-verify a destination (or all content-addressed destinations) at any time:
Expand Down Expand Up @@ -384,7 +385,7 @@ squirrel sync pictures --to nas # just one
squirrel sync # every (volume, destination) pair in config
```

Sync compares every file with its copy on a mirror destination by checksum (rclone's `--checksum`), under the first hash both ends support — MD5 on local disks and S3, independent of the BLAKE3 in the index. A copy that fails the check after transfer is an error, so the runs row is not marked success. The run records the `checksum` method, which the offload gate does not accept: a mirror can never be named in `offload_requires`. Use `--shallow` to fall back to rclone's default size+mtime comparison if you want speed over integrity for a big initial push. Encrypted (`crypt`) destinations always use the size+mtime comparison (see [Encrypted destinations](#encrypted-destinations)).
A mirror on a `local` disk is written by squirrel itself: it hashes every file with BLAKE3 as it streams out, reads each copy back through BLAKE3 before committing it, and records the run as `fingerprint-verified` once every file has such a copy, so it can be named in `offload_requires`; `--shallow` is refused there, since there is no comparison to skip. A native sftp mirror (no crypt) is written the same way, without the read-back. Sync compares every file with its copy on a mirror rclone writes (encrypted, or on s3, b2 or gcs) by checksum (rclone's `--checksum`), under the first hash both ends support — MD5 on S3, independent of the BLAKE3 in the index. A copy that fails the check after transfer is an error, so the runs row is not marked success, and the run records the `checksum` method, which the offload gate refuses: such a mirror can never be named in `offload_requires`, and neither can a native sftp mirror, which reads nothing back. Use `--shallow` to fall back to rclone's default size+mtime comparison on an rclone mirror if you want speed over integrity for a big initial push. Encrypted (`crypt`) destinations always use the size+mtime comparison (see [Encrypted destinations](#encrypted-destinations)).

### First use and the `.squirrel-volume` marker

Expand Down Expand Up @@ -470,13 +471,15 @@ Each mirrored destination (`layout = "mirror"`, the default) is a tree shaped li
pictures/
2024/cat.jpg
.squirrel-history/run-7/2024/cat.jpg # prior content of cat.jpg
.squirrel-index/run-12 # receipt for run 12 (local disks)
.squirrel-index/index-20260604T120000.000Z-run-12.db # global index snapshot (ride-along)
.squirrel-staging/ # in-flight writes (local disks)
docs/
invoice.pdf
.squirrel-history/run-9/invoice.pdf
```

`.squirrel-history/run-<run-id>/` is rclone's `--backup-dir` target for that sync run. It is filtered out of all subsequent comparisons so it does not grow rclone's listing time or get uploaded back. A directory literally called `.squirrel-history` in your source volume is also filtered (with a warning), to keep the reserved name out of the destination tree by accident.
`.squirrel-history/run-<run-id>/` holds the prior bytes of every file that sync run replaced, moved there first and never deleted. On a local disk squirrel writes the mirror itself: each file is staged under `.squirrel-staging/`, whatever its path held moves into history, and the staged copy is renamed into place; each run leaves a receipt of its changes at `.squirrel-index/run-<id>`, and a local mirror starts on a fresh or emptied root. Remote mirrors are written by rclone, with history as its `--backup-dir`. History is filtered out of all subsequent comparisons so it does not grow listing time or get uploaded back. A directory literally called `.squirrel-history` in your source volume is also filtered (with a warning), to keep the reserved name out of the destination tree by accident.

`.squirrel-index/` holds the index snapshots ridden along after each successful sync (see [Index snapshots](#index-snapshots)). Like `.squirrel-history`, it is filtered out of all sync and restore transfers and from peer-sync, so a snapshot is never mistaken for user content.

Expand Down
22 changes: 19 additions & 3 deletions SAFETY-AUDIT.md
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,12 @@ extended enforcement to remote rclone destinations (`sftp`, `s3`, `b2`,
the mirror, content-addressed, and packed layouts, with the marker filtered
out of every transfer, comparison, and restore. A read that fails for any
reason other than a definite "not found" refuses without writing, so a
reachability blip cannot be mistaken for a fresh root.
reachability blip cannot be mistaken for a fresh root. Since
[#217](https://github.com/mbertschler/squirrel/pull/217), a `local`
destination and an `sftp` one without crypt read and write the marker
through squirrel's own transport, staged and renamed onto its name, in every
layout; a volume that synced there before is refused as a disk that is most
likely not mounted rather than steered toward `--init`.

**Issue:** [#64 — sync: require .squirrel-volume markers on destination and source to gate against misconfiguration](https://github.com/mbertschler/squirrel/issues/64); [#150 — sync: enforce .squirrel-volume markers on remote rclone destinations](https://github.com/mbertschler/squirrel/issues/150)

Expand Down Expand Up @@ -1019,7 +1024,12 @@ local and s3 — and runs were recorded as `blake3` all the same.
records such a run as `checksum`, relabels the components already stored,
and stops the offload gate from accepting it, so a mirror can no longer be
named in `offload_requires`. The shallow warning now says "skipping the
checksum comparison".
checksum comparison". The native mirror
([#217](https://github.com/mbertschler/squirrel/pull/217)) earns the evidence
back on a `local` disk: it refuses `--shallow`, hashes every file as it
streams, reads each copy back through BLAKE3 before committing it, and
`squirrel verify` re-checks its copies, so a local mirror may gate offload
again. rclone mirrors and native sftp mirrors still may not.

**Issue:** `sync: surface --shallow trade-off in logs and persist it on the runs row`
→ tracked in [#79](https://github.com/mbertschler/squirrel/issues/79),
Expand Down Expand Up @@ -1620,7 +1630,13 @@ proves — `presence+size` is explicitly **not** content-verified, and
`store.ContentVerifiedMethod`). So the *consequence* the finding worried
about — a presence-only advance gating an offload — is gone.

The narrow original gap remains: nothing downloads an object back through
Since [#217](https://github.com/mbertschler/squirrel/pull/217), a
destination without crypt that squirrel writes itself closes the gap: each
artifact is staged, read back through BLAKE3 on a local disk or hashed by
the server's command on sftp, and only then renamed onto its name. The gap
stays for crypt destinations, which rclone writes.

The narrow original gap remains there: nothing downloads an object back through
the crypt overlay and BLAKE3s the plaintext, so a wrong-at-upload object
that happens to preserve decrypted size is still theoretically undetected.
No `--verify` mode exists. This stays a deliberate non-decision rather than
Expand Down
16 changes: 9 additions & 7 deletions agent/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ func (s *scheduler) refresh() {
s.pullEvery = resolvePullCadences(cur.Nodes)
}

// resolveVerifyCadences maps each verifiable (content-addressed or packed)
// destination to its effective verify cadence: the destination's own
// resolveVerifyCadences maps each verifiable destination (content-addressed,
// packed, or a native mirror) to its effective verify cadence: the destination's own
// verify_every when set, otherwise the [agent] verify_every default. Only
// destinations with a positive resulting cadence are included, so a config
// with neither knob set yields an empty map and no verify activity.
func resolveVerifyCadences(dests map[string]*config.Destination, def time.Duration) map[string]time.Duration {
out := make(map[string]time.Duration)
for name, d := range dests {
if d.Layout != config.LayoutContentAddressed && d.Layout != config.LayoutPacked {
if !d.Verifiable() {
continue
}
eff := d.VerifyEvery
Expand Down Expand Up @@ -252,10 +252,12 @@ func (s *scheduler) tick(ctx context.Context) {
}
// The verify and durability-pull cadences key on destinations and peer
// nodes rather than volumes, so they run after the per-volume loop as
// their own phases. Both are read-only / metadata-only and take no
// volume lock: verify touches only the remote-object bookkeeping, and a
// durability pull only merges peer-supplied vectors — neither races the
// per-volume index/sync/audit work the loop above coordinates.
// their own phases. Both only read the destination and take no volume
// lock: verify updates only squirrel's records of what the destination
// holds, a mirror copy's only while its row is still where the pass
// read it, and a durability pull only merges peer-supplied vectors — so
// neither is confused by the per-volume index/sync/audit work the loop
// above coordinates.
s.evaluateVerify(ctx)
s.evaluateDurabilityPulls(ctx)
}
Expand Down
Loading
Loading