Backup prefixed tables in MySQL without PHP

Reading time ~1 minute

Just a quick note which took me some time and advice asking to find out. I have a database with two drupal installations separated by a table prefix, say drupal1_ and drupal2_. Lets call my database simply myDB.

If I’d like to backup only certain tables to an SQL file using mysqldump, I’d have to list all the table names separately. This is not nice at least since module installations and upgrades might add prefixed tables to the database dynamically over time. The other catch is that I want to do this without PHP.

One solution which works for me to backup only drupal1_ prefixed tables is to run the following script on the command line (in one line): mysql -u myUsername -p myPassword myDB -e "show tables like 'drupal1_%';" | sed '1d' | xargs mysqldump -u myUsername -p myPassword myBD > drupal1_tables_dump.sql

If you have a better solution feel free to comment. I usually leave out the myPassword part and enter the password (twice) when the script asks for it.

Moving to Jekyll!

I have been running this site on top of [Drupal][drupal], because I felt that platform would be awesome to build something on top of. Tha...… Continue reading