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

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -