#!/bin/bash

# Anzahl der Sicherungen die aufgehoben werden sollen
KEEP=56
BACKUPS=`find /volume1/Backups/hour -name "MariaDBDump_*.gz" | wc -l | sed 's/\ //g'`
while [ $BACKUPS -ge $KEEP ]
do
ls -tr1 /volume1/Backups/hour/MariaDBDump_*.gz | head -n 1 | xargs rm -f 
BACKUPS=`expr $BACKUPS - 1` 
done
DATE=`date +%Y_%m_%d__%H_%M`
rm -f /volume1/Backups/hour/.MariaDBDump_${DATE}.gz_INPROGRESS
/volume1/@appstore/MariaDB10/usr/local/mariadb10/bin/mysqldump --opt -uroot -p'SecretEisock!22' --all-databases | gzip -c -9 > /volume1/Backups/hour/.MariaDBDump_${DATE}.gz_INPROGRESS
mv -f /volume1/Backups/hour/.MariaDBDump_${DATE}.gz_INPROGRESS /volume1/Backups/hour/MariaDBDump_${DATE}.gz
exit 0