mirror of
https://github.com/fradelg/docker-mysql-cron-backup.git
synced 2025-01-18 16:22:33 +01:00
Delete strategy moved to new file, as could custom
This commit is contained in:
parent
3011a8770a
commit
ee27961c60
3 changed files with 10 additions and 9 deletions
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -46,13 +46,7 @@ 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" ]
|
exec /delete.sh
|
||||||
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
|
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
rm -rf "$FILENAME"
|
rm -rf "$FILENAME"
|
||||||
|
|
7
delete.sh
Executable file
7
delete.sh
Executable file
|
@ -0,0 +1,7 @@
|
||||||
|
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
|
Loading…
Reference in a new issue