From 31421a5ec2430c17062d1220fcf96047facd46e2 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Mon, 29 Jan 2024 19:28:22 -0500 Subject: [PATCH 1/6] Changed back so only files are deleted, only backup files, and added su. --- scripts/backup.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/backup.sh b/scripts/backup.sh index 0fd0b6d65..a58d4ac7d 100644 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -18,5 +18,9 @@ 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 [ "$(id -u)" -eq 0 ]; then + su steam -c "find /palworld/backups/ -mindepth 1 -maxdepth 1 -mtime "+${OLD_BACKUP_DAYS}" -type f -name 'palworld-save-*.tar.gz' -print -delete" + else + find /palworld/backups/ -mindepth 1 -maxdepth 1 -mtime "+${OLD_BACKUP_DAYS}" -type f -name 'palworld-save-*.tar.gz' -print -delete + fi fi From 1e214b105878aee567cd202e430a544e1de569b2 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Mon, 29 Jan 2024 20:50:13 -0500 Subject: [PATCH 2/6] Moved default number of days --- Dockerfile | 1 + scripts/backup.sh | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 21a55e18c..c8aed382f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -42,6 +42,7 @@ ENV PORT= \ TZ=UTC \ SERVER_DESCRIPTION= \ BACKUP_ENABLED=true \ + OLD_BACKUP_DAYS=30 \ BACKUP_CRON_EXPRESSION="0 0 * * *" COPY ./scripts/* /home/steam/server/ diff --git a/scripts/backup.sh b/scripts/backup.sh index a58d4ac7d..845dfa762 100644 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -17,7 +17,7 @@ fi echo "backup created at $FILE_PATH" if [ "${DELETE_OLD_BACKUPS}" = true ]; then - echo "removing backups older than ${OLD_BACKUP_DAYS:=30} days" + echo "removing backups older than ${OLD_BACKUP_DAYS} days" if [ "$(id -u)" -eq 0 ]; then su steam -c "find /palworld/backups/ -mindepth 1 -maxdepth 1 -mtime "+${OLD_BACKUP_DAYS}" -type f -name 'palworld-save-*.tar.gz' -print -delete" else From 512cc768dde4d4dcf81ace7943fbc026060e3022 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Mon, 29 Jan 2024 21:14:51 -0500 Subject: [PATCH 3/6] Added default for delete old backup to dockerfile --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index c8aed382f..5092a4a1d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -42,6 +42,7 @@ ENV PORT= \ TZ=UTC \ SERVER_DESCRIPTION= \ BACKUP_ENABLED=true \ + DELETE_OLD_BACKUPS=false \ OLD_BACKUP_DAYS=30 \ BACKUP_CRON_EXPRESSION="0 0 * * *" From 49c69c2e5ca905bf52f05d6031ad4e4e6dd3ff89 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Mon, 29 Jan 2024 21:28:53 -0500 Subject: [PATCH 4/6] Using su doesn't seem to respect permissions or ownership --- scripts/backup.sh | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/scripts/backup.sh b/scripts/backup.sh index 845dfa762..e72555f02 100644 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -18,9 +18,5 @@ echo "backup created at $FILE_PATH" if [ "${DELETE_OLD_BACKUPS}" = true ]; then echo "removing backups older than ${OLD_BACKUP_DAYS} days" - if [ "$(id -u)" -eq 0 ]; then - su steam -c "find /palworld/backups/ -mindepth 1 -maxdepth 1 -mtime "+${OLD_BACKUP_DAYS}" -type f -name 'palworld-save-*.tar.gz' -print -delete" - else - find /palworld/backups/ -mindepth 1 -maxdepth 1 -mtime "+${OLD_BACKUP_DAYS}" -type f -name 'palworld-save-*.tar.gz' -print -delete - fi + find /palworld/backups/ -mindepth 1 -maxdepth 1 -mtime "+${OLD_BACKUP_DAYS}" -type f -name 'palworld-save-*.tar.gz' -print -delete fi From a0ec278bc8ad95e078a5319535ce5171f98f1a10 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Wed, 31 Jan 2024 11:34:07 -0500 Subject: [PATCH 5/6] Added checks for OLD_BACKUP_DAYS --- scripts/backup.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/scripts/backup.sh b/scripts/backup.sh index e72555f02..c96281222 100644 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -17,6 +17,12 @@ fi echo "backup created at $FILE_PATH" if [ "${DELETE_OLD_BACKUPS}" = true ]; 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 + 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 From b75254e7457a98351a5a08adbe6a3fd950d22e9a Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Wed, 31 Jan 2024 11:34:37 -0500 Subject: [PATCH 6/6] Changed 8 spaces to 4 spacing to match other bash scripts in repo --- scripts/backup.sh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/scripts/backup.sh b/scripts/backup.sh index c96281222..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,18 +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 - 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 + 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