Skip to content

Commit

Permalink
#27 added backup retention policy
Browse files Browse the repository at this point in the history
  • Loading branch information
jammsen committed Jan 30, 2024
1 parent 86e43c0 commit b3d5cfb
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 17 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 14 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<br>`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<br>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<br>`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<br>See https://developer.valvesoftware.com/wiki/SteamCMD#Downloading_an_App | true | false/true |

### TZ identifiers

Expand Down Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions backupmanager.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
13 changes: 8 additions & 5 deletions servermanager.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b3d5cfb

Please sign in to comment.