added check to only delete old backups when there are some

This commit is contained in:
kolaente 2018-01-30 21:58:29 +01:00
parent 829b23d744
commit de7b9d21f4
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 7 additions and 5 deletions

View File

@ -22,11 +22,13 @@ fi
# Save the date
date=`date +%d\-%m\-%Y\_%H\-%M\-%S`
# Delete backups older than three days
echo "Deleting Backups older than three days..."
find $backup_folder/* -type d -ctime +3 | xargs rm -rf
echo "Deleted."
echo "-------------------------------"
# Delete backups older than three days if there are any
if [ ! "$(ls -A $backup_folder)" ]; then
echo "Deleting Backups older than three days..."
find $backup_folder/* -type d -ctime +3 | xargs rm -rf
echo "Deleted."
echo "-------------------------------"
fi
# Create new Backup folder
mkdir $backup_folder/"$date" -p