Merge pull request #95 from g-nardiello/feature-custom-delete

[Feature] Get out delete script, to allow custom logics
This commit is contained in:
Fco. Javier Delgado del Hoyo 2023-01-09 20:50:08 +01:00 committed by GitHub
commit 6ef15a2672
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 9 deletions

View file

@ -32,10 +32,10 @@ ENV CRON_TIME="0 3 * * sun" \
TIMEOUT="10s" \ TIMEOUT="10s" \
MYSQLDUMP_OPTS="--quick" MYSQLDUMP_OPTS="--quick"
COPY ["run.sh", "backup.sh", "restore.sh", "/"] COPY ["run.sh", "backup.sh", "restore.sh", "/delete.sh", "/"]
RUN mkdir /backup && \ RUN mkdir /backup && \
chmod 777 /backup && \ chmod 777 /backup && \
chmod 755 /run.sh /backup.sh /restore.sh && \ chmod 755 /run.sh /backup.sh /restore.sh /delete.sh && \
touch /mysql_backup.log && \ touch /mysql_backup.log && \
chmod 666 /mysql_backup.log chmod 666 /mysql_backup.log

View file

@ -46,13 +46,8 @@ do
cd /backup || exit && ln -s "$BASENAME" "$(basename "$LATEST")" cd /backup || exit && ln -s "$BASENAME" "$(basename "$LATEST")"
if [ -n "$MAX_BACKUPS" ] if [ -n "$MAX_BACKUPS" ]
then then
while [ "$(find /backup -maxdepth 1 -name "*.$db.sql$EXT" -type f | wc -l)" -gt "$MAX_BACKUPS" ] # Execute the delete script, delete older backup or other custom delete script
do /delete.sh $db $EXT
TARGET=$(find /backup -maxdepth 1 -name "*.$db.sql$EXT" -type f | sort | head -n 1)
echo "==> Max number of ($MAX_BACKUPS) backups reached. Deleting ${TARGET} ..."
rm -rf "${TARGET}"
echo "==> Backup ${TARGET} deleted"
done
fi fi
else else
rm -rf "$FILENAME" rm -rf "$FILENAME"

14
delete.sh Executable file
View file

@ -0,0 +1,14 @@
#!/bin/bash
db=$1
EXT=$2
# This file could be customized to create custom delete strategy
while [ "$(find /backup -maxdepth 1 -name "*.$db.sql$EXT" -type f | wc -l)" -gt "$MAX_BACKUPS" ]
do
TARGET=$(find /backup -maxdepth 1 -name "*.$db.sql$EXT" -type f | sort | head -n 1)
echo "==> Max number of ($MAX_BACKUPS) backups reached. Deleting ${TARGET} ..."
rm -rf "${TARGET}"
echo "==> Backup ${TARGET} deleted"
done