diff --git a/Dockerfile b/Dockerfile index 450a473..2018425 100644 --- a/Dockerfile +++ b/Dockerfile @@ -60,6 +60,8 @@ ENV DEBIAN_FRONTEND=noninteractive \ COMMUNITY_SERVER=true \ BACKUP_ENABLED=true \ BACKUP_CRON_EXPRESSION="0 * * * *" \ + BACKUP_RETENTION_POLICY=false \ + BACKUP_RETENTION_AMOUNT_TO_KEEP=30 \ STEAMCMD_VALIDATE_FILES=true \ SERVER_SETTINGS_MODE=auto \ # Server-setting diff --git a/README.md b/README.md index a86fa71..b4bf55d 100644 --- a/README.md +++ b/README.md @@ -86,16 +86,18 @@ These settings control the behavior of the Docker container: > If you want to change the server settings via environment variables use the default value (`auto`) for the environment variable `SERVER_SETTINGS_MODE`, otherwise change it to `manual` and edit the config file directly. -| Variable | Description | Default value | Allowed values | -| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| TZ | Timezone used for time stamping server backups | Europe/Berlin | See [TZ identifiers](#tz-identifiers) | -| ALWAYS_UPDATE_ON_START | Updates the server on startup | true | false/true | -| MULTITHREAD_ENABLED | Sets options for "Improved multi-threaded CPU performance" | true | false/true | -| COMMUNITY_SERVER | Set to enabled, the server will appear in the Community-Serverlist. | true | false/true | -| BACKUP_ENABLED | Backup function, creates backups in your `game` directory | true | false/true | -| BACKUP_CRON_EXPRESSION | Needs a Cron-Expression - See [Cron expression](#cron-expression) | 0 * * * * (meaning every hour) | Cron-Expression | -| SERVER_SETTINGS_MODE | Determines whether settings can be modified via environment variables or via file, except `COMMUNITY_SERVER` and `MULTITHREAD_ENABLED`! | `auto` | `auto`: Settings are modified only by environment variables, manual edits will be ignored
`manual`: Settings are modified only by editing the file directly, environment variables are ignored | -| STEAMCMD_VALIDATE_FILES | Set to enabled SteamCMD will also validate the gameserver files, making sure nothing is corrupted and also overwrite any file changes of the source
See https://developer.valvesoftware.com/wiki/SteamCMD#Downloading_an_App | true | false/true | +| Variable | Description | Default value | Allowed values | +| ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| TZ | Timezone used for time stamping server backups | Europe/Berlin | See [TZ identifiers](#tz-identifiers) | +| ALWAYS_UPDATE_ON_START | Updates the server on startup | true | false/true | +| MULTITHREAD_ENABLED | Sets options for "Improved multi-threaded CPU performance" | true | false/true | +| COMMUNITY_SERVER | Set to enabled, the server will appear in the Community-Serverlist. | true | false/true | +| BACKUP_ENABLED | Backup function, creates backups in your `game` directory | true | false/true | +| BACKUP_CRON_EXPRESSION | Needs a Cron-Expression - See [Cron expression](#cron-expression) | 0 * * * * (meaning every hour) | Cron-Expression | +| BACKUP_RETENTION_POLICY | Set to enabled, will cleanup old backups | false | false/true | +| BACKUP_RETENTION_AMOUNT_TO_KEEP | Defines how many backups in numbers to keep | 30 | Integer | +| SERVER_SETTINGS_MODE | Determines whether settings can be modified via environment variables or via file, except `COMMUNITY_SERVER` and `MULTITHREAD_ENABLED`! | `auto` | `auto`: Settings are modified only by environment variables, manual edits will be ignored
`manual`: Settings are modified only by editing the file directly, environment variables are ignored | +| STEAMCMD_VALIDATE_FILES | Set to enabled SteamCMD will also validate the gameserver files, making sure nothing is corrupted and also overwrite any file changes of the source
See https://developer.valvesoftware.com/wiki/SteamCMD#Downloading_an_App | true | false/true | ### TZ identifiers @@ -212,6 +214,8 @@ services: - COMMUNITY_SERVER=true - BACKUP_ENABLED=true - BACKUP_CRON_EXPRESSION=0 * * * * + - BACKUP_RETENTION_POLICY=false + - BACKUP_RETENTION_AMOUNT_TO_KEEP=30 - STEAMCMD_VALIDATE_FILES=true - SERVER_SETTINGS_MODE=auto # Change this to manual if you want to edit the config yourself - NETSERVERMAXTICKRATE=120 diff --git a/backupmanager.sh b/backupmanager.sh index 060f71e..43a28a3 100644 --- a/backupmanager.sh +++ b/backupmanager.sh @@ -3,16 +3,24 @@ DATE=$(date +%Y%m%d_%H%M%S) TIME=$(date +%H-%M-%S) +mkdir -p /palworld/backups +if [[ -n $BACKUP_RETENTION_POLICY ]] && [[ $BACKUP_RETENTION_POLICY == "true" ]]; then + cd /palworld/backups + echo ">>> The Backup retention policy is enabled" + echo "> Keeping latest $BACKUP_RETENTION_AMOUNT_TO_KEEP backups" + ls -1t saved-*.tar.gz | tail -n +$(($BACKUP_RETENTION_AMOUNT_TO_KEEP + 1)) | xargs -d '\n' rm -f -- + echo ">>> Cleanup finished" +fi echo ">>> Creating backup" echo "> Sending message to gameserver" cd ~/steamcmd/ -rconcli "broadcast $TIME-Backup_in_progress" +rconcli "broadcast $TIME-Backup-in-progress" sleep 1 rconcli 'broadcast Saving...' rconcli 'save' rconcli 'broadcast Done...' sleep 15 # Create backup dir and change into it -mkdir -p /palworld/backups && cd /palworld/Pal +cd /palworld/Pal tar cfz /palworld/backups/saved-$DATE.tar.gz Saved/ echo ">>> Done" diff --git a/servermanager.sh b/servermanager.sh index 86b7d01..e0d01ac 100755 --- a/servermanager.sh +++ b/servermanager.sh @@ -369,14 +369,17 @@ function checkForDefaultCredentials() { fi } -function startMain() { - checkForDefaultCredentials +function setupCrons() { + touch cronlist if [[ -n $BACKUP_ENABLED ]] && [[ $BACKUP_ENABLED == "true" ]]; then - # Preparing the cronlist file echo "$BACKUP_CRON_EXPRESSION /backupmanager.sh" >> cronlist - # Making sure supercronic is enabled and the cronfile is loaded - /usr/local/bin/supercronic cronlist & fi + /usr/local/bin/supercronic cronlist & +} + +function startMain() { + checkForDefaultCredentials + setupCrons # Check if server is installed, if not try again if [ ! -f "$GAME_PATH/PalServer.sh" ]; then installServer