added configurable amount of backups to keep

This commit is contained in:
kolaente 2018-01-31 14:10:28 +01:00
parent fa9e265ee3
commit cec30786a9
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
2 changed files with 19 additions and 11 deletions

View File

@ -81,14 +81,14 @@ fi
# Backup folder # Backup folder
if [ -z $backup_folder ] if [ -z $backup_folder ]
then then
backup_folder=$PWD/backups backup_folder=$PWD/backups
fi fi
# Max number of backups to keep # Max number of backups to keep
if [ -z $max_backups ] if [ -z $max_backups ]
then then
$max_backups=24 max_backups=24
fi fi
# Save the date # Save the date
@ -123,13 +123,21 @@ backup_hosts_file=$(cat $backup_hosts_location)
# Delete old backups # # Delete old backups #
###################### ######################
if [ -n "\${max_backups}" && "$(ls -A $backup_folder)" ]; then if [ -n "${max_backups}" ] && [ "$(ls -A $backup_folder)" ]; then
while [ \$(ls $backup_folder -1 | wc -l) -gt \${max_backups} ]; deleted=false
do
BACKUP_TO_BE_DELETED=\$(ls $backup_folder -1tr | head -n 1) # While there are > $max_backups, delete every old backup
echo " Backup \${BACKUP_TO_BE_DELETED} is deleted" while [ $(ls $backup_folder -1 | wc -l) -gt $max_backups ]; do
rm -rf \${BACKUP_TO_BE_DELETED} BACKUP_TO_BE_DELETED=$(ls $backup_folder -1tr | head -n 1)
echo "Deleted old backup $BACKUP_TO_BE_DELETED"
rm -rf $backup_folder/$BACKUP_TO_BE_DELETED
deleted=true
done done
if $deleted ; then
echo "--------------------------------------"
fi
fi fi
#################### ####################
@ -184,6 +192,6 @@ for row in $(echo "${backup_hosts_file}" | jq -r '.[] | @base64'); do
# Delete the file if the backup was not successfull # Delete the file if the backup was not successfull
rm $backup_folder/"$date"/${db_host}_all-databases.sql -f rm $backup_folder/"$date"/${db_host}_all-databases.sql -f
fi fi
echo "------------------" echo "-------------------------"
done done

View File

@ -1,6 +1,6 @@
[ [
{ {
"host":"host-db", "host":"127.0.0.1",
"user":"root", "user":"root",
"password":"1234" "password":"1234"
} }