NYCPHP Meetup

NYPHP.org

[nycphp-talk] Re: can mysqldump exclude a database?

Andrew Yochum andrew at digitalpulp.com
Thu Oct 28 23:34:26 EDT 2004


On Thu, Oct 28, 2004 at 11:26:04PM -0400, Andrew Yochum wrote:
> On Thu, Oct 28, 2004 at 11:10:29PM -0400, Faber Fedor wrote:
> > On 28/10/04 22:57 -0400, Daniel Convissor wrote:
> > > Hey Folks:
> > > 
> > > mysqldump -A will export all of the databases.  But, what if I want to 
> > > exclude a particular database?  Is it possible?  How, please?
> > 
> > Is there a way to A) list all the databases (databasi?), B) run the
> > output through 'grep -v' and then C) mysqldump the result?
> 
> Here's some quick bash for that:
>     for TABLE in $(echo "show tables" | mysql -u <username> -p'<password>' <database> | grep -v Tables_in_ | grep -v <some_table_to_exclude>)
>     do
>        mysqldump -u <username> -p'<password>' <database> ${TABLE}
>     done
> 
> ...replace things in angle brackets.  That could certainly be wrapped in a
> shell script w/ proper params and stuff, but I'm leaving that to you.

Whoops... thats for excluding tables, not databases.  Try:
    for DB in $(echo "show databases" | mysql -u <username> -p'<password>' | grep -v Database | grep -v <some_db_to_exclude>)
    do
        mysqldump -u <username> -p'<password>' ${DB}
    done

Same rules apply.

HTH more,
Andrew



More information about the talk mailing list