Open rdebath opened 1 year ago
That quirky logic for auto backup has been there since MCForge, and even all the way back to MCLawl/MCZall.
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 50c2140734ded53bbfa89fa10c2b90e726db0a7c
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 <rdebath@tvisiontech.co.uk>
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) {
The flag
ChangedSinceBackup
is ignored because it is set when a block is placed and never cleared. TheAutoSave
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.