Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1T2SaC-0002mp-J4 for pgsql-docs@postgresql.org; Fri, 17 Aug 2012 19:51:48 +0000 Received: from eisentraut.org ([85.214.91.16] helo=gattler.pezone.net) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1T2SaB-0001s1-Jx for pgsql-docs@postgresql.org; Fri, 17 Aug 2012 19:51:48 +0000 Received: from jesse.pezone.net (efw.scs.myyearbook.com [204.145.120.11]) by gattler.pezone.net (Postfix) with ESMTPSA id 222EC5A8366; Fri, 17 Aug 2012 19:51:46 +0000 (UTC) Message-ID: <502EA0D0.10004@gmx.net> Date: Fri, 17 Aug 2012 15:51:44 -0400 From: Peter Eisentraut User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:14.0) Gecko/20120713 Thunderbird/14.0 MIME-Version: 1.0 To: Bruce Momjian CC: Josh Kupershmidt , Greg Smith , Euler Taveira de Oliveira , pgsql-docs@postgresql.org Subject: Re: somewhat wrong archive_command example 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> <20120816011347.GF8353@momjian.us> In-Reply-To: <20120816011347.GF8353@momjian.us> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201208/31 X-Sequence-Number: 7424 On 8/15/12 9:13 PM, Bruce Momjian wrote: >> 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. Btw., is anyone else concerned about using plain cp for this? If the cp fails half-way, it leaves a partial file around, but subsequent file existence checks will find the file OK and skip it. I have occasionally used some combination of mktemp + cp + mv, which seems to work around this problem.