diff --git a/Dockerfile b/Dockerfile index 5fd8106f0..21a55e18c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 \ @@ -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 && \ diff --git a/README.md b/README.md index c35fb7301..daa615ad6 100644 --- a/README.md +++ b/README.md @@ -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 | @@ -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 diff --git a/scripts/backup.sh b/scripts/backup.sh index 707df6ce0..0fd0b6d65 100644 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -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") diff --git a/scripts/start.sh b/scripts/start.sh index 3ad3564b0..40edf2ff8 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -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 <