There is my approach to backup a mysql database. I have put all the required parameters in bash variables, so the code can be easily reusable.
In addition to the core functionality (making backup) there is also the functionality to delete the older files that the specified number of days. For example, we can set to delete the backup files older than one month. The code is located below:
https://gist.github.com/deanpodgornik/612a40adc17785701c57
Explanation of the code above:
If this code is usefully for you, just grab it and customize it as you want. You can also fork it from my github repository:
Cheer