From e251a62015775d23ff5a007f50bb82a89f2be4de Mon Sep 17 00:00:00 2001 From: luatan Date: Mon, 12 Feb 2024 22:40:22 +0100 Subject: [PATCH 1/3] wait for palworld server to shutdown first --- scripts/restore.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/scripts/restore.sh b/scripts/restore.sh index e0f287273..75c57fc10 100644 --- a/scripts/restore.sh +++ b/scripts/restore.sh @@ -67,6 +67,12 @@ if [ -f "$BACKUP_FILE" ]; then echo "RCON is not enabled. Please enable RCON to use this feature. Unable to restore backup." exit 1 fi + + while [ -n "$(pidof PalServer-Linux-Test)" ] + do + echo "Waiting for Palworld to exit.." + sleep 1 + done printf "\e[0;32mShutdown complete.\e[0m\n" trap - ERR @@ -103,6 +109,8 @@ if [ -f "$BACKUP_FILE" ]; then # Decompress the backup file in tmp directory tar -zxvf "$BACKUP_FILE" -C "$TMP_PATH" + rm -rf "$RESTORE_PATH/Saved/" + # Move the backup file to the restore directory \cp -rf -f "$TMP_PATH/Saved/" "$RESTORE_PATH" From 024b051ee80d2a5dbc6554dc24fd96db7fdbf297 Mon Sep 17 00:00:00 2001 From: luatan Date: Mon, 12 Feb 2024 22:41:04 +0100 Subject: [PATCH 2/3] add comment --- scripts/restore.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/restore.sh b/scripts/restore.sh index 75c57fc10..c649951e5 100644 --- a/scripts/restore.sh +++ b/scripts/restore.sh @@ -109,6 +109,7 @@ if [ -f "$BACKUP_FILE" ]; then # Decompress the backup file in tmp directory tar -zxvf "$BACKUP_FILE" -C "$TMP_PATH" + # Make sure Saves with a different ID are removed before restoring the save rm -rf "$RESTORE_PATH/Saved/" # Move the backup file to the restore directory From aaae8c688ddb76ecb84fde5b045319fccb50bebd Mon Sep 17 00:00:00 2001 From: Luatan <74045606+Luatan@users.noreply.github.com> Date: Tue, 13 Feb 2024 09:01:26 +0100 Subject: [PATCH 3/3] change from while loop to tail Co-authored-by: Carlos Martinez --- scripts/restore.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/scripts/restore.sh b/scripts/restore.sh index c649951e5..207748fb3 100644 --- a/scripts/restore.sh +++ b/scripts/restore.sh @@ -68,11 +68,13 @@ if [ -f "$BACKUP_FILE" ]; then exit 1 fi - while [ -n "$(pidof PalServer-Linux-Test)" ] - do + mapfile -t server_pids < <(pgrep PalServer-Linux-Test) + if [ "${#server_pids[@]}" -ne 0 ]; then echo "Waiting for Palworld to exit.." - sleep 1 - done + for pid in "${server_pids[@]}"; do + tail --pid="$pid" -f 2>/dev/null + done + fi printf "\e[0;32mShutdown complete.\e[0m\n" trap - ERR