Skip to content

Commit

Permalink
Merge pull request #194 from Dashboy1998/cron-backup
Browse files Browse the repository at this point in the history
Cron backup
  • Loading branch information
thijsvanloef authored Jan 29, 2024
2 parents 19fdc72 + 8900fc7 commit 61b816c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
15 changes: 14 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ RUN wget -q https://github.com/gorcon/rcon-cli/releases/download/v0.10.3/rcon-0.
mv rcon-0.10.3-amd64_linux/rcon /usr/bin/rcon-cli && \
rmdir /tmp/dumps

# Latest releases available at https://github.com/aptible/supercronic/releases
ENV SUPERCRONIC_URL=https://github.com/aptible/supercronic/releases/download/v0.2.29/supercronic-linux-amd64 \
SUPERCRONIC=supercronic-linux-amd64 \
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

ENV PORT= \
PUID=1000 \
PGID=1000 \
Expand All @@ -29,7 +40,9 @@ ENV PORT= \
RCON_PORT=25575 \
QUERY_PORT=27015 \
TZ=UTC \
SERVER_DESCRIPTION=
SERVER_DESCRIPTION= \
BACKUP_ENABLED=true \
BACKUP_CRON_EXPRESSION="0 0 * * *"

COPY ./scripts/* /home/steam/server/
RUN chmod +x /home/steam/server/init.sh /home/steam/server/start.sh /home/steam/server/backup.sh && \
Expand Down
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ It is highly recommended you set the following environment values before startin
| RCON_ENABLED*** | Enable RCON for the Palworld server | true | true/false |
| RCON_PORT | RCON port to connect to | 25575 | 1024-65535 |
| QUERY_PORT | Query port used to communicate with Steam servers | 27015 | 1024-65535 |
| BACKUP_CRON_EXPRESSION | Setting affects frequency of automatic backups. | 0 0 \* \* \* | Needs a Cron-Expression - See [Configuring Automatic Backups with Cron](#configuring-automatic-backups-with-cron) |
| BACKUP_ENABLED | Enables automatic backups | true | true/false |
| DELETE_OLD_BACKUPS | Delete backups after a certain number of days | false | true/false |
| OLD_BACKUP_DAYS | How many days to keep backups | 30 | any positive integer |

Expand Down Expand Up @@ -204,6 +206,23 @@ This will create a backup at `/palworld/backups/`

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

## Configuring Automatic Backups with Cron

The server is automatically backed up everynight at midnight according to the timezone set with TZ

Set BACKUP_ENABLED enable or disable automatic backups (Default is enabled)

BACKUP_CRON_EXPRESSION is a cron expression, in a Cron-Expression you define an interval for when to run jobs.

> [!TIP]
> This image uses Supercronic for crons
> see [supercronic](https://github.com/aptible/supercronic#crontab-format)
> or
> [Crontab Generat](https://crontab-generator.org).
Set BACKUP_CRON_EXPRESSION to change the default schedule.
Example Usage: If BACKUP_CRON_EXPRESSION to `0 2 * * *`, the backup script will run every day at 2:00 AM.

## Editing Server Settings

### With Environment Variables
Expand Down
2 changes: 1 addition & 1 deletion scripts/backup.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

if [ "${RCON_ENABLED}" = true ]; then
rcon-cli save
rcon-cli -c /home/steam/server/rcon.yaml save
fi

DATE=$(date +"%Y-%m-%d_%H-%M-%S")
Expand Down
7 changes: 7 additions & 0 deletions scripts/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,13 @@ if [ -n "${RCON_PORT}" ]; then
sed -i "s/RCONPort=[0-9]*/RCONPort=$RCON_PORT/" /palworld/Pal/Saved/Config/LinuxServer/PalWorldSettings.ini
fi

if [ "${BACKUP_ENABLED}" = true ]; then
echo "BACKUP_ENABLED=${BACKUP_ENABLED}"

echo "$BACKUP_CRON_EXPRESSION bash /usr/local/bin/backup" > "/home/steam/server/crontab"
supercronic "/home/steam/server/crontab" &
fi

# Configure RCON settings
cat >/home/steam/server/rcon.yaml <<EOL
default:
Expand Down

0 comments on commit 61b816c

Please sign in to comment.