Skip to content

Commit

Permalink
Merge pull request thijsvanloef#1 from GuillaumeBarreau/feat_backup_w…
Browse files Browse the repository at this point in the history
…ith_cron

feat: ✨ Add Cron command to Dockerfile.
  • Loading branch information
GuillaumeBarreau authored Jan 25, 2024
2 parents aaf8ef5 + 9868ce7 commit 07ecd58
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 2 deletions.
Binary file added .DS_Store
Binary file not shown.
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
xdg-user-dirs=0.17-2 \
procps=2:3.3.17-5 \
wget=1.21-1+deb11u1 \
&& apt-get install -y cron \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

RUN wget -q https://github.com/itzg/rcon-cli/releases/download/1.6.4/rcon-cli_1.6.4_linux_amd64.tar.gz -O - | tar -xz
RUN mv rcon-cli /usr/bin/rcon-cli

RUN rm -f /var/run/crond.pid
COPY ./scripts/backup.sh /usr/local/bin/backup
RUN chmod +x /usr/local/bin/backup
RUN echo "0 3 * * * root bash /usr/local/bin/backup" > /etc/cron.d/backups-cron
RUN chmod 0644 /etc/cron.d/backups-cron

ENV PORT= \
PUID=1000 \
PGID=1000 \
Expand Down
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,25 @@ docker exec palworld-server backup

This will create a backup at `/palworld/backups/`

## Setting Up Automatic Backups with Cron

This section guides you through the process of configuring automatic backups using Cron. Use the provided command to set up the necessary Cron job for your Palworld server within a Docker environment.

The configured backup system automatically deletes backups older than 7 days to manage storage efficiently.

```bash
docker exec palworld-server cron /etc/cron.d/backups-cron

```

Additionally, to stop the cron process within the Docker container, you can use the following command:

```bash
docker exec palworld-server service cron stop
```

This command stops the cron service within the specified container, halting the scheduled cron job.

## Editing Server Settings

When the server starts, a `PalWorldSettings.ini` file will be created in the following location: `<mount_folder>/Pal/Saved/Config/LinuxServer/PalWorldSettings.ini`
Expand Down
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
services:
palworld:
image: thijsvanloef/palworld-server-docker:latest
image: test/palworld-server-docker:latest
build: .
restart: unless-stopped
container_name: palworld-server
ports:
Expand Down
13 changes: 12 additions & 1 deletion scripts/backup.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
#!/bin/bash

printf "\e[0;34m***** RUNNING SCRIPTS backup.sh *****\e[0m\n"

DATE=$(date +"%Y-%m-%d_%H-%M-%S")
FILE_PATH="/palworld/backups/palworld-save-${DATE}.tar.gz"
DESTINATION_PATH="/palworld/backups"
FILE_PATH="${DESTINATION_PATH}/backup_palworld_${DATE}.tar.gz"

if [ ! -f ${FILE_PATH} ]; then
printf "\e[0;32m***** CREATING BACKUPS FOLDER *****\e[0m\n"
mkdir -p "${DESTINATION_PATH}"
fi

cd /palworld/Pal/ || exit

tar -zcf "$FILE_PATH" "Saved/"
echo "backup created at $FILE_PATH"

find "${DESTINATION_PATH}" -type f -name "backup_palworld_*.tar.gz" -ctime +7 -exec rm -f {} \;
2 changes: 2 additions & 0 deletions scripts/init.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

printf "\e[0;34m***** RUNNING SCRIPTS init.sh *****\e[0m\n"

if [[ ! "${PUID}" -eq 0 ]] && [[ ! "${PGID}" -eq 0 ]]; then
printf "\e[0;32m*****EXECUTING USERMOD*****\e[0m\n"
usermod -o -u "${PUID}" steam
Expand Down
2 changes: 2 additions & 0 deletions scripts/start.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

printf "\e[0;34m***** RUNNING SCRIPTS start.sh *****\e[0m\n"

STARTCOMMAND="./PalServer.sh"

if [ -n "${PORT}" ]; then
Expand Down

0 comments on commit 07ecd58

Please sign in to comment.