Re: Dump all databases to corresponding files

From: Tomasz Ostrowski <tometzky(at)batory(dot)org(dot)pl>
To: CSN <cool_screen_name90001(at)yahoo(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Dump all databases to corresponding files
Date: 2006-11-07 10:24:25
Message-ID: 20061107102424.GB10992@batory.org.pl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, 06 Nov 2006, Roman Neuhauser wrote:

> # tometzky(at)batory(dot)org(dot)pl / 2006-11-06 12:26:43 +0100:
> > On Sun, 05 Nov 2006, CSN wrote:
> >
> > > Anybody know of a script that dumps all databases into
> > > corresponding dump files
> >
> > I've written this one in bash:
> > [snip]
> > This would break if any database name has white space.
>
> Why don't you use "while" then?
> psql -qXtc "$query" template1 | while read dbname; do
> pg_dump -b -F t "$dbname" > "/var/lib/pgsql/backups/$dbname.dump"
> done

It won't work if a database name have white space as first or last
letter... Or when database name has a newline somewhere (also
possible). It's hard to do it right so I did it simply wrong :-)

The way to do it right would be somehow forcing psql to output rows
separated by nulls ("\0") and use "xargs --null -i". But I don't know
how to do it.

Regards
Tometzky
--
...although Eating Honey was a very good thing to do, there was a
moment just before you began to eat it which was better than when you
were...
Winnie the Pooh

In response to

Browse pgsql-general by date

  From Date Subject
Next Message William Leite Araújo 2006-11-07 10:29:07 Re: FOR ... IN
Previous Message Martijn van Oosterhout 2006-11-07 10:06:22 Re: Header meaning for pg_dump