Repository navigation
cmd: keep the database untouched when gogs restore fails to move files - #8453
Merged
Merged
Conversation
Restoring moves the current custom and data directories aside to
"<dir>.bak". When an earlier restore had already left those behind, the
rename failed ("Access is denied" on Windows, "directory not empty"
elsewhere), but only after the database had been replaced, so the
instance was left half restored.
Check for the leftover ".bak" paths before importing anything and say
which one to move away.
Restore the custom and data directories before the database, so a leftover ".bak" from an earlier restore stops the restore while the database is still untouched. The current files are kept as ".bak" and can be moved back by hand, whereas a failed database import cannot be undone. Backup and restore now share one list of data directories, which also makes restore bring back the built-in SSH server's host keys that backup has been including since gogs#7345.
gogs restore fails to move files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe the pull request
gogs restoremoves the currentcustomdirectory, and each data directory it restores, aside to<dir>.bak. If an earlier restore already leftcustom.bakbehind, that rename fails: "Access is denied" on Windows, as in #7999, and "directory not empty" elsewhere. It only failed after the database had been imported, so the instance was left with the backup's database but its currentcustom, data and repositories.This restores the files before the database. The current files are kept as
<dir>.bakand can be moved back by hand, whereas a failed database import cannot be undone. A leftover.baknow stops the restore with a message that says which path to move away, while the database is still untouched.Backup and restore now share one list of data directories. As a result, restore also brings back the built-in SSH server's host keys (
data/ssh), which backup has been including since #7345 but restore never put back.Link to the issue: #7999
Checklist
Test plan
With a SQLite instance:
gogs backup --config custom/conf/app.ini, thengogs restore --config custom/conf/app.ini --from gogs-backup-<time>.zip. This succeeds, leavescustom.bakbehind, and replacesdata/sshwith the backup's host keys.On
main, step 2 replaces the database (the new user is gone) and then fails with the error from #7999:With this change, step 2 stops before touching the database, and the new user is still there:
After moving
custom.bak(and anydata/*.bak) away, the restore succeeds.AI usage
The follow-up maintainer commits (reordering the restore, sharing the data directory list) were written with Claude Code and reviewed by a maintainer.