Scripting to backup mySQL databases

Assistance in writing a script that will:-

a) backup mySQL databases at 00:01, together a log to state that backups are completed successfully or failed and and e-mail notification is sent out
b) mySQL databases are kept for 7days before they are archived
rakkadAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Prabhin MPDevOps EngineerCommented:
use the below script

nowdate=$(date +"%Y-%m-%d-%H")
dayago=`(date --date='7 days ago' '+%Y-%m-%d-%H')`
months=$(date +"%Y-%m")
days=$(date +"%d")
daysago=`(date --date='1 days ago' '+%d')`
username=youruser
host=
password=yourpassword
mkdir -p /backup/mysql-backup/$months/$days/
cd /backup/mysql-backup/$months/$days/
dbs=`mysql -h zurichdevrds.ctno4kxs9e0b.ap-southeast-1.rds.amazonaws.com -uroot -p$password -e "show databases"`
for db in $dbs
do
echo "==========$db ========"
mysqldump -h $host -C $db -uroot -p$password > ${db}-$nowdate.sql
done
echo $?
#Email Notification
if [ "$?" = "0" ]; then
        echo "Backup Process was Successful. A new backup file $nowdate.sql.gz has been created" | mailx -s "backup has been successful" your-email@domain.com
         echo "Backup Process Failed. Please contact System Administrator" | mailx -s "backup has been failed, " your-email@domain.com
        exit 1
fi

gzip *.sql
rm -rf /backup/mysql-backup/$months/$dayago
theGhost_k8Database ConsultantCommented:
If might want to consider using the Holland Framework. Here are the holland setup steps. You can provide details there and have an after-backup (success/failure)  script to send the email.

Update:
If you're willing to stick to the mysqldump / logical backup then you might want to use this backup script.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rakkadAuthor Commented:
Both solutions have been helpful and I appreciated your help
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Storage Software

From novice to tech pro — start learning today.