Re: Shell Script help for backup - Mailing list pgsql-general

From david.morgan@s4c.co.uk
Subject Re: Shell Script help for backup
Date
Msg-id 7AFD985147A2D51197A700508BC75BC90DC87C@EXCHANGE
Whole thread Raw
In response to Shell Script help for backup  (ratlhead@ratlhead.com (ratlhead))
List pgsql-general
You don't have to compromise and use a clear passphrase, you can use
keychain, this uses ssh-agent and caches the user's passphrases:

http://www-106.ibm.com/developerworks/library/l-keyc2/





-----Original Message-----
From: strange@nsk.yi.org [mailto:strange@nsk.yi.org]
Sent: 22 July 2002 15:09
To: pgsql-general@postgresql.org
Subject: Re: [GENERAL] Shell Script help for backup


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.

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Mae�r neges e-bost hon ac unrhyw ffeiliau sydd ynghlwm wrthi yn gwbl gyfrinachol ac wedi�u bwriadu at sylw yr unigolyn
neu�rendid y maent wedi eu cyfeirio ato yn unig. Gallant gynnwys gwybodaeth sy�n freintiedig yn gyfreithiol a/neu�n
gyfrinacholac os nad chi yw�r sawl y cyfeiriwyd y neges ato, yna peidiwch � chopio, dosbarthu na chymryd unrhyw gamau o
ganlyniada gan ddibynnu arni. Os ydych wedi derbyn y neges e-bost hon ar gam, a wnewch chi ein hysbysu o hyn cyn gynted
�phosib a�i dileu os gwelwch yn dda. Barn neu safbwyntiau�r awdur yw�r rhai a fynegir yn y neges e-bost hon ac/neu�n
unrhywatodiadau ac nid ydynt yn adlewyrchu o anghenraid barn neu safbwyntiau S4C. 

This e-mail message and any files attached are strictly confidential and intended solely for the attention of the
personor entity to whom they are addressed. They may contain legally privileged and/or confidential information and if
youare not the addressee, you should not copy, distribute nor take any action in reliance on them. If you have received
thise-mail message in error, please notify us as soon as possible and delete it. The views and opinions expressed in
thise-mail message and any attachments are the author�s own and they do not reflect necessarily the views and opinions
ofS4C. 


pgsql-general by date:

Previous
From: Andrew Sullivan
Date:
Subject: Re: Windows - why not?
Next
From: Devrim GUNDUZ
Date:
Subject: Re: Windows - why not?