Skip to content

Commit

Permalink
Merge pull request #215 from Dashboy1998/backup-fixes
Browse files Browse the repository at this point in the history
Changed backup so only old backup files are deleted
  • Loading branch information
thijsvanloef authored Jan 31, 2024
2 parents cd0103c + b75254e commit 689674b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 * * * *" \
Expand Down
14 changes: 10 additions & 4 deletions 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 -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")
Expand All @@ -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

0 comments on commit 689674b

Please sign in to comment.