here's an improved script...maybe :) got some trouble on my server using your script. the base of this script i found on the internet (long time ago) too and did some modifcations.
#!/bin/bash
KEEP=31 # number of backups to keep
USER='user' # database user
PASS='pass' # database password
DB='db' # select the database to backup, or...
#DB='--all-databases' # backup all databases (comment the line above)
BUPATH='/root/backup_etkatalog/db_backups' # path to this (!!) script
BACKUPS=`find $BUPATH -name $DB"-*.sql.gz" | wc -l | sed 's/\ //g'`
while [ $BACKUPS -ge $KEEP ]
do
ls -tr1 $BUPATH/$DB-*.sql.gz | head -n 1 | xargs rm -f
BACKUPS=`expr $BACKUPS - 1`
done
DATE=`date +%Y%m%d%H%M%S`
rm -f $BUPATH/.$DB-${DATE}.sql.gz_TMP
/usr/bin/mysqldump $DB --opt -Q -u$USER -p$PASS | gzip -c -9 > $BUPATH/.$DB-${DATE}.sql.gz_TMP
mv -f $BUPATH/.$DB-${DATE}.sql.gz_TMP $BUPATH/$DB-${DATE}.sql.gz
exit 0
# example for daily backup (00:01)
# ================================
# add this line to crontab
# 1 0 * * * root sh /path/to/this/script.sh