Skip to content

Commit

Permalink
add flexibility to backup messages
Browse files Browse the repository at this point in the history
  • Loading branch information
thijsvanloef committed Mar 6, 2024
1 parent d65134d commit 27c62f6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,21 @@ ENV HOME=/home/steam \
DISCORD_PLAYER_LEAVE_MESSAGE="\${player_name} has left Palworld." \
DISCORD_PLAYER_LEAVE_MESSAGE_URL= \
DISCORD_PLAYER_LEAVE_MESSAGE_ENABLED=true \
DISCORD_PRE_BACKUP_MESSAGE="Creating backup..." \
DISCORD_PRE_BACKUP_MESSAGE_URL= \
DISCORD_PRE_BACKUP_MESSAGE_ENABLED=true \
DISCORD_POST_BACKUP_MESSAGE="Backup created at \${FILE_PATH}" \
DISCORD_POST_BACKUP_MESSAGE_URL= \
DISCORD_POST_BACKUP_MESSAGE_ENABLED=true \
DISCORD_PRE_BACKUP_DELETE_MESSAGE="Removing backups older than \${OLD_BACKUP_DAYS} days" \
DISCORD_PRE_BACKUP_DELETE_URL= \
DISCORD_PRE_BACKUP_DELETE_ENABLED=true \
DISCORD_POST_BACKUP_DELETE_MESSAGE="Removed backups older than \${OLD_BACKUP_DAYS} days" \
DISCORD_POST_BACKUP_DELETE_URL= \
DISCORD_POST_BACKUP_DELETE_ENABLED=true \
DISCORD_ERR_BACKUP_DELETE_MESSAGE="Unable to delete old backups, OLD_BACKUP_DAYS is not an integer. OLD_BACKUP_DAYS=\${OLD_BACKUP_DAYS}" \
DISCORD_ERR_BACKUP_DELETE_URL= \
DISCORD_ERR_BACKUP_DELETE_ENABLED=true \
ENABLE_PLAYER_LOGGING=true \
PLAYER_LOGGING_POLL_PERIOD=5 \
ARM_COMPATIBILITY_MODE=false \
Expand Down
10 changes: 5 additions & 5 deletions scripts/backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# shellcheck source=scripts/helper_functions.sh
source "/home/steam/server/helper_functions.sh"

DiscordMessage "Backup" "Creating backup..." "in-progress"
DiscordMessage "Backup" "${DISCORD_PRE_BACKUP_MESSAGE}" "in-progress" "${DISCORD_PRE_BACKUP_MESSAGE_ENABLED}" "${DISCORD_PRE_BACKUP_MESSAGE_URL}"
if [ "${RCON_ENABLED,,}" = true ]; then
save_server
fi
Expand All @@ -18,7 +18,7 @@ if [ "$(id -u)" -eq 0 ]; then
chown steam:steam "$FILE_PATH"
fi
LogInfo "Backup created at ${FILE_PATH}"
DiscordMessage "Backup" "Backup created at ${FILE_PATH}" "success"
DiscordMessage "Backup" "${DISCORD_POST_BACKUP_MESSAGE//\$\{FILE_PATH\}/${FILE_PATH}}" "success" "${DISCORD_POST_BACKUP_MESSAGE_ENABLED}" "${DISCORD_POST_BACKUP_MESSAGE_URL}"

if [ "${DELETE_OLD_BACKUPS,,}" != true ]; then
exit 0
Expand All @@ -33,11 +33,11 @@ fi
if [[ "${OLD_BACKUP_DAYS}" =~ ^[0-9]+$ ]]; then
LogAction "Removing Old Backups"
LogInfo "Removing backups older than ${OLD_BACKUP_DAYS} days"
DiscordMessage "Backup" "Removing backups older than ${OLD_BACKUP_DAYS} days..." "in-progress"
DiscordMessage "Backup" "${DISCORD_PRE_BACKUP_DELETE_MESSAGE//\$\{FILE_PATH\}/${FILE_PATH}}" "in-progress" "${DISCORD_PRE_BACKUP_DELETE_MESSAGE_ENABLED}" "${DISCORD_PRE_BACKUP_DELETE_MESSAGE_URL}"
find /palworld/backups/ -mindepth 1 -maxdepth 1 -mtime "+${OLD_BACKUP_DAYS}" -type f -name 'palworld-save-*.tar.gz' -print -delete
DiscordMessage "Backup" "Removed backups older than ${OLD_BACKUP_DAYS} days" "success"
DiscordMessage "Backup" "${DISCORD_POST_BACKUP_DELETE_MESSAGE//\$\{FILE_PATH\}/${FILE_PATH}}" "success" "${DISCORD_POST_BACKUP_DELETE_MESSAGE_ENABLED}" "${DISCORD_POST_BACKUP_DELETE_MESSAGE_URL}"
exit 0
fi

LogError "Unable to delete old backups, OLD_BACKUP_DAYS is not an integer. OLD_BACKUP_DAYS=${OLD_BACKUP_DAYS}"
DiscordMessage "Backup" "Unable to delete old backups, OLD_BACKUP_DAYS is not an integer. OLD_BACKUP_DAYS=${OLD_BACKUP_DAYS}" "failure"
DiscordMessage "Backup" "${DISCORD_ERR_BACKUP_DELETE_MESSAGE//\$\{OLD_BACKUP_DAYS\}/${OLD_BACKUP_DAYS}}}" "failure" "${DISCORD_ERR_BACKUP_DELETE_MESSAGE_ENABLED}" "${DISCORD_ERR_BACKUP_DELETE_MESSAGE_URL}"

0 comments on commit 27c62f6

Please sign in to comment.