Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1T1oen-0007le-2Z for pgsql-docs@postgresql.org; Thu, 16 Aug 2012 01:13:53 +0000 Received: from momjian.us ([72.94.173.45]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1T1oel-0005Va-6e for pgsql-docs@postgresql.org; Thu, 16 Aug 2012 01:13:52 +0000 Received: from bruce by momjian.us with local (Exim 4.72) (envelope-from ) id 1T1oeh-0005aI-CC; Wed, 15 Aug 2012 21:13:47 -0400 Date: Wed, 15 Aug 2012 21:13:47 -0400 From: Bruce Momjian To: Josh Kupershmidt Cc: Greg Smith , Euler Taveira de Oliveira , pgsql-docs@postgresql.org Subject: Re: somewhat wrong archive_command example Message-ID: <20120816011347.GF8353@momjian.us> References: <1316524671.9044.12.camel@fsopti579.F-Secure.com> <4E794FB5.80400@2ndQuadrant.com> <1316613536.14119.6.camel@fsopti579.F-Secure.com> <4E7A6D0D.4060106@2ndQuadrant.com> <4E7A887F.8010908@timbira.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="WChQLJJJfbwij+9x" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.20 (2009-06-14) X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201208/26 X-Sequence-Number: 7419 --WChQLJJJfbwij+9x Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Thu, Sep 22, 2011 at 02:15:30PM -0400, Josh Kupershmidt wrote: > On Wed, Sep 21, 2011 at 8:59 PM, Euler Taveira de Oliveira > wrote: > > On 21-09-2011 20:02, Greg Smith wrote: > >> > >> Attached version fixes the late night brain fade errors. I think the right > >> thing to do next is to package this up into a doc update that corrects the > >> errors in that section too; just clean the whole thing up while I'm poking > >> at > >> it. I'll submit that over to the hackers list so that everyone can take a > >> shot > >> at correcting my shell code. > > First, a +1 on the impetus for this script. > > Few more suggestions/nitpicks: > 1.) IMO it's more logical to put the test for whether the $ARCHIVE > directory exists before the test whether ${ARCHIVE}/${FILE} exists. > 2.) I think the error code reporting here is not sound: > > cp ${FULLPATH} ${ARCHIVE}/${FILE} > if [ $? -ne 0 ] ; then > echo $0 Archive copy of ${FILE} failed with error $? >&2 > > at least on my OS X machine, that echo produces a message like > "./local_backup_script.sh Archive copy of failed with error 0", I > guess since $? gets reset to 0 after that if-statement. You can use a > temporary variable like $ERRCODE=$? to get around this. I have made all the suggestions posted and would like to add the attached script to our documentation as a simple example. -- Bruce Momjian http://momjian.us EnterpriseDB http://enterprisedb.com + It's impossible for everything to be true. + --WChQLJJJfbwij+9x Content-Type: application/x-sh Content-Disposition: attachment; filename="local_backup_script.sh" Content-Transfer-Encoding: quoted-printable #!/bin/sh=0A=0A# archive_command script for Standalone Hot Backup=0A=0A# SE= T THIS VARIABLE TO YOUR ARCHIVE DIRECTORY=0AARCHIVE=3D"/mnt/pg_archive"=0A= =0AFULLPATH=3D"$1"=0AFILE=3D"$2"=0A=0Aif [ ! -d "$ARCHIVE" ] ; then=0A ech= o "$0: Archive directory does not exist" 1>&2=0A exit 1=0Afi=0A=0Aif [ -f= "$ARCHIVE/$FILE" ] ; then=0A echo "$0: Archive file $FILE already exists= in archive, skipping" 1>&2=0A exit 0=0Afi=0A=0Acp "$FULLPATH" "$ARCHIVE/$= FILE"=0A=0ARET=3D"$?"=0A=0Aif [ "$RET" -ne 0 ] ; then=0A echo "$0: Archiv= e copy of $FILE failed with error $RET" 1>&2=0A exit 1=0Afi=0A=0Aexit 0=0A --WChQLJJJfbwij+9x--