On Sat, Jul 20, 2002 at 02:25:48AM -0700, ratlhead wrote:
>
> #!/bin/bash
> DATE=`date +%Y-%m-%d`
> PGUSER=<my username>
> PGPASSWORD=<my password>
> export PGUSER PGPASSWORD
> pg_dump <dbname> | gzip > /folder/pg_backup.$DATE.gzip
> if [ !$? ]
> then
> find /folder/pg_backup/* -mtime 8 -exec rm -f {} \;
> echo "The PostGreSQL backup for today completed successfully" | mail
> ratlhead@ratlhead.com
> else
> echo "The PostGreSQL backup for today was unsuccessful" | mail
> ratlhead@ratlhead.com
> fi
>
>
> The problem is that is always gets detected as being successful, even
> if I say, comment out the export line of my user/pass. Any
> suggestions on how I can detect whether or not it worked?
The script always detects a successful dump because the last command in
the pipe is gzip and it always succeeds.
You could change the [ !$? ] to something like:
[ "$( zcat /folder/pg_backup.$DATE.gzip | head -c1 | wc -c )" -eq 1 ]
> Something else I'll be lookin' to do is FTP'ing the backup to another
> server. If anyone has suggestions on where I can look for help on
> that, it'd be great.
Use ncftpput or scp with no passphrase.
Regards,
Luciano Rocha
--
Consciousness: that annoying time between naps.