In continuing my tradition of mySQL / bash shell one-liners (and posts with arguably SEO-friendly but embarassingly long titles) here’s one that just popped up today. I wanted to dump only selected tables from my database (full disclosure: all the tables relating to a particular WordPress plugin). Knowing I had done something similarly, I popped over to this post and modified it accordingly.
mysql -uUSERNAME -pPASS DBNAME --skip-column-names -e "select table_name from information_schema.tables where table_schema not like 'information_schema' and table_name like 'wp\_visual%';" | xargs -t -I {} mysqldump -uUSERNAME -pPASS DBNAME {} | gzip > dump_VFB-only_2012-11-20.sql.gz |
Xargs and I are still dating on-and-off, (well, more off than on), but when I need her special kind of loving to get my freak on, there’s really no other game in town. Don’t be confused by the -t output. I was. It looked like 3 separate files, and I was basically expecting only the last of the tables to actually find its way into my gzip (that sounds ruder than I intended. Excellent) but that was not the case.
If you find yourself vaguely offended or disturbed by my thinly-veiled sexual references to Unix shell commands, then you do not love your code. Or sex. Not sure which is worse.
Read More