Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Level Backup don't use ChangedSinceBackup flag. #754

Open
rdebath opened this issue Mar 30, 2023 · 2 comments
Open

Level Backup don't use ChangedSinceBackup flag. #754

rdebath opened this issue Mar 30, 2023 · 2 comments

Comments

@rdebath
Copy link
Contributor

rdebath commented Mar 30, 2023

The flag ChangedSinceBackup is ignored because it is set when a block is placed and never cleared.
The AutoSave server task will do a backup with a 1 in 15 chance each time that a map save is triggered by a block change within the last save period (backup-time). With the default setup, if a level is changed every 5 minutes for 75 minutes a backup will be triggered.

I would not expect this semi-random method is what it was supposed to do.

Perhaps the backup is supposed to be done 15 backup-time periods after the first change (plus when the map is unloaded)?
It is very unclear because the counter used is on the task not the level.

@UnknownShadow200
Copy link
Collaborator

That quirky logic for auto backup has been there since MCForge, and even all the way back to MCLawl/MCZall.
image

Probably should be changed into using separate autosave-interval and autobackup-interval config options though


I accidentally removed resetting of ChangedSinceBackup to unchanged around 5 years with the commit 50c2140

@rdebath
Copy link
Contributor Author

rdebath commented Jun 23, 2023

This seems to be working nicely; doesn't backup on exit-level but does stop main getting perpetually saved by Snakes and Zombies.

From f3a9fe4d016fb02e0b3fa0cdf4ef7252f864eea0 Mon Sep 17 00:00:00 2001
From: Robert de Bath <[email protected]>
Date: Fri, 23 Jun 2023 11:20:04 +0100
Subject: [PATCH] Use ChangedSinceBackup to allow and disallow backups

---
 MCGalaxy/Levels/Level.cs             | 2 ++
 MCGalaxy/Server/Tasks/ServerTasks.cs | 4 +++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/MCGalaxy/Levels/Level.cs b/MCGalaxy/Levels/Level.cs
index 2902c6921..e4b76b577 100644
--- a/MCGalaxy/Levels/Level.cs
+++ b/MCGalaxy/Levels/Level.cs
@@ -301,7 +301,9 @@ namespace MCGalaxy
             if (ChangedSinceBackup || force) {
                 if (backup.Length == 0) backup = LevelInfo.NextBackup(name);
 
+                ChangedSinceBackup = false;
                 if (!LevelActions.Backup(name, backup)) {
+                    ChangedSinceBackup = true;
                     Logger.Log(LogType.Warning, "FAILED TO INCREMENTAL BACKUP :" + name);
                     return null;
                 }
diff --git a/MCGalaxy/Server/Tasks/ServerTasks.cs b/MCGalaxy/Server/Tasks/ServerTasks.cs
index 0f29e73ce..c7f72b97f 100644
--- a/MCGalaxy/Server/Tasks/ServerTasks.cs
+++ b/MCGalaxy/Server/Tasks/ServerTasks.cs
@@ -130,7 +130,9 @@ namespace MCGalaxy.Tasks {
             
             foreach (Level lvl in levels) {
                 try {
-                    if (!lvl.Changed || !lvl.SaveChanges) continue;
+                    if (!lvl.SaveChanges) continue;
+                    if ((count != 0 || !lvl.ChangedSinceBackup) && !lvl.Changed)
+                        continue;
 
                     lvl.Save();
                     if (count == 0)  {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants