diff --git a/Dockerfile b/Dockerfile index acaf6c779..40d18c98d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -42,6 +42,8 @@ ENV PORT= \ TZ=UTC \ SERVER_DESCRIPTION= \ BACKUP_ENABLED=true \ + DELETE_OLD_BACKUPS=false \ + OLD_BACKUP_DAYS=30 \ BACKUP_CRON_EXPRESSION="0 0 * * *" \ AUTO_UPDATE_ENABLED=false \ AUTO_UPDATE_CRON_EXPRESSION="0 * * * *" \ diff --git a/scripts/backup.sh b/scripts/backup.sh index 0fd0b6d65..3f7c845fd 100644 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -1,7 +1,7 @@ #!/bin/bash if [ "${RCON_ENABLED}" = true ]; then - rcon-cli -c /home/steam/server/rcon.yaml save + rcon-cli -c /home/steam/server/rcon.yaml save fi DATE=$(date +"%Y-%m-%d_%H-%M-%S") @@ -11,12 +11,18 @@ cd /palworld/Pal/ || exit tar -zcf "$FILE_PATH" "Saved/" if [ "$(id -u)" -eq 0 ]; then - chown steam:steam "$FILE_PATH" + chown steam:steam "$FILE_PATH" fi echo "backup created at $FILE_PATH" if [ "${DELETE_OLD_BACKUPS}" = true ]; then - echo "removing backups older than ${OLD_BACKUP_DAYS:=30} days" - find /palworld/backups/ -mindepth 1 -maxdepth 1 -mtime "+${OLD_BACKUP_DAYS}" -print -delete + if [ -z "${OLD_BACKUP_DAYS}" ]; then + echo "Unable to deleted old backups, OLD_BACKUP_DAYS is empty." + elif [[ "${OLD_BACKUP_DAYS}" =~ ^[0-9]+$ ]]; then + echo "removing backups older than ${OLD_BACKUP_DAYS} days" + find /palworld/backups/ -mindepth 1 -maxdepth 1 -mtime "+${OLD_BACKUP_DAYS}" -type f -name 'palworld-save-*.tar.gz' -print -delete + else + echo "Unable to deleted old backups, OLD_BACKUP_DAYS is not an integer. OLD_BACKUP_DAYS=${OLD_BACKUP_DAYS}" + fi fi