13 Dec

Quick simple script for automated database dumps

I tried looking for script for database dumps but most of them are way too complex then a simple solution one can implement. 


Thus, I wrote a quick simple 1 page (infact few lines) bash script for database dumps.


Here’s the code:  


#Script for MySQL automated dumps


# Enter database names here
dbname=( database1 database2 database3 )

for i in "${dbname[@]}"

timestamp=backup_date +%F.%T
mysqldump -h $dbhost -u $dbusername -p$dbpassword -C $i | bzip2 -c > /backups/MySQL-automated/$output


To use this script, simply add names of database inside brackets in front of “dbname” like
dbname=( database1 database2 database3 ) and that’s all. You will get output in form of compressed .sql file.

Next, make script executable by using chmod +x script-name.sh

and run the script!

One can always set this up via a cron job for automated backups. 

Hope it will help!