send email after mysql backup through bash script in simple way
In Facebook group one of the user asked this question “how to send email after mysql backup through bash script”.
If you know bash scripting a bit it is just a one liner.
It can be write in more advanced form but here I am using just simple method which is applicable and tested in Red Hat,CentOS, Debian and Ubuntu.
You can use this script in crontab also and schedule it as per your requirement.
Step 1: Create a bash script with file name called db-backup.sh
Note: replace the value like mysql-username,password,database-name, as per your server information.
Change email@example.com with your email id.
db-backup.sh #!/bin/bash mysqldump -u mysql-username -p password database-name > serverDB.`date +%F_%T`.sql && echo "the mysqldump has been completed- status received at `date +%F_%T`|mail -s mysqldump-status firstname.lastname@example.org
Step 2: give it read,write and execute permission only to owner.
chmod 700 db-backup.sh
Step 3: Now you can execute the script directly or can be used in crontab