Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id B1909B5DC22 for ; Wed, 21 Sep 2011 20:02:45 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 11842-10 for ; Wed, 21 Sep 2011 23:02:39 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.17.8]) by mail.postgresql.org (Postfix) with ESMTP id E16E7B5DC01 for ; Wed, 21 Sep 2011 20:02:38 -0300 (ADT) Received: from [192.168.1.6] (mail.highperformancepostgresql.com [71.179.240.8]) by mrelayeu.kundenserver.de (node=mreu3) with ESMTP (Nemesis) id 0MSlXs-1Qh6fy0X3c-00SHNE; Thu, 22 Sep 2011 01:02:38 +0200 Message-ID: <4E7A6D0D.4060106@2ndQuadrant.com> Date: Wed, 21 Sep 2011 19:02:37 -0400 From: Greg Smith User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.16) Gecko/20110818 Icedove/3.0.11 MIME-Version: 1.0 CC: 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> In-Reply-To: <1316613536.14119.6.camel@fsopti579.F-Secure.com> Content-Type: multipart/mixed; boundary="------------030805000404010204080300" X-Provags-ID: V02:K0:IZye1tTJxzuEFJAWZoMSdG3NJJnGgip/qCQbLS+t6iX r6Pg52Q3Yv5oKwlFErPrtX/2Nh4qRFrjHowgHAYY52USoNy+Be j79J7hXnKTWsLPlniCbvPEjMVicOz15Fb721YxBNR6SPxlOHi0 8dsLwK3UAl49SBLOX7RK4tYs+ISSD9czyiOuXu+BcdWAEN3G0c BcggTairUmrPN6bMpvEY9yYqSKDg+8kbYVwdt9wGzLxaCla2Uu Ib1N2HfTSk6/ahqiAH7py+Laijj7eiSsBhC854KpoZtvzMSCgL tyVNrnV3rH9wOqgZ/273BRi5a0h1CQdnCHbO55ZrncKNrbSNJD LhzOZvkj2miyf1O4nWLo= X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.879 tagged_above=-5 required=5 tests=BAYES_00=-1.9, MISSING_HEADERS=1.021, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201109/68 X-Sequence-Number: 6989 This is a multi-part message in MIME format. --------------030805000404010204080300 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 09/21/2011 09:58 AM, Peter Eisentraut wrote: > I can see a few problems with your script, as far as making it into a > generally reusable example: > > - Uses bash. Portable scripts shouldn't do this. > > - Overwrites PATH variable for unrelated purpose. > > - Path ($PATH) should be quoted everywhere. (By contrast, you don't > need the quotes in PATH="$1". Just saying ...) > > - cp shouldn't be called with an absolute path. > Most of these problems stemmed from the unnoticed fact that I'd made PATH the name of my variable. The absolute path for cp for example? Added that because it couldn't seem to find cp in the PATH, which was driving me crazy for a while there...sigh. 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. -- Greg Smith 2ndQuadrant US greg@2ndQuadrant.com Baltimore, MD PostgreSQL Training, Services, and 24x7 Support www.2ndQuadrant.us --------------030805000404010204080300 Content-Type: application/x-sh; name="local_backup_script.sh" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="local_backup_script.sh" #!/bin/sh # archive_command script for Standalone Hot Backup # # Assumes that your backup_in_progress trigger file # is located at a subdirectory below the database # directory, along with an archive/ subdirectory # to hold WAL files. FULLPATH=$1 FILE=$2 ARCHIVE="../archive" if [ ! -f ../backup_in_progress ]; then exit 0 fi if [ -f ${ARCHIVE}/${FILE} ] ; then echo Archive file ${FILE} already exists in archive, skipping >&2 exit 0 fi if [ ! -d ${ARCHIVE} ] ; then echo Archive directory does not exist >&2 exit 1 fi cp ${FULLPATH} ${ARCHIVE}/${FILE} if [ $? -ne 0 ] ; then echo $0 Archive copy of ${FILE} failed with error $? >&2 exit 1 fi exit 0 --------------030805000404010204080300--