On Thu, May 17, 2012 at 1:04 PM, Daniel Andersson <[email protected]> wrote:
>    DBNAMES=$(mysql --defaults-file=/etc/mysql/debian.cnf --execute="SHOW
> DATABASES" | awk 'BEGIN{ORS=" "}!/^(Database|mysql)$/')

In light of #673257, my above suggestion should be changed to the one
following below.

I also skip `information_schema` since this is a table similar to
`performance_schema` that does not really make sense to backup.

I skip the `Database` header by skipping the first line instead of
doing a line match against `Database`, since it is actually allowed to
have a database named `Database`, and the earlier command would not
back that up.

    DBNAMES=$(mysql --defaults-file=/etc/mysql/debian.cnf
--execute="SHOW DATABASES" | awk 'BEGIN{ORS=" "} NR==1{next}
!/^(information_schema|performance_schema|mysql)$/')

(the line break is part of my mail client, just skip that).

> Somewhat similarly, the other example
>
>    DBNAMES=`find /var/lib/mysql -mindepth 1 -maxdepth 1 -type d | cut -d'/'
> -f5 | grep -v ^mysql\$ | tr \\\r\\\n ,\ `
>
> can be done as e.g.
>
>    DBNAMES=$(ls -d /var/lib/mysql/*/ | awk -F/ 'BEGIN{ORS="
> "}$5!="mysql"{print $5}')

In a similar vein to the earlier change, this should now be:

    DBNAMES=$(ls -d /var/lib/mysql/*/ | awk -F/ 'BEGIN{ORS=" "}
$5!~/^(performance_schema|mysql)$/ {print $5}')

I notice now that the current `SHOW DATABASES` example in the package
configuration file does not give the same output as the `ls` one,
since `information_schema` does not exist as a directory in
`/var/lib/mysql`. Also, databases named `Database` would be backed up
by the old `ls` version, but not with the old `SHOW DATABASES`
version. These new versions give the same results, at least. More
anti-patterns are easily added by adding `|newpattern` in the `awk`
commands.

/Daniel



--
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to