Toby Joiner
Toby Joiner

Reputation: 4376

ignore mysql tables in backup script

I am following the guide at this site and trying to exclude databases with the name turnkey in them.

find /var/lib/mysql -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f5 | grep -v ^mysql\$ | tr \\\r\\\n ,\ `

this command returns all the database names, how can I remove the turnkey ones?

Upvotes: 0

Views: 121

Answers (2)

rush
rush

Reputation: 2564

You can use a little improved script without any additional utilities, just pure find:

find /var/lib/mysql -mindepth 1 -maxdepth 1 -type d ! \( -name turnkey -or -name mysql \) -printf "%f "

Or just modify your variant to add turnkey in grep -v statement to exclude it from the list:

find /var/lib/mysql -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f5 | grep -v "^mysql\$\|^turnkey$" | tr \\\r\\\n ,\ `

Upvotes: 0

O. Jones
O. Jones

Reputation: 108641

The command you show is a Linux / unix shell command. If you add another step

 grep -v turnkey

you will omit any lines with the word "turnkey" in them.

Like so:

find /var/lib/mysql -mindepth 1 -maxdepth 1 -type d | 
cut -d'/' -f5 | 
grep -v ^mysql\$ |
grep -v turnkey 
tr \\\r\\\n ,\ `

You didn't ask if this is a good idea. I don't think it is, because it relies on a particular ondisk structure for the MySQL server daemon software that is not part of the formal specification of the system. In other words, it could change.

You could do this:

SELECT SCHEMA_NAME FROM `information_schema`.`SCHEMATA` 
 WHERE SCHEMA_NAME NOT LIKE '%turnkey%'
 ORDER BY SCHEMA_NAME

Upvotes: 1

Related Questions