From fa6a2d4869a58bb7ad707f85b482c77bf514e656 Mon Sep 17 00:00:00 2001 From: Peritia Date: Mon, 29 Dec 2025 11:53:45 +0100 Subject: [PATCH] update: add more checks to filter between different backup processes --- .../minecraft-template-backup-routine.sh | 43 +++++++++++++++---- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/minecraft/Scripts/minecraft-template-backup-routine.sh b/minecraft/Scripts/minecraft-template-backup-routine.sh index 46b3fb0..8e99aa1 100644 --- a/minecraft/Scripts/minecraft-template-backup-routine.sh +++ b/minecraft/Scripts/minecraft-template-backup-routine.sh @@ -201,37 +201,55 @@ countdown() { } +build_backup_signature() { + local sig=() + + [[ "$FULL" == true ]] && sig+=("full") || sig+=("world") + [[ "$PURE" == true ]] && sig+=("pure") + + sig+=("format=$FORMAT") + sig+=("compression=$COMPRESSION") + + IFS=','; echo "${sig[*]}" +} check_user_activity() { local activity_file="$DATA_DIR/$SERVER_NAME/$USER_ACTIVITY_FILE" + local marker="[backuped:${BACKUP_SIGNATURE}]" if [[ ! -f "$activity_file" ]]; then echo "[WARN] User activity file not found: $activity_file" return 1 fi - # Find unbackuped login lines - if ! grep -E 'was logged in' "$activity_file" | grep -vq '\[backuped\]'; then - echo "[INFO] No unbackuped user activity detected." + # Find login lines NOT marked with the current backup signature + if ! grep -E 'was logged in' "$activity_file" | grep -vqF "$marker"; then + echo "[INFO] No unbackuped user activity detected for signature: $BACKUP_SIGNATURE" return 1 fi - echo "[INFO] Unbackuped user activity detected." + echo "[INFO] Unbackuped user activity detected for signature: $BACKUP_SIGNATURE" return 0 } mark_user_activity_backuped() { local activity_file="$DATA_DIR/$SERVER_NAME/$USER_ACTIVITY_FILE" + local marker="[backuped:${BACKUP_SIGNATURE}]" - # Append [backuped] to all unbackuped login lines + [[ -z "${ACTIVITY_LINE_CUTOFF:-}" || "$ACTIVITY_LINE_CUTOFF" -le 0 ]] && return 0 + + # Only mark lines that existed before the backup started sed -i \ - -e '/was logged in/{ - /\[backuped\]/! s/$/ [backuped]/ - }' \ + -e "1,${ACTIVITY_LINE_CUTOFF}{ + /was logged in/{ + /$marker/! s/\$/ $marker/ + } + }" \ "$activity_file" } + do_backup() { local backup_source="" local backup_destination="" @@ -386,6 +404,15 @@ do_backup() { #echo "[DEBUG] FULL=$FULL" +BACKUP_SIGNATURE="$(build_backup_signature)" + +ACTIVITY_LINE_CUTOFF=0 + +if [[ "$CHECK_USER" == true ]]; then + ACTIVITY_LINE_CUTOFF=$(wc -l < "$DATA_DIR/$SERVER_NAME/$USER_ACTIVITY_FILE") +fi + + if [[ "$CHECK_USER" == true ]]; then echo "[INFO] Running in --check-user mode" if ! check_user_activity; then