Skip to content

Commit

Permalink
Delete strategy moved to new file, as could custom
Browse files Browse the repository at this point in the history
  • Loading branch information
g-nardiello committed Jan 6, 2023
1 parent 3011a87 commit 6b6656c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ ENV CRON_TIME="0 3 * * sun" \
TIMEOUT="10s" \
MYSQLDUMP_OPTS="--quick"

COPY ["run.sh", "backup.sh", "restore.sh", "/"]
COPY ["run.sh", "backup.sh", "restore.sh", "/delete.sh", "/"]
RUN mkdir /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 && \
chmod 666 /mysql_backup.log

Expand Down
9 changes: 2 additions & 7 deletions backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,8 @@ do
cd /backup || exit && ln -s "$BASENAME" "$(basename "$LATEST")"
if [ -n "$MAX_BACKUPS" ]
then
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
# Execute the delete script, delete older backup or other custom delete script
/delete.sh $db $EXT
fi
else
rm -rf "$FILENAME"
Expand Down
14 changes: 14 additions & 0 deletions delete.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6b6656c

Please sign in to comment.