Prevent yml data corruption#862
Draft
TechnicallyCoded wants to merge 1 commit intobooksaw:masterfrom
Draft
Conversation
Owner
|
This looks interesting, is this something you have seen happen on your server before? |
Author
|
Yep, due to storage running out when a plugin misbehaved and wrote gigabytes per second to disk. Any plugin using flatfile storage failed and all data was deleted. Backups were pulled, but obviously, a daily backup is only as up to date as its last save, making us lose data regardless. This method guarantees that storage is available before overwriting by writing first and swapping the file in if it succeeds. |
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.
This is not intended to be merged in its current state. I am only opening this PR draft in order to share this solution with anyone who may want/need it.
What this edit does:
teams.ymlfile toteams.yml.bakteams.yml.preand write the new datateams.yml.pretoteams.ymloverwriting the existingteams.ymlfile with the new dataIf during any step, a write is prevented, the list of tasks is aborted and does not proceed. In this scenario, any new data is discarded but the integrity of the file is preserved, preventing a total loss of data. If the file writing process is interrupted in a weird way (during shutdown / force-kill / etc) the .bak is still present and would allow the admins to simply restore this version.
Realistically, a production ready version of this would probably omit the .bak file and preserve the rest.