Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed backup so only old backup files are deleted #215

Merged
merged 7 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 \
Dashboy1998 marked this conversation as resolved.
Show resolved Hide resolved
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"
Dashboy1998 marked this conversation as resolved.
Show resolved Hide resolved
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