diff --git a/Dockerfile b/Dockerfile index c06ccf7..be861f9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/backup.sh b/backup.sh index 33ff1b1..70f7761 100755 --- a/backup.sh +++ b/backup.sh @@ -46,13 +46,7 @@ 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 + exec /delete.sh fi else rm -rf "$FILENAME" diff --git a/delete.sh b/delete.sh new file mode 100755 index 0000000..59f138c --- /dev/null +++ b/delete.sh @@ -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 \ No newline at end of file