Skip to content

Fixes from the project review, and a new Keep versions rule - #4

Merged
razbenaharon merged 23 commits into
mainfrom
audit-fixes
Nov 16, 2026
Merged

razbenaharon merged 23 commits into
mainfrom
audit-fixes

Conversation

@razbenaharon

@razbenaharon razbenaharon commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Fixes from a review of the whole project, plus the behaviour changes that were decided along the way. Every fix has a test that showed the fault first. Not merged on purpose: please review before merging.

What was wrong and is fixed

Wrong success, missing backup, data loss

  • A plain copy that ended early (robocopy closed half-way, no totals in its log) was recorded as a success. It is now a failed run.
  • A stopped or crashed versioned backup left a lock that failed every later run. A lock is now removed by itself, only when it was made on this computer and its process has ended; the step is tried once more.
  • The clean-up of old versions could keep a partial version and delete a complete one of the same day. Partial versions are tagged, never counted, and never the reason a complete version goes.
  • Two selected folders could share one copy log, hiding a failure. A recovery folder made in a run could be deleted by the same run. A run whose result could not be read in full was recorded as a success.
  • A file and a folder that swapped kinds blocked the copy for ever; the old item is now moved to the recovery folder and the new one copied.

Deletion that was not approved (found in the last round)

  • Continuing an earlier backup of a folder that is added again (Use the earlier settings) kept the drive's clean-up approval, so its old versions and recovery folders were deleted by the rule without ever being listed. The first clean-up is now shown for approval again, and the window says so.
  • One version saved while the clock was far ahead moved the monthly part of Keep versions out of reach: every month's version was deleted, backup after backup. The months counted back from the version just made now keep their version too.
  • Deletion by hand could remove the newest complete version this tool made of a computer and set of folders when another program had saved a newer version of the same folders, or when the same folder was written with other capital letters. It is now also protected as the clean-up groups versions.
  • The question before the first clean-up has Show the full list: every version (with its ID) and recovery folder it would delete, in a scrollable window. Approving stores that same list; nothing outside it is deleted.

Plain copy: -Repair copies again what the last content check found different, keeping each old version; files skipped through a short Windows name, names that differ only by case, and files in use are named in the result; the same-disk guard works in both directions.

Versions: restore below protected folders says plainly that content was not verified; deletion in batches; an interrupted password change can resume after the drive letter changed; clean-up limited to this computer; a missing versions folder stops the backup instead of quietly starting an empty one.

Window: one window at a time; a damaged settings file can be restored from the last good copy and is never overwritten, also when it was damaged or edited while the window was open; the overview warns when the latest run failed; buttons that are off say why; the window refreshes itself and can shrink to 80%.

Drive check and privacy check: a controller reset counts only for the drive's own connection; a new scan keeps the last scan's bad areas; parts that were not checked are not reported as fine; a scan that loses the drive ends as not completed; the privacy check reads UTF-16, checks every pushed commit and finds long values inside words.

Keep versions: new rule

The newest N complete versions, whatever their dates, plus the newest complete version of each calendar month for M months, for each computer and set of folders (10 and 6 by default; up to 16 complete versions per group, usually 15, while the clock is right). A partial version is deleted once three complete versions of the same group are newer, which can remove content that exists only in it. Earlier day/week/month settings that deleted versions become 10 and 6, after a copy of the settings file is written.

Nothing is deleted before the first clean-up is approved: backups list what would go, the window asks once after a backup of every source that finished without errors, and that first clean-up deletes only what was listed. After that it runs by the rule. Changing the numbers, or continuing an earlier backup of a folder, asks again.

Decided during review (approved)

  • A full drive scan stops as "may have been disconnected" only when the drive answers nowhere else either. A chunk that fails with a device error while the drive still answers elsewhere is read again and then recorded as bad areas, so real damage behind a USB box is still reported.
  • A settings file that is valid but was changed outside the window is kept aside as profiles.changed-<time>.local.json, the window's settings are saved, and the status line names the copy.
  • An Exclude name with a wildcard can still skip files through their short Windows name; they are now named, not copied.

Locks when Windows reuses a process number

When the process that made a lock has ended and Windows already gave its number to another program, the worker judges the lock ended, but restic keeps it until it is 30 minutes old; the run fails with that time in its message, and a later run removes it. Test-BackupVersionsRules.ps1 checks this judgement against real running programs on every run. The kill test in Test-BackupVersions.ps1 cannot cause a reused number, but when it meets one (before its wait ends, or just after) the next run decides: the lock is removed with the usual checks, or it is kept, nothing is removed and the message names the number in use. Anything else fails and prints the run's result. CI met this case several times.

How it was tested

  • Locally and in CI: every test that needs no second drive, 17 test files plus the report generator's test. CI is green on the latest commit.
  • The new tests run real copies into a temporary folder and real restic repositories under the temporary folder; the window is opened off-screen and its questions are answered through test switches.
  • No real backup, password or settings file was used for deleting, overwriting or password experiments.

Not verified / known limits

  • The four older tests that need a second drive (Test-DevDriveBackup, Test-BackupSelection, Test-BackupSystem, Test-BackupSecurity) were not run; two were edited and only parse-checked.
  • The drive check itself (needs administrator rights and a disk) was not run; its rules and the reader against a plain file are tested. No real disconnect was tried. A very short break that ends before the drive is asked again can still record a few areas as bad (a false warning, not lost data).
  • No button in the real window was clicked by hand; the full-list window was drawn by a test but not looked at by a person. The retention rule was not run against a real backup.
  • A clock that was wrong can make a group keep up to M more monthly versions than usual until the dates are right again.
  • The drive database beside smartctl was compared with the official smartmontools 7.5 source archive: identical except the version line and the line ends of the Windows build. The pinned checksum is that of the installed Windows file; it was not re-derived by unpacking the installer.
  • The main window script is too large for the second-opinion review tool used here; it was reviewed through its data module and diffs.
  • Deliberately unchanged: cache folders are skipped, recovery folder names use local time.

🤖 Generated with Claude Code

razbenaharon and others added 23 commits November 14, 2026 20:00
…port copy limits

A robocopy log without totals is a failed run. Each selected folder has its own
log. A file and a folder that swapped kinds heal by moving the old item to the
dated recovery folder. -Repair copies again what the last content check found
different. Short-name skips and case collisions are reported. The same-disk
guard works in both directions. Tests run in a temporary folder (-TestRoot).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A backup that could not read every file is tagged as partial and never counted
or deleted by Keep versions. A lock left by a run that ended is removed only when
it was made on this computer and its process is gone; the step is retried once.
Clean-up is limited to this computer, deletes in batches, and restore below
protected folders reports that content was not verified.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Starting twice brings the open window forward. A damaged settings file can be
restored from the last good copy and is always kept. The overview warns when the
latest run failed. Runs are recorded as failed, stopped or unknown instead of a
wrong success. The window refreshes itself, explains disabled buttons and offers
Repair. Tests open the window off-screen (-Quiet).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Controller resets count only for the drive's own connection. A new scan keeps the
last scan's bad areas. Parts that were not checked are not reported as fine. The
health tool's drive database is pinned and a stray library stops it. The privacy
check reads UTF-16, checks every pushed commit and finds long values inside
words.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…sturdier test clean-up

-PreviewRecovery names the recovery folders the keep rule would delete and deletes
none, for the window's first-clean-up approval. The test's own tidying up removes
its junctions one by one and no longer fails a passed run.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A step that dot-sources a test ends with the exit code of the last program the
test ran (robocopy returns 1 after copying), so a passed test failed its step.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…en the engine is missing

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…er and folder set

The plan is computed by Get-VersionRetentionPlan and re-checked before deletion;
restic only lists and deletes by exact ID. Partial versions never count and go
once three complete versions of the same group are newer. -RetentionPreview plans
only. The result names the deleted versions and reports no freed size.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…before the first clean-up

Old day/week/month settings that deleted versions become 10 and 6 after a copy of
the settings file is written. Until the first clean-up is approved, backups only
list what would be deleted; the list is offered after a backup of every source
that finished without errors. Keep deleted is labelled by recovery folders.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…he engine installed

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…g repository stops the backup

-RetentionApprovedFile narrows one clean-up to the listed IDs that the plan still
wants deleted and reports what was deferred. A versions folder that is gone is
never recreated without -CreateNewRepository.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…a drive lost during a scan

-RecoveryApproved deletes only listed recovery folders. Files in use are named;
the run stays failed, but the first full check is remembered apart from a
complete backup and forgotten when any real difference is found. A scan that
loses the drive ends as not completed. Unmatched log entries are a note.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… settings changed on disk

Approval stores exactly what was shown and the next backup deletes only that.
The window suggests a keep rule, offers to exclude a file in use three times,
asks before creating a new versions folder and when a folder is added again,
can shrink to 80%, and never overwrites a settings file damaged or changed on
disk.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… variables

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ext run

On a slow computer the run that follows a killed backup could start while the
killed process still existed; its lock is then rightly left alone and the test
failed.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…esses to be gone

The hosted runner's screen is smaller than the window at full size, so Windows
cut the test window down and three size checks failed. The workflow sets a larger
resolution and the test says so plainly on a small screen. The kill tests wait
until Windows no longer knows the killed engine processes.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A lock is released only when its process is gone. On a busy computer Windows can
hand the ended process's number to a new program at once; the lock is then
rightly kept, and the two kill tests failed now and then. They now wait until
Windows no longer knows the killed processes and report that case as skipped.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…d two fixes

- A lock whose process number Windows gave to another program: the judgement
  is now checked every run against real running programs (Get-LockProcess
  moved to Backup.History.psm1). When the kill test meets a taken number it
  checks the outcome (lock kept with a plain message, or removed once free)
  instead of only skipping.
- Keep versions: one version dated far ahead by a wrong clock no longer moves
  every month out of the monthly rule; the months ending with the version
  just made count too.
- Continuing an earlier backup of a folder added again has the first clean-up
  shown for approval again; its old versions and recovery folders were
  deleted unseen on a drive whose clean-up already ran by the rule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tool's newest complete version

- The question before the first clean-up has "Show the full list": every
  version (with its ID) and recovery folder it would delete, in a window that
  can be scrolled and copied. Approving stores that same list.
- Deletion by hand also protects the newest complete version this tool made
  of each computer and set of folders as the clean-up groups them, so a newer
  version of another program or the same folder in other capital letters no
  longer leaves it unprotected.
- Tests can answer several questions in a row (-Answer 'A>B').

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ait is judged by the run itself

The kill test met a number that Windows gave to another program right after
it had waited for the old process to go. The next run decides now: the lock
is removed with the usual checks, or it is kept, nothing is removed and the
message names the number in use. Anything else fails and prints the result.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…umber match

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ttons stay on the screen

A hand check of the clean-up question with long folder names found its
buttons below the bottom edge of the screen. The text now scrolls in a box
of the height that fits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@razbenaharon
razbenaharon merged commit eae805a into main Nov 16, 2026
3 checks passed
@razbenaharon
razbenaharon deleted the audit-fixes branch November 16, 2026 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant