Re: pg_dump return status.. - Mailing list pgsql-general

From Anthony E . Greene
Subject Re: pg_dump return status..
Date
Msg-id 20010105000617.O8784@cp5340
Whole thread Raw
In response to pg_dump return status..  (Anand Raman <araman@india-today.com>)
List pgsql-general
On Thu, 04 Jan 2001 05:12:25 Anand Raman wrote:
>I am trying to create a shell script which dumps my db to a flat file ..
>
>To dump the database i use the pg_dump command..
>
>I find that irrespective of the fact whether pg_dump managed to connect
>to the db or not the return status ($?) is always zero.. This throws the
>shell script in a spin which continues even when pg_dump is not able to
>connect ..
>
>Is there anyway around this. I thought of one way was to check stderr
>for the occurence of the word "failed" and then exit..

You could have the script check for the existence of the dump file and that
it has a non-zero size. To dump my personal database, I could use this:

#!/bin/bash
dumpfile=$HOME/mydatabase.dump
pg_dump -d $LOGNAME > $dumpfile
if [ -s $dumpfile ] ; then
  echo 'Dump succeeded'
else
  echo 'Dump failed'
fi

This should work in sh also.

Tony
--
Anthony E. Greene <agreene@pobox.com> <http://www.pobox.com/~agreene/>
PGP Key: 0x6C94239D/7B3D BD7D 7D91 1B44 BA26  C484 A42A 60DD 6C94 239D
Chat:  AOL/Yahoo: TonyG05    ICQ: 91183266
Linux. The choice of a GNU Generation. <http://www.linux.org/>

pgsql-general by date:

Previous
From: The Hermit Hacker
Date:
Subject: Re: running pgsql 7 under Jail'ed virtual machine on FreeBSD 4.2
Next
From: Lincoln Yeoh
Date:
Subject: Re: Synchronous LISTEN/NOTIFY?