From 30ccf35d03ce4424e8f5b69f7ea0dd52aa380974 Mon Sep 17 00:00:00 2001 From: Peritia Date: Thu, 12 Feb 2026 08:08:49 +0100 Subject: [PATCH] Update: fix script not accidentally writing files owned by root + added a trap to ensure it doesnt just exit silently --- .../minecraft-template-backup-routine.sh | 37 ++++++++++++++++--- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/minecraft/Scripts/minecraft-template-backup-routine.sh b/minecraft/Scripts/minecraft-template-backup-routine.sh index 8af2e6e..21c055e 100644 --- a/minecraft/Scripts/minecraft-template-backup-routine.sh +++ b/minecraft/Scripts/minecraft-template-backup-routine.sh @@ -436,7 +436,9 @@ delta_sync_snapshot() { local progress_last_time progress_last_time=$(date +%s) - "$rsync_cmd" -rptgoDL --delete --info=progress2 --stats \ + #"$rsync_cmd" -rptgoDL --delete --info=progress2 --stats \ + # may result in root owning files for example mods + "$rsync_cmd" -rptL --delete-after --info=progress2 --stats \ "$DATA_DIR/$SERVER_NAME/" \ "$SNAPSHOT_DIR/" 2>&1 | \ while IFS= read -r -d $'\r' chunk; do @@ -501,15 +503,40 @@ if (( SLEEP_TIME > 0 )); then countdown "$SLEEP_TIME" fi -mkdir -p "$DESTINATION" -echo "[INFO] Make Snapshot dir..." + +cleanup() { + say "Something went wrong" + say "Ensuring automatic world saves are re-enabled..." + $mcrcon_cmd save-on >/dev/null 2>&1 || true +} + + + +mkdir -p "$DESTINATION" +echo "[INFO] Preparing snapshot directory..." SNAPSHOT_DIR="${DATA_DIR}/${SERVER_NAME}_snapshot" mkdir -p "$SNAPSHOT_DIR" -say "Updating the Snapshot it could take a moment" +say "Initiating backup procedure..." -delta_sync_snapshot +say "Disabling automatic world saves to ensure data consistency..." + +trap cleanup EXIT + +$mcrcon_cmd save-off + +say "Forcing world save to disk..." +$mcrcon_cmd save-all + +say "Starting incremental snapshot sync. This may take a moment depending on world size..." + +if delta_sync_snapshot; then + say "Snapshot sync completed successfully." +else + say "WARNING: Snapshot sync encountered errors." + exit 1 +fi say "Backing up Server now "