git - Bash Script to Backup MySQL databases starting with specified prefix -


obviously if google search, there tons of results bash scripts mysql database. couldn't find specific example though.

say start new web projects @ dev.example.com/newprojectname

i prefix tables project name, newprojectname_posts, newprojectname_pages, etc.

everytime make change, want run command , specify database , table prefix so, command tablename prefix have .sql file git push

thanks

you can use script:

#!/bin/bash  tables=( $(mysql "$1" --silent -e "show tables '${2}_%'") )  t in "${tables[@]}";     mysqldump "$1" "$t" done 

then run this:

command databasename newprojectname >backup.sql 

it backup tables starting newprojectname_ (note included underscore).


Comments