Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add restore command #244

Merged
merged 31 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
44879b6
Update Dockerfile and add restore.sh script
seoseonyu Jan 31, 2024
82d1a2d
Add restore instructions to README.md
seoseonyu Jan 31, 2024
5b948bc
Fixes invalid code modifications and shell script lint fix
seoseonyu Jan 31, 2024
3faeadb
Change restore command description in README.md
seoseonyu Jan 31, 2024
dbba5ec
fix restore.sh
seoseonyu Jan 31, 2024
5f16b77
Remove unnecessary functions
seoseonyu Jan 31, 2024
e5f6fab
fix restore.sh unreachable code
seoseonyu Jan 31, 2024
8163be0
Remove unnecessary codes
seoseonyu Jan 31, 2024
2e0186e
End script if `RCON` is disabled
seoseonyu Jan 31, 2024
f81e972
fix restore.sh spacing -> 4x
seoseonyu Jan 31, 2024
ffbb021
fix restore.sh Syntax errors
seoseonyu Jan 31, 2024
a3e4a48
Merge remote-tracking branch 'upstream/main' into add-resotre
seoseonyu Feb 1, 2024
5fbcc00
Add Wait for restore to complete
seoseonyu Feb 1, 2024
c4d986a
Add temporary save file path for restore process
seoseonyu Feb 1, 2024
e644eaf
remove test code
seoseonyu Feb 1, 2024
358e759
Change the temporary folder creation code to a single line
seoseonyu Feb 1, 2024
897d7ae
Change the temporary folder cleanup code to one line
seoseonyu Feb 1, 2024
7a0cbc3
Update scripts/restore.sh
seoseonyu Feb 1, 2024
c049f72
Simplify conditional statements that ask users questions and get answers
seoseonyu Feb 2, 2024
2863b61
set ownership of the temp save directory
seoseonyu Feb 2, 2024
3cf801b
set ownership of the restore work temp directory
seoseonyu Feb 2, 2024
b4568ec
Update restore important comment on README.md
seoseonyu Feb 2, 2024
9072a3a
Update restore description in KR README.md
seoseonyu Feb 2, 2024
428bbc6
Fix README.md lint
seoseonyu Feb 2, 2024
a15b0a9
Update restore command in README.md
seoseonyu Feb 2, 2024
e2cb18c
Update restore command in docs/kr/README.md
seoseonyu Feb 2, 2024
51c8586
Update restore description in README.md
seoseonyu Feb 2, 2024
860323b
Update restore description in docs/kr README.md
seoseonyu Feb 2, 2024
6efba6c
Add disclaimer in restore command
seoseonyu Feb 2, 2024
66fd42c
Merge branch 'main' into add-resotre
seoseonyu Feb 2, 2024
d52fab0
Change restore descript title in README
seoseonyu Feb 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ ENV SUPERCRONIC_URL=https://github.com/aptible/supercronic/releases/download/v0.
SUPERCRONIC_SHA1SUM=cd48d45c4b10f3f0bfdd3a57d054cd05ac96812b

RUN wget -q "$SUPERCRONIC_URL" \
&& echo "${SUPERCRONIC_SHA1SUM} ${SUPERCRONIC}" | sha1sum -c - \
&& chmod +x "$SUPERCRONIC" \
&& mv "$SUPERCRONIC" "/usr/local/bin/${SUPERCRONIC}" \
&& ln -s "/usr/local/bin/${SUPERCRONIC}" /usr/local/bin/supercronic
&& echo "${SUPERCRONIC_SHA1SUM} ${SUPERCRONIC}" | sha1sum -c - \
&& chmod +x "$SUPERCRONIC" \
&& mv "$SUPERCRONIC" "/usr/local/bin/${SUPERCRONIC}" \
&& ln -s "/usr/local/bin/${SUPERCRONIC}" /usr/local/bin/supercronic

ENV PORT= \
PUID=1000 \
Expand Down Expand Up @@ -50,9 +50,11 @@ ENV PORT= \
AUTO_UPDATE_WARN_MINUTES=30

COPY ./scripts/* /home/steam/server/
RUN chmod +x /home/steam/server/init.sh /home/steam/server/start.sh /home/steam/server/backup.sh /home/steam/server/update.sh && \

RUN chmod +x /home/steam/server/init.sh /home/steam/server/start.sh /home/steam/server/backup.sh /home/steam/server/update.sh /home/steam/server/restore.sh && \
mv /home/steam/server/backup.sh /usr/local/bin/backup && \
mv /home/steam/server/update.sh /usr/local/bin/update
mv /home/steam/server/update.sh /usr/local/bin/update && \
mv /home/steam/server/restore.sh /usr/local/bin/restore

WORKDIR /home/steam/server

Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,21 @@ This will create a backup at `/palworld/backups/`

The server will run a save before the backup if rcon is enabled.

## Restore a backup

To restore a backup, use the command:

```bash
docker exec palworld-server restore
seoseonyu marked this conversation as resolved.
Show resolved Hide resolved
```

The `RCON_ENABLED` environment variable must be set to `true` to use this command.
> [!IMPORTANT]
> If docker restart is not set to policy `always` or `unless-stopped` then the server will shutdown and will need to be
> manually restarted.
>
> The example docker run command and docker compose file in [How to Use](#how-to-use) already uses the needed policy

## Configuring Automatic Backups with Cron

The server is automatically backed up everynight at midnight according to the timezone set with TZ
Expand Down
25 changes: 20 additions & 5 deletions docs/kr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@

[English](/README.md) | [한국어](/docs/kr/README.md) | [简体中文](/docs/zh-CN/README.md)

> [!Tip]
> [!TIP]
> 어떻게 시작해야 할지 모르시나요? [제가 작성한 이 가이드](https://tice.tips/containerization/palworld-server-docker/)를 확인해 보세요

[Palworld](https://store.steampowered.com/app/1623730/Palworld/) 전용 서버 호스팅을 시작하는 데 도움이 되는 Docker 컨테이너입니다.

이 도커 컨테이너는 테스트되었으며 Linux(Ubuntu/Debian), Windows 10 및 macOS (Apple Silicon 포함) 모두에서 작동합니다.

> [!Important]
> [!IMPORTANT]
> 현재 Xbox Gamepass/Xbox 콘솔 플레이어는 전용 서버에 참여할 수 없습니다.
>
> 초대 코드를 통해 다른 플레이어들과 함께 게임을 즐길 수 있으며, 게임은 최대 4명의 플레이어로 제한됩니다.
Expand Down Expand Up @@ -188,7 +188,7 @@ docker exec -it palworld-server rcon-cli

## 백업 만들기

현재 시점의 게임 세이브 백업을 생성하려면 다음 명령을 사용합니다.
현재 시점의 게임 세이브 백업을 생성하려면 다음 명령을 사용합니다:

```bash
docker exec palworld-server backup
Expand All @@ -198,11 +198,26 @@ docker exec palworld-server backup

rcon이 활성화된 경우 서버는 백업 전에 저장을 실행합니다.

## 백업 복원 하기

백업을 복원하려면 다음 명령을 사용합니다:

```bash
docker exec palworld-server restore
seoseonyu marked this conversation as resolved.
Show resolved Hide resolved
```

복원 명령어를 사용하려면 `RCON_ENABLED` 환경 변수가 `true`여야 합니다.

> [!IMPORTANT]
> 도커 `restart` 정책이 `always` 또는 `unless-stopped`로 설정 되어있지 않다면 복원 이후 컨테이너가 종료되므로 수동으로 재시작 해야 합니다.
>
> [사용하기](#사용하기)에서 제공된 Docker 실행 명령어와 Docker Compose 파일 예시는 이미 필요한 정책을 적용하고 있습니다.

## 서버 설정 편집

### 환경 변수 사용 설정

> [!Important]
> [!IMPORTANT]
>
> 게임이 아직 베타버전이므로 이러한 환경 변수/설정은 변경될 수 있습니다

Expand Down Expand Up @@ -276,7 +291,7 @@ rcon이 활성화된 경우 서버는 백업 전에 저장을 실행합니다.

서버 설정에 대한 자세한 설명 목록을 보려면 다음을 참조하세요: [shockbyte](https://shockbyte.com/billing/knowledgebase/1189/How-to-Configure-your-Palworld-server.html)

> [!Tip]
> [!TIP]
> 만약 `<mount_folder>/Pal/Saved/Config/LinuxServer/PalWorldSettings.ini` 파일 내부가 비어 있으면,
> 파일을 삭제하고 서버를 다시 시작하면 콘텐츠가 포함된 새 파일이 생성됩니다.

Expand Down
8 changes: 8 additions & 0 deletions scripts/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,11 @@ if [ "${#backup_pids[@]}" -ne 0 ]; then
tail --pid="$pid" -f 2>/dev/null
done
fi

mapfile -t restore_pids < <(pgrep restore)
if [ "${#restore_pids[@]}" -ne 0 ]; then
echo "Waiting for restore to finish"
for pid in "${restore_pids[@]}"; do
tail --pid="$pid" -f 2>/dev/null
done
fi
125 changes: 125 additions & 0 deletions scripts/restore.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#!/bin/bash

# Backup file directory path
BACKUP_DIRECTORY_PATH="/palworld/backups"

# Resotre path
RESTORE_PATH="/palworld/Pal"

# Copy the save file before restore temporary path
TMP_SAVE_PATH="/palworld/backups/restore-"$(date +"%Y-%m-%d_%H-%M-%S")

# shellcheck disable=SC2317
term_error_handler() {
echo "An error occurred during server shutdown."
exit 1
}

# shellcheck disable=SC2317
restore_error_handler() {
printf "\033[0;31mAn error occurred during restore.\033[0m\n"
if [ -d "$TMP_SAVE_PATH/Saved" ]; then
read -rp "I have a backup before recovery can proceed. Do you want to recovery it? (y/n): " RUN_ANSWER
if [[ ${RUN_ANSWER,,} == "y" ]]; then
rm -rf "$RESTORE_PATH/Saved"
mv "$TMP_SAVE_PATH/Saved" "$RESTORE_PATH"
printf "\e[0;32mRecovery complete.\e[0m\n"
fi
fi

echo "Clean up the temporary directory."
rm -rf "$TMP_PATH" "$TMP_SAVE_PATH"

exit 1
}

if [ "${RCON_ENABLED}" != true ]; then
echo "RCON is not enabled. Please enable RCON to use this feature."
exit 1
fi

# Show up backup list
echo "Backup List:"
mapfile -t BACKUP_FILES < <(find "$BACKUP_DIRECTORY_PATH" -type f -name "*.tar.gz" | sort)
select BACKUP_FILE in "${BACKUP_FILES[@]}"; do
if [ -n "$BACKUP_FILE" ]; then
echo "Selected backup: $BACKUP_FILE"
break
else
echo "Invalid selection. Please try again."
fi
done

if [ -f "$BACKUP_FILE" ]; then
echo "Do you want to continue with the command?"
read -rp "When you run it, the server will be stopped and the recovery will proceed. (y/n): " RUN_ANSWER
if [[ ${RUN_ANSWER,,} == "y" ]]; then
printf "\e[0;32m*****STARTING PROCESS*****\e[0m\n"
# Shutdown server
trap 'term_error_handler' ERR

if [ "${RCON_ENABLED}" = true ]; then
printf "\e[0;32m*****SHUTDOWN SERVER*****\e[0m\n"
rcon-cli -c /home/steam/server/rcon.yaml save
rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1"
else
echo "RCON is not enabled. Please enable RCON to use this feature. Unable to restore backup."
exit 1
fi
printf "\e[0;32mShutdown complete.\e[0m\n"

trap - ERR

trap 'restore_error_handler' ERR

printf "\e[0;32m*****START RESTORE*****\e[0m\n"

# Recheck the backup file
if [ -f "$BACKUP_FILE" ]; then
# Copy the save file before restore
if [ -d "$RESTORE_PATH/Saved" ]; then
echo "Saves the current state before the restore proceeds."
echo "$TMP_SAVE_PATH"
mkdir -p "$TMP_SAVE_PATH"
seoseonyu marked this conversation as resolved.
Show resolved Hide resolved
if [ "$(id -u)" -eq 0 ]; then
chown steam:steam "$TMP_SAVE_PATH"
fi
\cp -rf "$RESTORE_PATH/Saved" "$TMP_SAVE_PATH/Saved"

while [ ! -d "$TMP_SAVE_PATH/Saved" ]; do
sleep 1
done

printf "\e[0;32mSave complete.\e[0m\n"
fi

# Create tmp directory
TMP_PATH=$(mktemp -d -p "/palworld/backups")
seoseonyu marked this conversation as resolved.
Show resolved Hide resolved
if [ "$(id -u)" -eq 0 ]; then
chown steam:steam "$TMP_PATH"
fi

# Decompress the backup file in tmp directory
tar -zxvf "$BACKUP_FILE" -C "$TMP_PATH"

# Move the backup file to the restore directory
\cp -rf -f "$TMP_PATH/Saved/" "$RESTORE_PATH"

echo "Clean up the temporary directory."
rm -rf "$TMP_PATH" "$TMP_SAVE_PATH"

printf "\e[0;32mRestore complete!!!! Please restart the Docker container\e[0m\n"

exit 0
else
echo "The selected backup file does not exist."
exit 1
fi
else
echo "Abort the recovery."
exit 1
fi
else
echo "The selected backup file does not exist."
exit 1
fi