palworld-server-docker icon indicating copy to clipboard operation
palworld-server-docker copied to clipboard

Add restore command

Open seoseonyu opened this issue 1 year ago • 9 comments

Context

  • Add the restore command to restore a backup file created using the backup command.
  • Add the usage of the resotre command to the README.md (English and Korean have been written, but Chinese needs additional work)

Choices

  • There is a backup command, but not a restore command, so this is for users who are not familiar with CLI commands.

Test instructions

  1. set the path to the actual save file locally and tested it.
  2. added the command to the docker file and tested whether it runs normally after building.
  3. For safe recovery, we shut down the server, temporarily saved the save file, and created a recovery process in case of an error.

We've done our own error handling and testing for all cases, but if additional testing is needed, we can do it.

Checklist before requesting a review

  • [v] I have performed a self-review of my code
  • [v] I've added documentation about this change to the README.
  • [v] I've not introduced breaking changes.

seoseonyu avatar Jan 31 '24 14:01 seoseonyu

We'll work on a fix for that error.

seoseonyu avatar Jan 31 '24 14:01 seoseonyu

Resolved all Shell - Lint warnings except for functions for error handling.

In order to give you the option to recover your backed up files before proceeding with the recovery by executing a handling function to detect errors if they occur during the recovery, the Error handling functions are required.

The code I'm doing that generates the warning is executed when an execution error occurs via a trap. The Lint process doesn't seem to detect this.

What do you think about this?

seoseonyu avatar Jan 31 '24 15:01 seoseonyu

Thanks for the suggestion.

We'll take your suggestion into consideration and make changes.

seoseonyu avatar Jan 31 '24 17:01 seoseonyu

The container stops when su steam -c ./start.sh stops. su steam -c ./start.sh stops when the PalServer.sh stops.

I believe running the restore command leads to a race since the restore must finish during limited window in which the server has shutdown but su steam -c ./start.sh has not.

Dashboy1998 avatar Jan 31 '24 17:01 Dashboy1998

The container stops when su steam -c ./start.sh stops. su steam -c ./start.sh stops when the PalServer.sh stops.

I believe running the restore command leads to a race since the restore must finish during limited window in which the server has shutdown but su steam -c ./start.sh has not.

Hmm... When I ran several tests, the restore went fine.

rcon-cli -c /home/steam/server/rcon.yaml save
rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1"

Are you saying that if this command is executed, the recovery should happen within the container's shutdown latency?

The docker in our test environment uses --stop-timeout 30 option was enabled.

i will test this separately by removing the --stop-timeout option.

seoseonyu avatar Jan 31 '24 23:01 seoseonyu

The container stops when su steam -c ./start.sh stops. su steam -c ./start.sh stops when the PalServer.sh stops. I believe running the restore command leads to a race since the restore must finish during limited window in which the server has shutdown but su steam -c ./start.sh has not.

Hmm... When I ran several tests, the restore went fine.

rcon-cli -c /home/steam/server/rcon.yaml save
rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1"

Are you saying that if this command is executed, the recovery should happen within the container's shutdown latency?

The docker in our test environment uses --stop-timeout 30 option was enabled.

i will test this separately by removing the --stop-timeout option.

Yes it must happen within the shutdown period however there's no way to know the size of the shutdown period. --stop-timeout 30 is the limit.

There is a non-zero amount of time between rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1" and when the container stops. In that amount of time you must complete the restore.

Also looking at the script again it doesn't look like it actual waits for the server to stop. rcon-cli exits almost instantly. To prevent this you'd want to add this after the rcon wait $(pidof PalServer-Linux-Test).

Dashboy1998 avatar Feb 01 '24 00:02 Dashboy1998

The container stops when su steam -c ./start.sh stops. su steam -c ./start.sh stops when the PalServer.sh stops. I believe running the restore command leads to a race since the restore must finish during limited window in which the server has shutdown but su steam -c ./start.sh has not.

Hmm... When I ran several tests, the restore went fine.

rcon-cli -c /home/steam/server/rcon.yaml save
rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1"

Are you saying that if this command is executed, the recovery should happen within the container's shutdown latency? The docker in our test environment uses --stop-timeout 30 option was enabled. i will test this separately by removing the --stop-timeout option.

Yes it must happen within the shutdown period however there's no way to know the size of the shutdown period. --stop-timeout 30 is the limit.

There is a non-zero amount of time between rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1" and when the container stops. In that amount of time you must complete the restore.

Also looking at the script again it doesn't look like it actual waits for the server to stop. rcon-cli exits almost instantly. To prevent this you'd want to add this after the rcon wait $(pidof PalServer-Linux-Test).

Thanks for the feedback.

I will do some more testing on this and think of a workaround.

I can't fix it right now because I'm at work. 😭

seoseonyu avatar Feb 01 '24 00:02 seoseonyu

The container stops when su steam -c ./start.sh stops. su steam -c ./start.sh stops when the PalServer.sh stops. I believe running the restore command leads to a race since the restore must finish during limited window in which the server has shutdown but su steam -c ./start.sh has not.

Hmm... When I ran several tests, the restore went fine.

rcon-cli -c /home/steam/server/rcon.yaml save
rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1"

Are you saying that if this command is executed, the recovery should happen within the container's shutdown latency? The docker in our test environment uses --stop-timeout 30 option was enabled. i will test this separately by removing the --stop-timeout option.

Yes it must happen within the shutdown period however there's no way to know the size of the shutdown period. --stop-timeout 30 is the limit. There is a non-zero amount of time between rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1" and when the container stops. In that amount of time you must complete the restore. Also looking at the script again it doesn't look like it actual waits for the server to stop. rcon-cli exits almost instantly. To prevent this you'd want to add this after the rcon wait $(pidof PalServer-Linux-Test).

Thanks for the feedback.

I will do some more testing on this and think of a workaround.

I can't fix it right now because I'm at work. 😭

Realizing the issue also exists for backups I made this PR #248.

Also wait $(pidof PalServer-Linux-Test) won't work in the update script since PalServer-Linux-Test is not a child of your script. You'd have to do a pgrep and tail.

Dashboy1998 avatar Feb 01 '24 01:02 Dashboy1998

As suggested by @Dashboy1998, I removed the --stop-timeout and --restart unless-stopped options and forced a wait using the sleep command in the middle of the restore process and found that the container was actually terminated before the restore was complete.

As per his suggestion, I added code to init.sh to suspend container termination until the restore is complete, referring to PR #248.

  1. Force the restore script to be long-lived via the sleep command and test if it waits for the container to terminate while the script is in progress.
  2. test if the game is restored to the point in the backup file as normal if the container is waiting for termination.

We ran the above tests and confirmed that the container waits for termination and the game is restored to the point of view of the backup file.

We fixed the creation location of the temporary directory used for restoration to /palworld/backups.

seoseonyu avatar Feb 01 '24 14:02 seoseonyu

Fixed for suggestions

seoseonyu avatar Feb 02 '24 01:02 seoseonyu

Thank you very much for your help

seoseonyu avatar Feb 02 '24 06:02 seoseonyu

I added this disclaimer to the process of selecting the backup file to restore and confirming user intentions just before running the command.

The output looks like the picture below.

image

seoseonyu avatar Feb 02 '24 09:02 seoseonyu

I haven't executed this script yet but just wanna ask, will this let me select a backup file or will it only restore the latest backup?

rairulyle avatar Feb 02 '24 15:02 rairulyle

I haven't executed this script yet but just wanna ask, will this let me select a backup file or will it only restore the latest backup?

It let's you select a backup.

Dashboy1998 avatar Feb 02 '24 15:02 Dashboy1998