[Helper] New parameter --delete-days to delete backups older than n days

master
andryyy 2019-10-23 21:41:19 +02:00
parent cd6594df01
commit ccd9d934d6
No known key found for this signature in database
GPG Key ID: 8EC34FF2794E25EF
1 changed files with 10 additions and 2 deletions

View File

@ -9,8 +9,8 @@ if [[ ! ${1} =~ (backup|restore) ]]; then
exit 1
fi
if [[ ${1} == "backup" && ! ${2} =~ (crypt|vmail|redis|rspamd|postfix|mysql|all) ]]; then
echo "Second parameter needs to be 'vmail', 'crypt', 'redis', 'rspamd', 'postfix', 'mysql' or 'all'"
if [[ ${1} == "backup" && ! ${2} =~ (crypt|vmail|redis|rspamd|postfix|mysql|all|--delete-days) ]]; then
echo "Second parameter needs to be 'vmail', 'crypt', 'redis', 'rspamd', 'postfix', 'mysql', 'all' or '--delete-days'"
exit 1
fi
@ -99,6 +99,14 @@ function backup() {
--entrypoint= \
-v ${BACKUP_LOCATION}/mailcow-${DATE}:/backup \
${SQLIMAGE} /bin/sh -c "mysqldump -hmysql -uroot -p${DBROOT} --all-databases | gzip > /backup/backup_mysql.gz"
;;&
--delete-days)
shift
if [[ "${1}" =~ ^[0-9]+$ ]]; then
find ${BACKUP_LOCATION}/* -maxdepth 0 -mmin +$((${1}*60*24)) -exec rm -rvf {} \;
else
echo "Parameter of --delete-days is not a number."
fi
;;
esac
shift