repository: do not delete config on atomic backends during upgrade rollback (#22136)

In UpgradeRepo, if upgradeRepository fails, the error handler attempts
contingency rollback by re-uploading the original config file.

However, the contingency path unconditionally executed repo.be.Remove(ctx, h)
before calling repo.be.Save. On backends supporting atomic replacement (such
as local filesystems), a failed upgrade (e.g. out-of-disk-space or permissions
error while writing the temporary file) leaves the original, valid version 1
configuration file completely intact on disk.

Unconditionally removing the config file during rollback actively deletes
the working configuration. If the subsequent Save call also fails, the
repository is left permanently corrupted without a config file.

Condition the pre-removal on !repo.be.Properties().HasAtomicReplace, matching
the forward upgrade path in upgradeRepository. Add a unit test asserting that
aborted upgrades on atomic backends preserve the intact original configuration.

---------

Co-authored-by: Michael Eischer <michael.eischer@fau.de>
This commit is contained in:
Rob MartinandMichael Eischer authored and GitHub committed 2026-11-15 18:57:01 +00:00
1 parent c904b78998
commit 2c9b353cbf
4 files changed
+50 -7

No files matched your search

+10
View File
@@ -0,0 +1,10 @@
Bugfix: Improve silience of repository v2 upgrade rollback
When upgrading a repository from version 1 to 2, an aborted migration
attempted contingency rollback by unconditionally removing the configuration
file before re-saving it. On atomic backends (such as local filesystems),
the original configuration was intact, and deleting it during a failed rollback
left the repository unopenable. Restic now conditions config pre-removal
on whether the backend lacks atomic replacement.
https://github.com/restic/restic/pull/22136