feat: Add variables Env for cron feature

This commit is contained in:
Guillaume Barreau
2024-01-25 07:09:30 -05:00
parent 735ae33392
commit 918c32c623
6 changed files with 56 additions and 25 deletions

View File

@@ -1,13 +1,11 @@
#!/bin/bash
printf "\e[0;34m***** RUNNING SCRIPTS backup.sh *****\e[0m\n"
DATE=$(date +"%Y-%m-%d_%H-%M-%S")
DESTINATION_PATH="/palworld/backups"
FILE_PATH="${DESTINATION_PATH}/backup_palworld_${DATE}.tar.gz"
if [ ! -f ${FILE_PATH} ]; then
printf "\e[0;32m***** CREATING BACKUPS FOLDER *****\e[0m\n"
echo "\e[0;32m***** CREATING BACKUPS FOLDER *****\e[0m\n"
mkdir -p "${DESTINATION_PATH}"
fi
@@ -16,4 +14,11 @@ cd /palworld/Pal/ || exit
tar -zcf "$FILE_PATH" "Saved/"
echo "backup created at $FILE_PATH"
find "${DESTINATION_PATH}" -type f -name "backup_palworld_*.tar.gz" -ctime +7 -exec rm -f {} \;
if [[ -n "${DAYS_TO_KEEP}" && "${DAYS_TO_KEEP}" =~ ^[0-9]+$ ]]; then
echo "DAYS_TO_KEEP=${DAYS_TO_KEEP}"
find "${DESTINATION_PATH}" -type f -mtime +"${DAYS_TO_KEEP}" -exec rm {} \;
else
echo "DAYS_TO_KEEP is not a valid number."
fi