简体   繁体   中英

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?

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

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 ,\ `

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM